/// <summary>
        /// Constructor that accepts the <see cref="LogCache"/> <paramref name="logCache"/> that logs will be
        /// stored in and the <see cref="SceneValidationMode"/> <paramref name="validationMode"/> that scenes
        /// will be validated in (if any).
        /// </summary>
        /// <param name="logCache"></param>
        /// <param name="validationMode"></param>
        public AssetValidatorRunner(LogCache logCache, SceneValidationMode validationMode)
        {
            _scenePaths = ProjectTools.GetScenePaths(validationMode);

            _logCache = logCache;

            _cache = new ClassTypeCache();

            // Ensure any unit test types do not get picked up for validation.
            _cache.IgnoreType <MonoBehaviourTwo>();
            _cache.IgnoreAttribute <OnlyIncludeInTestsAttribute>();

            // Find all objects for validation
            _cache.AddTypeWithAttribute <MonoBehaviour, ValidateAttribute>();

            // Add all disabled logs for this run
            AssetValidatorOverrideConfig.FindOrCreate().AddDisabledLogs(logCache);

            _isRunning   = true;
            _runningTime = EditorApplication.timeSinceStartup;
        }
        public override void OnInspectorGUI()
        {
            var path = AssetDatabase.GetAssetPath(target);

            if (!ProjectTools.IsInResourcesFolder(path))
            {
                EditorGUILayout.HelpBox(
                    EditorConstants.ConfigAssetNotInResourcesPath,
                    MessageType.Warning);
            }

            var overrideItems = _config.OverrideItems;

            overrideItems.Sort(Comparison);

            var headerRect = EditorGUILayout.BeginVertical();

            headerRect.height += 10f;

            if (Event.current.type == EventType.Repaint)
            {
                var originalColor = GUI.color;
                GUI.color = new Color(0.5f, 0.5f, 0.5f, 1);
                GraphicsTools.LogRowHeaderBackground.Draw(headerRect, false, false, false, false);
                GUI.color = originalColor;
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(20f);
            EditorGUILayout.LabelField(
                EditorConstants.OverrideConfigEnabledHeader,
                EditorStyles.boldLabel,
                GUILayout.Width(80f));
            EditorGUILayout.LabelField(
                EditorConstants.OverrideConfigClassHeader,
                EditorStyles.boldLabel,
                GUILayout.Width(200f));
            EditorGUILayout.LabelField(
                EditorConstants.OverrideConfigTypeHeader,
                EditorStyles.boldLabel,
                GUILayout.Width(200f));
            GUILayout.Space(20f);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            var contentsRect = EditorGUILayout.BeginVertical();

            GUILayout.Space(5f);
            GUI.Box(contentsRect, GraphicsTools.GrayTexture2D);
            EditorGUI.BeginChangeCheck();
            for (var i = 0; i < overrideItems.Count; i++)
            {
                var item = overrideItems[i];

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20f);
                item.enabled = EditorGUILayout.Toggle(item.enabled, GUILayout.Width(80f));
                EditorGUILayout.LabelField(item.type.Name, GUILayout.Width(200f));
                EditorGUILayout.LabelField(GetTypeOfValidator(item.type), GUILayout.Width(200f));
                GUILayout.Space(20f);
                EditorGUILayout.EndHorizontal();
            }

            var valueHasChanged = EditorGUI.EndChangeCheck();

            GUILayout.Space(5f);
            EditorGUILayout.EndVertical();

            if (!valueHasChanged)
            {
                return;
            }

            Repaint();
            EditorUtility.SetDirty(_config);
        }
コード例 #3
0
        /// <summary>
        /// Renders the controls for an individual <see cref="ValidationLogTreeViewItem"/> <paramref name="viewItem"/>
        /// in <see cref="Rect"/> <paramref name="controlsRect"/>.
        /// </summary>
        /// <param name="controlsRect"></param>
        /// <param name="viewItem"></param>
        private static void OnControlsGUI(Rect controlsRect, ValidationLogTreeViewItem viewItem)
        {
            var rect = controlsRect;

            rect.y     += 3f;
            rect.height = EditorGUIUtility.singleLineHeight;

            var prefixRect = new Rect(rect)
            {
                width = 80f
            };
            var fieldRect = new Rect(rect)
            {
                width = rect.width - prefixRect.width,
                x     = rect.x + prefixRect.width
            };

            EditorGUI.LabelField(prefixRect, EditorConstants.TreeViewAreaLabel, EditorStyles.boldLabel);
            EditorGUI.LabelField(fieldRect, viewItem.Log.GetSourceDescription());

            prefixRect.y    += rect.height + EditorGUIUtility.standardVerticalSpacing;
            fieldRect.y      = prefixRect.y;
            fieldRect.height = EditorGUIUtility.singleLineHeight;

            EditorGUI.LabelField(prefixRect, EditorConstants.TreeViewObjectLabel, EditorStyles.boldLabel);
            EditorGUI.LabelField(fieldRect, viewItem.Log.objectPath);

            prefixRect.y    += rect.height + EditorGUIUtility.standardVerticalSpacing;
            fieldRect.y      = prefixRect.y;
            fieldRect.height = (rect.height + EditorGUIUtility.standardVerticalSpacing) * 2f;

            var charactersPerRow = GraphicsTools.GetCharactersPerRow(fieldRect, viewItem.Log.message);
            var multiLineMessage = GraphicsTools.GetMultilineString(viewItem.Log.message, charactersPerRow);

            fieldRect.height = 2 * (EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(prefixRect, EditorConstants.TreeViewMessageLabel,
                                 EditorStyles.boldLabel);
            EditorGUI.TextArea(fieldRect, multiLineMessage, EditorStyles.label);

            EditorGUI.LabelField(fieldRect, multiLineMessage);

            rect.y = fieldRect.y + fieldRect.height + EditorGUIUtility.standardVerticalSpacing;

            var buttonRect = rect;

            buttonRect.width   = 200f;
            buttonRect.height *= 1.25f;

            if ((viewItem.Log.source == LogSource.Scene ||
                 viewItem.Log.source == LogSource.Project) && viewItem.Log.HasObjectPath())
            {
                EditorGUI.BeginDisabledGroup(!viewItem.Log.CanPingObject());
                if (GUI.Button(buttonRect, EditorConstants.PingObjectButtonText))
                {
                    ProjectTools.TryPingObject(viewItem.Log);
                }

                EditorGUI.EndDisabledGroup();
            }

            buttonRect.x += 220f;

            if (viewItem.Log.source == LogSource.Scene)
            {
                EditorGUI.BeginDisabledGroup(!viewItem.Log.CanLoadScene());
                if (GUI.Button(buttonRect, EditorConstants.LoadSceneButtonText))
                {
                    EditorSceneManager.OpenScene(viewItem.Log.scenePath);
                }

                EditorGUI.EndDisabledGroup();
            }
        }