示例#1
0
        public void AddProfileRecursive(IValidationProfile profile, OdinMenuItem menuItem = null)
        {
            menuItem = menuItem ?? this.RootMenuItem;

            var newMenuItem = new OdinMenuItem(this, profile.Name, profile)
            {
                Icon = profile.GetProfileIcon()
            };

            this.childMenuItemLookup[profile] = newMenuItem;

            if (profile is ValidationProfileAsset)
            {
                var wrappedProfile = (profile as ValidationProfileAsset).GetWrappedProfile();
                this.childMenuItemLookup[wrappedProfile] = newMenuItem;
            }

            menuItem.ChildMenuItems.Add(newMenuItem);

            foreach (var childProfile in profile.GetNestedValidationProfiles())
            {
                this.AddProfileRecursive(childProfile, newMenuItem);
            }

            if (menuItem == this.RootMenuItem)
            {
                this.EnumerateTree().ForEach(x => x.Toggled = true);
                this.UpdateMenuTree();
            }
        }
        private void OpenValidator(List <IValidationProfile> profilesToRun, IValidationProfile actuallyFailingProfile)
        {
            IValidationProfile profile;

            if (profilesToRun.Count == 0)
            {
                return;
            }
            else if (profilesToRun.Count == 1)
            {
                profile = profilesToRun[0];
            }
            else if (profilesToRun.All(n => n is ValidationProfileAsset))
            {
                profile = new ValidationCollectionProfile()
                {
                    Name        = "Failed '" + this.Name + "' hook profiles",
                    Description = "These are the profiles that failed when the hook was executed",
                    Profiles    = profilesToRun.Cast <ValidationProfileAsset>().ToArray()
                };
            }
            else
            {
                profile = actuallyFailingProfile;
            }

            if (profile != null)
            {
                ValidationProfileManagerWindow.OpenProjectValidatorWithProfile(profile, true);
            }
        }
示例#3
0
        public void ScanProfile(IValidationProfile profile)
        {
            EditorApplication.delayCall += () =>
            {
                var results = new List <ValidationProfileResult>();
                this.validationProfileTree.CleanProfile(profile);

                try
                {
                    foreach (var result in profile.Validate(this.runner))
                    {
                        this.validationProfileTree.AddResultToTree(result);
                        results.Add(result);

                        if (GUIHelper.DisplaySmartUpdatingCancellableProgressBar(result.Profile.Name, result.Name, result.Progress))
                        {
                            break;
                        }
                    }
                }
                finally
                {
                    EditorUtility.ClearProgressBar();
                    this.overview.ProfileResults = results;
                    this.overview.Update();
                    this.validationProfileTree.MarkDirty();
                    this.validationProfileTree.UpdateMenuTree();
                    this.validationProfileTree.AddErrorAndWarningIcons();
                }
            };
        }
        protected override void Initialize()
        {
            this.menuTreeWidth  = this.GetPersistentValue <float>("menuTreeWidth", 320);
            this.overviewHeight = this.GetPersistentValue <float>("overviewHeight", 300);
            this.columns        = new List <ResizableColumn>()
            {
                ResizableColumn.FlexibleColumn(this.menuTreeWidth.Value, 80), ResizableColumn.DynamicColumn(0, 200)
            };
            this.runner                = new ValidationRunner();
            this.overview              = new ValidationOverview();
            this.editor                = this.ValueEntry.SmartValue;
            this.profile               = this.editor.Profile;
            this.sourceProperty        = this.Property.Children["selectedSourceTarget"];
            this.validationProfileTree = new ValidationProfileTree();
            this.overviewToggle        = this.GetPersistentValue <bool>("overviewToggle", true);

            this.validationProfileTree.Selection.SelectionChanged += (x) =>
            {
                if (x == SelectionChangedType.ItemAdded)
                {
                    var value  = this.validationProfileTree.Selection.SelectedValue;
                    var result = value as ValidationProfileResult;
                    if (result != null)
                    {
                        this.editor.SetTarget(result.GetSource());
                    }
                    else
                    {
                        this.editor.SetTarget(value);
                    }
                }
            };

            this.overview.OnProfileResultSelected += result =>
            {
                var mi = this.validationProfileTree.GetMenuItemForObject(result);
                mi.Select();
                var source = result.GetSource();
                this.editor.SetTarget(source);
            };

            this.validationProfileTree.AddProfileRecursive(this.ValueEntry.SmartValue.Profile);

            OdinMenuTree.ActiveMenuTree = this.validationProfileTree;

            if (this.editor.ScanProfileImmediatelyWhenOpening)
            {
                this.editor.ScanProfileImmediatelyWhenOpening = false;
                this.ScanProfile(this.editor.Profile);
            }
        }
