Exemplo n.º 1
0
        static PersistentContextCache()
        {
            EditorApplication.update -= UpdateCallback;
            EditorApplication.update += UpdateCallback;

            UnityEditorEventUtility.DelayAction(() => Instance.LoadCache());
        }
Exemplo n.º 2
0
 static CustomEditorLoader()
 {
     if (InspectorConfig.HasInstanceLoaded)
     {
         InspectorConfig.Instance.UpdateOdinEditors();
     }
     else
     {
         UnityEditorEventUtility.DelayAction(() => InspectorConfig.Instance.UpdateOdinEditors());
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        /// <param name="toolbarStyle">Not yet documented.</param>
        public void DrawSearchToolbar(GUIStyle toolbarStyle = null)
        {
            var config = this.Config;

            var searchFieldRect = GUILayoutUtility.GetRect(0, config.SearchToolbarHeight, GUILayoutOptions.ExpandWidth(true));

            if (Event.current.type == EventType.Repaint)
            {
                (toolbarStyle ?? SirenixGUIStyles.ToolbarBackground).Draw(searchFieldRect, GUIContent.none, 0);
            }

            searchFieldRect       = searchFieldRect.HorizontalPadding(5).AlignMiddle(16);
            searchFieldRect.xMin += 3;
            searchFieldRect.y    += 1;

            EditorGUI.BeginChangeCheck();
            config.SearchTerm = this.DrawSearchField(searchFieldRect, config.SearchTerm, config.AutoFocusSearchBar);
            var changed = EditorGUI.EndChangeCheck();

            if (changed && this.hasRepaintedCurrentSearchResult)
            {
                // We want fast visual search feedback. If the user is typing faster than the window can repaint,
                // then no results will be visible while he's typing. this.hasRepaintedCurrentSearchResult fixes that.

                this.hasRepaintedCurrentSearchResult = false;
                bool doSearch = !string.IsNullOrEmpty(config.SearchTerm);
                if (doSearch)
                {
                    this.DrawInSearchMode = true;
                    this.EnumerateTree().ForEach(x => x.IsVisible = config.SearchFunction(x));
                }
                else
                {
                    if (this.DrawInSearchMode)
                    {
                        this.DrawInSearchMode = false;
                        var last = this.selection.LastOrDefault();
                        UnityEditorEventUtility.DelayAction(() => this.scrollToAndCenter = last);
                    }

                    this.EnumerateTree()
                    .ForEach(x => x.IsVisible = true);

                    this.Selection
                    .SelectMany(x => x.GetParentMenuItemsRecursive(false))
                    .ForEach(x => x.Toggled = true);
                }
            }

            if (Event.current.type == EventType.Repaint)
            {
                this.hasRepaintedCurrentSearchResult = true;
            }
        }
Exemplo n.º 4
0
        private void SetupWindow(OdinEditorWindow window, EditorWindow prevSelectedWindow)
        {
            var prevFocusId      = GUIUtility.hotControl;
            var prevKeybaorFocus = GUIUtility.keyboardControl;

            this.popupWindowInstance = window;

            window.WindowPadding = new Vector4();

            bool wasConfirmed = false;

            this.SelectionTree.Selection.SelectionConfirmed += x => UnityEditorEventUtility.DelayAction(() =>
            {
                if (this.IsValidSelection(this.GetCurrentSelection()))
                {
                    wasConfirmed = true;
                    window.Close();

                    if (prevSelectedWindow)
                    {
                        prevSelectedWindow.Focus();
                    }
                }
            });

            window.OnBeginGUI += () =>
            {
                if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
                {
                    UnityEditorEventUtility.DelayAction(() =>
                    {
                        window.Close();
                    });

                    if (prevSelectedWindow)
                    {
                        prevSelectedWindow.Focus();
                    }

                    Event.current.Use();
                }
            };

            window.OnClose += () =>
            {
                if (!wasConfirmed && this.SelectionCancelled != null)
                {
                    this.SelectionCancelled();
                }

                GUIUtility.hotControl      = prevFocusId;
                GUIUtility.keyboardControl = prevKeybaorFocus;
            };
        }
 private static void OpenScene(string scenePath)
 {
     UnityEditorEventUtility.DelayAction(() =>
     {
         var scene = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePath);
         AssetDatabase.OpenAsset(scene);
         if (scene as SceneAsset)
         {
             UnityEditorEventUtility.DelayAction(() =>
             {
                 GameObject.FindObjectsOfType <Transform>()
                 .Where(x => x.parent == null && x.childCount > 0)
                 .OrderByDescending(x => x.GetSiblingIndex())
                 .Select(x => x.transform.GetChild(0).gameObject)
                 .ForEach(x => EditorGUIUtility.PingObject(x));
             });
         }
     });
 }
 static PersistentContextCache()
 {
     UnityEditorEventUtility.DelayAction(() => Instance.EnsureIsInitialized());
 }
Exemplo n.º 7
0
 void ISerializationCallbackReceiver.OnAfterDeserialize()
 {
     this.drawingConfig.UpdateCaches();
     UnityEditorEventUtility.DelayAction(() => this.UpdateOdinEditors());
 }
 public static void PersistentContextCache_Constructor()
 {
     UnityEditorEventUtility.DelayAction(() => Instance.EnsureIsInitialized());
 }
Exemplo n.º 9
0
        private void SetupWindow(OdinEditorWindow window, EditorWindow prevSelectedWindow)
        {
            var prevFocusId      = GUIUtility.hotControl;
            var prevKeybaorFocus = GUIUtility.keyboardControl;

            this.popupWindowInstance = window;

            window.WindowPadding = new Vector4();

            bool wasConfirmed = false;

            this.SelectionTree.Selection.SelectionConfirmed += x =>
            {
                var ctrl = Event.current != null && Event.current.modifiers != EventModifiers.Control;

                UnityEditorEventUtility.DelayAction(() =>
                {
                    if (this.IsValidSelection(this.GetCurrentSelection()))
                    {
                        wasConfirmed = true;

                        // This is so that users can hold control to trigger changes, without the window automatically closing.
                        if (ctrl)
                        {
                            window.Close();

                            if (prevSelectedWindow)
                            {
                                prevSelectedWindow.Focus();
                            }
                        }
                    }
                });
            };

            window.OnBeginGUI += () =>
            {
                if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
                {
                    UnityEditorEventUtility.DelayAction(() =>
                    {
                        window.Close();
                    });

                    if (prevSelectedWindow)
                    {
                        prevSelectedWindow.Focus();
                    }

                    Event.current.Use();
                }
            };

            window.OnClose += () =>
            {
                if (!wasConfirmed && this.SelectionCancelled != null)
                {
                    this.SelectionCancelled();
                }

                GUIUtility.hotControl      = prevFocusId;
                GUIUtility.keyboardControl = prevKeybaorFocus;
            };
        }
        private void DrawCard(OdinGettingStartedWindowData.Card card)
        {
            if (card.Title != null)
            {
                GUILayout.Label(card.Title, cardTitleStyle);
            }

            if (card.Description != null)
            {
                GUILayout.Label(card.Description, SirenixGUIStyles.MultiLineLabel);
            }

            if (card.Title != null || card.Description != null)
            {
                GUILayout.Space(5);
            }

            currBtnCount = 0;
            bool needsImport = card.AssetPathFromPackage != null && !File.Exists(card.AssetPathFromPackage);


            if (needsImport)
            {
                GUIHelper.PushGUIEnabled(false);
            }
            for (int i = 0; i < card.CustomActions.Length; i++)
            {
                var action = card.CustomActions[i];
                if (Button(action.Name))
                {
                    UnityEditorEventUtility.DelayAction(() =>
                    {
                        action.Action();
                    });
                }
            }
            if (card.SubPage != null && Button(card.SubPageTitle ?? card.SubPage.Title))
            {
                this.pager.PushPage(card.SubPage, card.SubPage.Title);
            }
            if (needsImport)
            {
                GUIHelper.PopGUIEnabled();
            }

            if (needsImport)
            {
                if (card.Package != null)
                {
                    var hasPackage = File.Exists(card.Package);
                    var text       = "Import " + Path.GetFileNameWithoutExtension(card.Package);

                    GUIHelper.PushGUIEnabled(hasPackage);
                    if (Button(text))
                    {
                        UnityEditorEventUtility.DelayAction(() =>
                        {
                            AssetDatabase.ImportPackage(card.Package, true);
                        });
                    }
                    GUIHelper.PopGUIEnabled();
                }
            }
        }