2021-12-27 00:52:50 +01:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEditor.IMGUI.Controls;
|
|
|
|
using Object = UnityEngine.Object;
|
|
|
|
|
|
|
|
namespace Validator.Editor
|
|
|
|
{
|
|
|
|
public class ValidatorEditorWindow : EditorWindow
|
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
private class ValidatorInfo
|
|
|
|
{
|
|
|
|
public IValidator validator = null;
|
|
|
|
public bool isEnabled = true;
|
|
|
|
|
|
|
|
public ValidatorInfo(IValidator validator)
|
|
|
|
{
|
|
|
|
this.validator = validator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ReportStats
|
|
|
|
{
|
|
|
|
public int infoCount = 0;
|
|
|
|
public int warningCount = 0;
|
|
|
|
public int errorCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class Settings
|
|
|
|
{
|
|
|
|
public bool showInfo = true;
|
|
|
|
public bool showWarning = true;
|
|
|
|
public bool showError = true;
|
2021-12-29 16:42:47 +01:00
|
|
|
public string searchInput = "";
|
2021-12-27 00:52:50 +01:00
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
public readonly Color lightColor = new Color(0.25f, 0.25f, 0.25f, 1);
|
|
|
|
public readonly Color darkColor = new Color(0.22f, 0.22f, 0.22f, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static readonly List<ValidatorInfo> validators = new List<ValidatorInfo>();
|
|
|
|
private static readonly List<Report> reports = new List<Report>();
|
|
|
|
|
|
|
|
private static readonly Settings settings = new Settings();
|
|
|
|
private static ReportStats reportStats = new ReportStats();
|
|
|
|
|
|
|
|
private MultiColumnHeaderState multiColumnHeaderState;
|
2021-12-27 00:52:50 +01:00
|
|
|
private MultiColumnHeader multiColumnHeader;
|
|
|
|
private MultiColumnHeaderState.Column[] columns;
|
|
|
|
private Vector2 scrollPosition;
|
|
|
|
private float multiColumnHeaderWidth;
|
|
|
|
private float rows;
|
|
|
|
|
|
|
|
[MenuItem("Window/General/Validator")]
|
|
|
|
private static void Init()
|
|
|
|
{
|
|
|
|
ValidatorEditorWindow window = (ValidatorEditorWindow)GetWindow(typeof(ValidatorEditorWindow));
|
2021-12-29 14:41:48 +01:00
|
|
|
window.titleContent = new GUIContent("Validator", EditorGUIUtility.IconContent("d_UnityEditor.ConsoleWindow").image);
|
2021-12-27 00:52:50 +01:00
|
|
|
window.Show();
|
|
|
|
window.LoadValidators();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnGUI()
|
|
|
|
{
|
|
|
|
using (new EditorGUILayout.VerticalScope(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
|
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
DrawMenu();
|
2021-12-27 00:52:50 +01:00
|
|
|
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
|
|
|
|
DrawMultiColumnScope();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void InitializeMultiColumn()
|
|
|
|
{
|
|
|
|
columns = new MultiColumnHeaderState.Column[]
|
|
|
|
{
|
|
|
|
new MultiColumnHeaderState.Column()
|
|
|
|
{
|
|
|
|
allowToggleVisibility = false, // At least one column must be there.
|
|
|
|
autoResize = false,
|
|
|
|
width = 36f,
|
|
|
|
minWidth = 36f,
|
|
|
|
maxWidth = 36f,
|
|
|
|
canSort = false,
|
|
|
|
sortingArrowAlignment = TextAlignment.Right,
|
|
|
|
headerContent = EditorGUIUtility.IconContent("d_console.erroricon.inactive.sml", "Warning Type."),
|
|
|
|
headerTextAlignment = TextAlignment.Center,
|
|
|
|
},
|
|
|
|
new MultiColumnHeaderState.Column()
|
|
|
|
{
|
|
|
|
allowToggleVisibility = true,
|
|
|
|
autoResize = false,
|
|
|
|
width = 36f,
|
|
|
|
minWidth = 36f,
|
|
|
|
maxWidth = 36f,
|
|
|
|
canSort = false,
|
|
|
|
sortingArrowAlignment = TextAlignment.Right,
|
|
|
|
headerContent = EditorGUIUtility.IconContent("Animation.FilterBySelection", "Target Objects"),
|
|
|
|
headerTextAlignment = TextAlignment.Center,
|
|
|
|
},
|
|
|
|
new MultiColumnHeaderState.Column()
|
|
|
|
{
|
|
|
|
allowToggleVisibility = true,
|
|
|
|
autoResize = true,
|
|
|
|
width = 75.0f,
|
|
|
|
minWidth = 75.0f,
|
|
|
|
canSort = false,
|
|
|
|
sortingArrowAlignment = TextAlignment.Right,
|
|
|
|
headerContent = new GUIContent("Category", "Warning Category."),
|
|
|
|
headerTextAlignment = TextAlignment.Center,
|
|
|
|
},
|
|
|
|
new MultiColumnHeaderState.Column()
|
|
|
|
{
|
|
|
|
allowToggleVisibility = true,
|
|
|
|
autoResize = true,
|
|
|
|
width = 200.0f,
|
|
|
|
minWidth = 200.0f,
|
|
|
|
canSort = false,
|
|
|
|
sortingArrowAlignment = TextAlignment.Right,
|
|
|
|
headerContent = new GUIContent("Message", "Warning Message."),
|
|
|
|
headerTextAlignment = TextAlignment.Center,
|
|
|
|
},
|
|
|
|
new MultiColumnHeaderState.Column()
|
|
|
|
{
|
|
|
|
allowToggleVisibility = true,
|
|
|
|
autoResize = true,
|
|
|
|
width = 200.0f,
|
|
|
|
minWidth = 200.0f,
|
|
|
|
canSort = false,
|
|
|
|
sortingArrowAlignment = TextAlignment.Right,
|
|
|
|
headerContent = new GUIContent("Solution", "Warning Solution."),
|
|
|
|
headerTextAlignment = TextAlignment.Center,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
multiColumnHeaderState = new MultiColumnHeaderState(columns);
|
|
|
|
multiColumnHeader = new MultiColumnHeader(multiColumnHeaderState);
|
2021-12-27 00:52:50 +01:00
|
|
|
multiColumnHeader.ResizeToFit();
|
|
|
|
}
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
private void DrawMenu()
|
|
|
|
{
|
|
|
|
using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
|
|
|
|
{
|
|
|
|
if (GUILayout.Button(EditorGUIUtility.IconContent("Refresh", "Refresh"), EditorStyles.toolbarButton))
|
|
|
|
{
|
|
|
|
LoadValidators();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GUILayout.Button(EditorGUIUtility.IconContent("d_Settings", "Select validator"), EditorStyles.toolbarButton))
|
|
|
|
{
|
|
|
|
GenericMenu validatorOptionsMenu = new GenericMenu();
|
|
|
|
validatorOptionsMenu.AddItem(new GUIContent($"All"), false, OnValidatorInfoVisibilityAllEvent);
|
|
|
|
validatorOptionsMenu.AddItem(new GUIContent($"None"), false, OnValidatorInfoVisibilityNoneEvent);
|
|
|
|
validatorOptionsMenu.AddSeparator("");
|
|
|
|
foreach (ValidatorInfo validatorInfo in validators)
|
|
|
|
{
|
2021-12-29 23:46:52 +01:00
|
|
|
validatorOptionsMenu.AddItem(new GUIContent($"{validatorInfo.validator.MenuName}"), validatorInfo.isEnabled, OnValidatorInfoVisibilityChangedEvent, validatorInfo);
|
2021-12-29 14:41:48 +01:00
|
|
|
}
|
|
|
|
validatorOptionsMenu.ShowAsContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GUILayout.Button(EditorGUIUtility.IconContent("PlayButton", "Run all"), EditorStyles.toolbarButton))
|
|
|
|
{
|
|
|
|
RunValidators();
|
|
|
|
UpdateStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
GUILayout.FlexibleSpace();
|
|
|
|
|
2021-12-29 16:42:47 +01:00
|
|
|
settings.searchInput = GUILayout.TextField(settings.searchInput, EditorStyles.toolbarSearchField, GUILayout.MaxWidth(300));
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
if(reportStats != null)
|
|
|
|
{
|
|
|
|
settings.showInfo = GUILayout.Toggle(settings.showInfo, new GUIContent($"{reportStats.infoCount}", EditorGUIUtility.IconContent(GetWarningIconName(WarningType.Info)).image), EditorStyles.toolbarButton);
|
|
|
|
settings.showWarning = GUILayout.Toggle(settings.showWarning, new GUIContent($"{reportStats.warningCount}", EditorGUIUtility.IconContent(GetWarningIconName(WarningType.Warning)).image), EditorStyles.toolbarButton);
|
|
|
|
settings.showError = GUILayout.Toggle(settings.showError, new GUIContent($"{reportStats.errorCount}", EditorGUIUtility.IconContent(GetWarningIconName(WarningType.Error)).image), EditorStyles.toolbarButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 00:52:50 +01:00
|
|
|
private void DrawMultiColumnScope()
|
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
//GUILayout.FlexibleSpace(); // If nothing has been drawn yet, uncomment this because GUILayoutUtility.GetLastRect() needs it.
|
2021-12-27 00:52:50 +01:00
|
|
|
Rect windowRect = GUILayoutUtility.GetLastRect();
|
|
|
|
windowRect.width = position.width;
|
|
|
|
windowRect.height = position.height;
|
|
|
|
|
|
|
|
if (multiColumnHeader == null)
|
|
|
|
{
|
|
|
|
InitializeMultiColumn();
|
|
|
|
}
|
|
|
|
|
|
|
|
float columnHeight = EditorGUIUtility.singleLineHeight * 2;
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
Rect headerRect = new Rect(windowRect)
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
|
|
|
height = EditorGUIUtility.singleLineHeight,
|
|
|
|
};
|
|
|
|
|
|
|
|
Rect scrollViewPositionRect = GUILayoutUtility.GetRect(0, float.MaxValue, 0, float.MaxValue);
|
|
|
|
scrollViewPositionRect.y += headerRect.height - EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
scrollViewPositionRect.height -= headerRect.height - EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
Rect scrollViewRect = new Rect(windowRect)
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
|
|
|
width = multiColumnHeaderState.widthOfAllVisibleColumns,
|
|
|
|
height = rows * columnHeight
|
|
|
|
};
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
Rect rowRect = new Rect(windowRect)
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
|
|
|
width = multiColumnHeaderWidth,
|
|
|
|
height = columnHeight,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Draw column header.
|
2021-12-29 14:41:48 +01:00
|
|
|
multiColumnHeader.OnGUI(headerRect, scrollPosition.x);
|
2021-12-27 00:52:50 +01:00
|
|
|
|
|
|
|
// Draw scroll view.
|
|
|
|
using (GUI.ScrollViewScope scope = new GUI.ScrollViewScope(scrollViewPositionRect, scrollPosition, scrollViewRect, false, false))
|
|
|
|
{
|
|
|
|
scrollPosition = scope.scrollPosition;
|
|
|
|
multiColumnHeaderWidth = Mathf.Max(scrollViewPositionRect.width + scrollPosition.x, multiColumnHeaderWidth);
|
|
|
|
|
|
|
|
rows = 0;
|
|
|
|
for (int i = 0; i < reports.Count; i++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < reports[i].Reports.Count; j++)
|
|
|
|
{
|
2021-12-29 16:42:47 +01:00
|
|
|
// Type filter.
|
2021-12-29 14:41:48 +01:00
|
|
|
switch (reports[i].Reports[j].WarningType)
|
|
|
|
{
|
|
|
|
case WarningType.Info:
|
|
|
|
if (!settings.showInfo)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case WarningType.Warning:
|
|
|
|
if (!settings.showWarning)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case WarningType.Error:
|
|
|
|
if (!settings.showError)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-29 16:42:47 +01:00
|
|
|
// Search filter.
|
|
|
|
if (!string.IsNullOrWhiteSpace(settings.searchInput))
|
|
|
|
{
|
|
|
|
if (!reports[i].Reports[j].Category.Contains(settings.searchInput) && !reports[i].Reports[j].Message.Contains(settings.searchInput) && !reports[i].Reports[j].Solution.Contains(settings.searchInput))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
// Only draw what is visible within the view.
|
2021-12-27 00:52:50 +01:00
|
|
|
if (rowRect.yMax > windowRect.y + scrollPosition.y && rowRect.yMin < windowRect.height + scrollPosition.y)
|
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
if (rows % 2 == 0)
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
EditorGUI.DrawRect(rowRect, settings.darkColor);
|
2021-12-27 00:52:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
EditorGUI.DrawRect(rowRect, settings.lightColor);
|
2021-12-27 00:52:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Warning Field.
|
|
|
|
int columnIndex = 0;
|
2021-12-29 14:41:48 +01:00
|
|
|
if (multiColumnHeader.IsColumnVisible(columnIndex))
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex);
|
|
|
|
Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex);
|
2021-12-27 00:52:50 +01:00
|
|
|
columnRect.y = rowRect.y;
|
|
|
|
columnRect.height = rowRect.height;
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
Rect labelFieldRect = multiColumnHeader.GetCellRect(visibleColumnIndex, columnRect);
|
2021-12-27 00:52:50 +01:00
|
|
|
labelFieldRect.x += 9;
|
|
|
|
labelFieldRect.width -= 9;
|
|
|
|
|
|
|
|
EditorGUI.LabelField(
|
2021-12-29 14:41:48 +01:00
|
|
|
labelFieldRect,
|
|
|
|
EditorGUIUtility.IconContent(GetWarningIconName(reports[i].Reports[j].WarningType), $"{reports[i].Reports[j].WarningType}")
|
2021-12-27 00:52:50 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Target Field.
|
|
|
|
columnIndex = 1;
|
2021-12-29 14:41:48 +01:00
|
|
|
if (multiColumnHeader.IsColumnVisible(columnIndex))
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex);
|
|
|
|
Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex);
|
2021-12-27 00:52:50 +01:00
|
|
|
columnRect.y = rowRect.y;
|
|
|
|
columnRect.height = rowRect.height;
|
|
|
|
|
|
|
|
if(reports[i].Reports[j].Target != null)
|
|
|
|
{
|
|
|
|
if (GUI.Button(
|
2021-12-29 14:41:48 +01:00
|
|
|
multiColumnHeader.GetCellRect(visibleColumnIndex, columnRect),
|
|
|
|
EditorGUIUtility.IconContent("Animation.FilterBySelection", "Ping Object")
|
2021-12-27 00:52:50 +01:00
|
|
|
))
|
|
|
|
{
|
|
|
|
Selection.objects = new Object[] { reports[i].Reports[j].Target };
|
|
|
|
|
|
|
|
if (!Selection.activeObject)
|
|
|
|
{
|
|
|
|
Debug.Log($"{nameof(Selection.activeObject)} is null.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (Object o in Selection.objects)
|
|
|
|
{
|
|
|
|
EditorGUIUtility.PingObject(o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Category Field.
|
|
|
|
columnIndex = 2;
|
2021-12-29 14:41:48 +01:00
|
|
|
if (multiColumnHeader.IsColumnVisible(columnIndex))
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex);
|
|
|
|
Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex);
|
2021-12-27 00:52:50 +01:00
|
|
|
columnRect.y = rowRect.y;
|
|
|
|
columnRect.height = rowRect.height;
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
Rect labelFieldRect = multiColumnHeader.GetCellRect(visibleColumnIndex, columnRect);
|
2021-12-27 00:52:50 +01:00
|
|
|
labelFieldRect.x += 7;
|
|
|
|
labelFieldRect.width -= 7;
|
|
|
|
|
|
|
|
EditorGUI.LabelField(
|
2021-12-29 14:41:48 +01:00
|
|
|
labelFieldRect,
|
|
|
|
new GUIContent($"{reports[i].Reports[j].Category}")
|
2021-12-27 00:52:50 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message Field.
|
|
|
|
columnIndex = 3;
|
2021-12-29 14:41:48 +01:00
|
|
|
if (multiColumnHeader.IsColumnVisible(columnIndex))
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex);
|
|
|
|
Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex);
|
2021-12-27 00:52:50 +01:00
|
|
|
columnRect.y = rowRect.y;
|
|
|
|
columnRect.height = rowRect.height;
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
Rect labelFieldRect = multiColumnHeader.GetCellRect(visibleColumnIndex, columnRect);
|
2021-12-27 00:52:50 +01:00
|
|
|
labelFieldRect.x += 7;
|
|
|
|
labelFieldRect.width -= 7;
|
|
|
|
|
|
|
|
EditorGUI.LabelField(
|
2021-12-29 14:41:48 +01:00
|
|
|
labelFieldRect,
|
|
|
|
new GUIContent($"{reports[i].Reports[j].Message}")
|
2021-12-27 00:52:50 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Solution Field.
|
|
|
|
columnIndex = 4;
|
2021-12-29 14:41:48 +01:00
|
|
|
if (multiColumnHeader.IsColumnVisible(columnIndex))
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex);
|
|
|
|
Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex);
|
2021-12-27 00:52:50 +01:00
|
|
|
columnRect.y = rowRect.y;
|
|
|
|
columnRect.height = rowRect.height;
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
Rect labelFieldRect = multiColumnHeader.GetCellRect(visibleColumnIndex, columnRect);
|
2021-12-27 00:52:50 +01:00
|
|
|
labelFieldRect.x += 7;
|
|
|
|
labelFieldRect.width -= 7;
|
|
|
|
|
|
|
|
EditorGUI.LabelField(
|
2021-12-29 14:41:48 +01:00
|
|
|
labelFieldRect,
|
|
|
|
new GUIContent($"{reports[i].Reports[j].Solution}")
|
2021-12-27 00:52:50 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rowRect.y += columnHeight;
|
|
|
|
rows++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scope.handleScrollWheel = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LoadValidators()
|
|
|
|
{
|
|
|
|
for (int i = validators.Count - 1; i >= 0; i--)
|
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
if (validators[i].validator == null)
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
|
|
|
validators.RemoveAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (Type type in GetValidatorTypes())
|
|
|
|
{
|
|
|
|
bool hasValidator = false;
|
2021-12-29 14:41:48 +01:00
|
|
|
foreach (ValidatorInfo validatorInfo in validators)
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
if (validatorInfo.validator.GetType() == type)
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
|
|
|
hasValidator = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasValidator)
|
|
|
|
{
|
|
|
|
IValidator validator = (IValidator)Activator.CreateInstance(type);
|
|
|
|
if (validator != null)
|
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
validators.Add(new ValidatorInfo(validator));
|
2021-12-27 00:52:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
private void RunValidators()
|
|
|
|
{
|
|
|
|
reports.Clear();
|
|
|
|
|
|
|
|
foreach (ValidatorInfo validatorInfo in validators)
|
|
|
|
{
|
|
|
|
if (validatorInfo.isEnabled)
|
|
|
|
{
|
|
|
|
reports.Add(validatorInfo.validator.Validate());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateStats()
|
|
|
|
{
|
|
|
|
reportStats = new ReportStats();
|
|
|
|
|
|
|
|
foreach (Report report in reports)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < report.Reports.Count; i++)
|
|
|
|
{
|
|
|
|
switch (report.Reports[i].WarningType)
|
|
|
|
{
|
|
|
|
case WarningType.Info:
|
|
|
|
reportStats.infoCount++;
|
|
|
|
break;
|
|
|
|
case WarningType.Warning:
|
|
|
|
reportStats.warningCount++;
|
|
|
|
break;
|
|
|
|
case WarningType.Error:
|
|
|
|
reportStats.errorCount++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnValidatorInfoVisibilityChangedEvent(object info)
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
if(info is ValidatorInfo validatorInfo)
|
|
|
|
{
|
|
|
|
validatorInfo.isEnabled = !validatorInfo.isEnabled;
|
2021-12-27 00:52:50 +01:00
|
|
|
}
|
2021-12-29 14:41:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnValidatorInfoVisibilityAllEvent()
|
|
|
|
{
|
|
|
|
foreach (ValidatorInfo validatorInfo in validators)
|
|
|
|
{
|
|
|
|
validatorInfo.isEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnValidatorInfoVisibilityNoneEvent()
|
|
|
|
{
|
|
|
|
foreach (ValidatorInfo validatorInfo in validators)
|
|
|
|
{
|
|
|
|
validatorInfo.isEnabled = false;
|
|
|
|
}
|
|
|
|
}
|
2021-12-27 00:52:50 +01:00
|
|
|
|
2021-12-29 14:41:48 +01:00
|
|
|
private static Type[] GetValidatorTypes()
|
2021-12-27 00:52:50 +01:00
|
|
|
{
|
|
|
|
return TypeCache.GetTypesDerivedFrom<IValidator>().ToArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static string GetWarningIconName(WarningType warningType)
|
|
|
|
{
|
|
|
|
return warningType switch
|
|
|
|
{
|
2021-12-29 14:41:48 +01:00
|
|
|
WarningType.Info => "d_console.infoicon.sml",
|
2021-12-27 00:52:50 +01:00
|
|
|
WarningType.Warning => "d_console.warnicon.sml",
|
|
|
|
WarningType.Error => "d_console.erroricon.sml",
|
|
|
|
_ => "d_console.erroricon.inactive.sml",
|
|
|
|
};
|
|
|
|
}
|
2021-12-29 14:41:48 +01:00
|
|
|
}
|
2021-12-27 00:52:50 +01:00
|
|
|
}
|