示例#5
0
        public static void OpenProjectValidatorWithProfile(IValidationProfile profile, bool scanProfileImmediately = false)
        {
            ValidationProfileManagerWindow window = GetWindow <ValidationProfileManagerWindow>();

            window.Show();
            window.position = GUIHelper.GetEditorWindowRect().AlignCenter(670, 700);
            window.pager    = new SlidePageNavigationHelper <object>();
            window.pager.PushPage(new ValidationProfileManagerOverview(window.pager), "Overview");

            ValidationProfileEditor editor = new ValidationProfileEditor(profile);

            editor.ScanProfileImmediatelyWhenOpening = scanProfileImmediately;
            window.pager.PushPage(new ValidationProfileEditorWrapper(editor), profile.Name);
        }
        private void RebuildChildMenuItemLookup()
        {
            this.childMenuItemLookup.Clear();

            foreach (OdinMenuItem item in this.EnumerateTree())
            {
                this.childMenuItemLookup[item.Value] = item;

                if (item.Value is ValidationProfileAsset)
                {
                    IValidationProfile wrappedProfile = (item.Value as ValidationProfileAsset).GetWrappedProfile();
                    this.childMenuItemLookup[wrappedProfile] = item;
                }
            }
        }
示例#7
0
        public void CleanProfile(IValidationProfile profile)
        {
            OdinMenuItem menuItem;

            if (this.childMenuItemLookup.TryGetValue(profile, out menuItem))
            {
                var allProfileMenuItems = menuItem.GetChildMenuItemsRecursive(true).Where(x => x.Value is IValidationProfile).ToList();

                foreach (var pi in allProfileMenuItems)
                {
                    pi.ChildMenuItems.RemoveAll(x => !(x.Value is IValidationProfile));
                }
            }

            this.MarkDirty();
            this.RebuildChildMenuItemLookup();
        }
示例#8
0
        public override IEnumerable <ValidationProfileResult> Validate(ValidationRunner runner)
        {
            var partialProgress         = 0f;
            var partialProgressStepSize = 1f / this.Profiles.Length;

            for (int i = 0; i < this.Profiles.Length; i++)
            {
                IValidationProfile profile = this.Profiles[i];
                foreach (var result in profile.Validate(runner))
                {
                    result.Progress = result.Progress * partialProgressStepSize + partialProgress;
                    yield return(result);
                }

                partialProgress += partialProgressStepSize;
            }
        }
示例#9
0
        private void DrawCard(IValidationProfile profile)
        {
            GUIHelper.RequestRepaint();
            GUILayout.BeginVertical();
            bool isMouseIver = GUIHelper.CurrentWindowHasFocus && GUIHelper.GetCurrentLayoutRect().Contains(Event.current.mousePosition);

            GUIHelper.PushColor(new Color(1, 1, 1, (EditorGUIUtility.isProSkin ? 0.25f : 0.45f) * (isMouseIver ? 2 : 1)));
            GUILayout.BeginHorizontal(SirenixGUIStyles.CardStyle);
            GUIHelper.PopColor();
            {
                string profileName        = profile.Name;
                string profileDescription = profile.Description;

                if (string.IsNullOrEmpty(profileName) || profileName.Trim().Length == 0)
                {
                    profileName = "(No Name)";
                }

                if (string.IsNullOrEmpty(profileDescription) || profileDescription.Trim().Length == 0)
                {
                    profileDescription = "(No Description)";
                }

                GUILayout.BeginVertical();
                GUILayout.Label(profileName, SirenixGUIStyles.BoldTitle);
                GUILayout.Label(profileDescription, SirenixGUIStyles.MultiLineLabel);
                GUILayout.EndVertical();
                GUILayout.Space(40);

                Rect rect     = GUIHelper.GetCurrentLayoutRect();
                Rect btnsRect = rect.Padding(20).AlignRight(20).AlignCenterY(20);
                if (SirenixEditorGUI.IconButton(btnsRect, EditorIcons.Pen))
                {
                    GUIHelper.OpenInspectorWindow(profile as UnityEngine.Object);
                }

                if (GUI.Button(rect, GUIContent.none, GUIStyle.none))
                {
                    this.pager.PushPage(new ValidationProfileManagerWindow.ValidationProfileEditorWrapper(new ValidationProfileEditor(profile)), profile.Name);
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
示例#10
0
        public static void OpenProjectValidatorWithProfile(IValidationProfile profile, bool scanProfileImmediately = false)
        {
            var window = Resources.FindObjectsOfTypeAll <ValidationProfileManagerWindow>().FirstOrDefault();

            if (window)
            {
                window.Focus();
            }
            else
            {
                window          = GetWindow <ValidationProfileManagerWindow>();
                window.position = GUIHelper.GetEditorWindowRect().AlignCenter(670, 700);
                window.Show();
            }

            window.pager = new SlidePageNavigationHelper <object>();
            window.pager.PushPage(new ValidationProfileManagerOverview(window.pager), "Overview");

            var editor = new ValidationProfileEditor(profile);

            editor.ScanProfileImmediatelyWhenOpening = scanProfileImmediately;
            window.pager.PushPage(new ValidationProfileEditorWrapper(editor), profile.Name);
        }
        public void OnHookExecuting()
        {
            using (var runner = new ValidationRunner())
            {
                bool stopTriggeringEvent = false;

                try
                {
                    foreach (var validation in this.Validations)
                    {
                        bool openValidatorWindow = false;
                        IValidationProfile actuallyFailingProfile = null;

                        try
                        {
                            foreach (var profile in validation.ProfilesToRun)
                            {
                                foreach (var result in profile.Validate(runner))
                                {
                                    if (GUIHelper.DisplaySmartUpdatingCancellableProgressBar("Executing Validation Hook: " + this.Name + " (Profile: " + profile.Name + ")", result.Name, result.Progress))
                                    {
                                        // Cancel validation
                                        return;
                                    }

                                    foreach (var subResult in result.Results)
                                    {
                                        bool couldExitFromFailure = false;

                                        if (subResult.ResultType == ValidationResultType.Error)
                                        {
                                            if (validation.HasActionFlag(AutomatedValidation.Action.LogError))
                                            {
                                                var source = result.GetSource() as UnityEngine.Object;
                                                Debug.LogError("Validation error on object '" + source + "', path '" + subResult.Path + "': " + subResult.Message, source);
                                            }

                                            if (validation.HasActionFlag(AutomatedValidation.Action.OpenValidatorIfError))
                                            {
                                                openValidatorWindow  = true;
                                                couldExitFromFailure = true;
                                            }

                                            if (validation.HasActionFlag(AutomatedValidation.Action.StopHookEventOnError))
                                            {
                                                stopTriggeringEvent  = true;
                                                couldExitFromFailure = true;
                                            }
                                        }
                                        else if (subResult.ResultType == ValidationResultType.Warning)
                                        {
                                            if (validation.HasActionFlag(AutomatedValidation.Action.LogWarning))
                                            {
                                                var source = result.GetSource() as UnityEngine.Object;
                                                Debug.LogWarning("Validation warning on object '" + source + "', path '" + subResult.Path + "': " + subResult.Message, source);
                                            }

                                            if (validation.HasActionFlag(AutomatedValidation.Action.OpenValidatorIfWarning))
                                            {
                                                openValidatorWindow  = true;
                                                couldExitFromFailure = true;
                                            }

                                            if (validation.HasActionFlag(AutomatedValidation.Action.StopHookEventOnWarning))
                                            {
                                                stopTriggeringEvent  = true;
                                                couldExitFromFailure = true;
                                            }
                                        }

                                        if (couldExitFromFailure)
                                        {
                                            actuallyFailingProfile = profile;

                                            if (!this.FinishValidationOnFailures)
                                            {
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        finally
                        {
                            if (openValidatorWindow)
                            {
                                if (this.Hook is OnPlayValidationHook)
                                {
                                    stopTriggeringEvent = true;
                                }

                                this.OpenValidator(validation.ProfilesToRun, actuallyFailingProfile);
                            }

                            if (stopTriggeringEvent)
                            {
                                this.Hook.StopTriggeringEvent();
                            }
                        }
                    }
                }
                finally
                {
                    EditorUtility.ClearProgressBar();
                }
            }
        }
示例#12
0
 public ValidationProfileEditor(IValidationProfile profile)
 {
     this.Profile = profile;
 }