private void OpenObject()
            {
                var obj = this.UnityObject;

                if (obj == null)
                {
                    obj = AssetDatabase.LoadAssetAtPath(this.StringValue, typeof(UnityEngine.Object));
                }

                EditorGUIUtility.PingObject(obj);
                if (obj as ScriptableObject)
                {
                    var window = OdinEditorWindow.InspectObject(obj);
                    window.position = GUIHelper.GetEditorWindowRect().AlignCenter(windowSize.x, windowSize.y);
                }
                else
                {
                    UnityEditorEventUtility.DelayAction(() =>
                    {
                        AssetDatabase.OpenAsset(obj);
                        if (obj 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));
                            });
                        }
                    });
                }
            }
 private static void InitHooks()
 {
     UnityEditorEventUtility.DelayAction(() =>
     {
         foreach (AutomatedValidationHook item in OdinValidationConfig.Instance.Hooks)
         {
             if (item.Enabled)
             {
                 item.SetupHook();
             }
         }
     });
 }
示例#3
0
        private DragHandle BeginDragHandle(ListDrawerConfigInfo info, int j, int i)
        {
            var child      = info.property.Children[j];
            var dragHandle = DragAndDropManager.BeginDragHandle(child, (TElement)child.ValueEntry.WeakSmartValue, info.IsReadOnly ? DragAndDropMethods.Reference : DragAndDropMethods.Move);

            dragHandle.Enabled = info.Draggable;

            if (dragHandle.OnDragStarted)
            {
                ListDrawerStaticInfo.CurrentDroppingPropertyInfo = null;
                ListDrawerStaticInfo.CurrentDraggingPropertyInfo = info.property.Children[j];
                dragHandle.OnDragFinnished = dropEvent =>
                {
                    if (dropEvent == DropEvents.Moved)
                    {
                        if (dragHandle.IsCrossWindowDrag || (ListDrawerStaticInfo.CurrentDroppingPropertyInfo != null && ListDrawerStaticInfo.CurrentDroppingPropertyInfo.Tree != info.property.Tree))
                        {
                            // Make sure drop happens a bit later, as deseiralization and other things sometimes
                            // overrides the cahnge.
                            GUIHelper.RequestRepaint();
                            UnityEditorEventUtility.DelayAction(() =>
                            {
                                GUIHelper.RequestRepaint();
                                UnityEditorEventUtility.DelayAction(() =>
                                {
                                    GUIHelper.RequestRepaint();
                                    UnityEditorEventUtility.DelayAction(() =>
                                    {
                                        info.ListValueChanger.RemoveListElementAt(j, CHANGE_ID);
                                    });
                                });
                            });
                        }
                        else
                        {
                            info.ListValueChanger.RemoveListElementAt(j, CHANGE_ID);
                        }
                    }

                    ListDrawerStaticInfo.CurrentDraggingPropertyInfo = null;
                };
            }

            return(dragHandle);
        }
        private static void ScheduleHook()
        {
            if (HookHasExecuted)
            {
                return;
            }

            // This is the time people have to hook into the event

            int counter = 0;

            Action count = null;

            count = () =>
            {
                if (HookHasExecuted)
                {
                    return;
                }
                if (counter >= 10)
                {
                    //Debug.LogWarning("Executing project start hook");
                    HookHasExecuted        = true;
                    HookExecutedThisReload = true;

                    for (int i = 0; i < HookedEvents.Count; i++)
                    {
                        HookedEvents[i]();
                    }

                    HookedEvents.Clear();
                }
                else
                {
                    counter++;
                    UnityEditorEventUtility.DelayAction(count);
                }
            };

            UnityEditorEventUtility.DelayAction(count);
        }
示例#5
0
        private static void InitHooks()
        {
            if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null || UnityEditorInternal.InternalEditorUtility.inBatchMode)
            {
                if (!HasInstanceLoaded)
                {
                    LoadInstanceIfAssetExists();
                }

                if (!HasInstanceLoaded)
                {
                    Debug.LogError("Odin's validation config asset could not be loaded during batch mode or headless run of the Unity Editor. No validation has taken place, whether it was configured to do so or not.");
                    return;
                }
            }

            Action action = () =>
            {
                foreach (var item in OdinValidationConfig.Instance.Hooks)
                {
                    if (item.Enabled)
                    {
                        item.SetupHook();
                    }
                }
            };

            if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null || UnityEditorInternal.InternalEditorUtility.inBatchMode)
            {
                action();
            }
            else
            {
                UnityEditorEventUtility.DelayAction(action);
            }
        }
示例#6
0
        private static void Update()
        {
            bool dontDoIt =
                AssemblyUtilities.GetTypeByCachedFullName("Sirenix.Utilities.Editor.Commands.Command") != null ||
                AssemblyUtilities.GetTypeByCachedFullName("Sirenix.Utilities.Editor.Commands.EditorCommand") != null ||
                EditorPrefs.HasKey("PREVENT_SIRENIX_FILE_GENERATION");

            if (dontDoIt)
            {
                if (DEBUG)
                {
                    Debug.Log(new DirectoryInfo("Assets/" + SirenixAssetPaths.SirenixAssembliesPath).FullName);
                }
                if (DEBUG)
                {
                    Debug.Log("Didn't do it.");
                }
                return;
            }

            if (!File.Exists("Assets/" + SirenixAssetPaths.SirenixPluginPath + "Odin Inspector/Scripts/Editor/OdinUpgrader.cs"))
            {
                if (DEBUG)
                {
                    Debug.Log("The updater doesn't exist, which means the OdinUpgrader was probably just executed and deleted itself, but the program is still in memory.");
                }
                return;
            }

            if (numberOfTimesCalled <= 2)
            {
                // EditorApplication.isCompiling gives an error in 2017 that can't be silenced if called from InitializeOnLoadMethod or DidReloadScripts.
                // We'll just wait a few frames and then call it.
                UnityEditorEventUtility.DelayAction(Update);
                numberOfTimesCalled++;
                return;
            }

            if (counter == NUM_OF_FRAMES_WITHOUT_RECOMPILE)
            {
                if (DEBUG)
                {
                    Debug.Log("Upgrading");
                }
                Upgrade();
            }
            else
            {
                bool isCompiling = true;

                try
                {
                    isCompiling = EditorApplication.isCompiling;
                }
                catch
                {
                }
                finally
                {
                    counter = isCompiling ? 0 : counter + 1;
                }

                if (DEBUG)
                {
                    Debug.Log("Counting " + counter);
                }
                UnityEditorEventUtility.DelayAction(Update);
            }
        }
示例#7
0
    private void DrawCard(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(5f);
        }
        this.currBtnCount = 0;
        bool needImport = string.IsNullOrEmpty(card.ModuleFolderPath) && !File.Exists(card.ModuleFolderPath);

        if (needImport)
        {
            GUIHelper.PushGUIEnabled(false);
        }
        for (int i = 0; i < card.CustomActions.Count; i++)
        {
            var action = card.CustomActions[i];
            if (string.IsNullOrEmpty(action.Name) == false)
            {
                if (this.Button(action.Name))
                {
                    var m = typeof(CaomaoGettingStartedWindow).GetMethod(action.Action);
                    if (m != null)
                    {
                        m.Invoke(this, null);
                    }
                    else
                    {
                        Debug.LogError($"No Method{action.Name}");
                    }
                }
            }
            else
            {
                Debug.LogError("card == null");
            }
        }
        if (card.SubPage != null && !string.IsNullOrEmpty(card.SubPage.Title) && this.Button(card.SubPage.Title))
        {
            this.pager.PushPage(card.SubPage, card.SubPage.Title);
        }
        if (needImport)
        {
            GUIHelper.PopGUIEnabled();
        }
        if (!needImport && string.IsNullOrEmpty(card.Package) == false)
        {
            bool   enabled = File.Exists(card.Package);
            string txt     = "Import " + Path.GetFileNameWithoutExtension(card.Package);
            GUIHelper.PushGUIEnabled(enabled);
            if (this.Button(txt))
            {
                UnityEditorEventUtility.DelayAction(() =>
                {
                    AssetDatabase.ImportPackage(card.Package, true);
                });
            }
            GUIHelper.PopGUIEnabled();
        }
    }
示例#8
0
        private void EndDropZone(ListDrawerConfigInfo info)
        {
            if (info.DropZone.IsReadyToClaim)
            {
                ListDrawerStaticInfo.CurrentDraggingPropertyInfo = null;
                ListDrawerStaticInfo.CurrentDroppingPropertyInfo = info.property;
                object droppedObject = info.DropZone.ClaimObject();

                object[] values = new object[info.ListValueChanger.ValueCount];

                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = droppedObject;
                }

                //GUIHelper.RequestRepaint();
                //info.property.Tree.DelayAction(() =>
                //{
                //    GUIHelper.RequestRepaint();
                //    info.ListValueChanger.InsertListElementAt(Mathf.Clamp(info.InsertAt, 0, info.property.Children.Count), values, CHANGE_ID);
                //});

                if (info.DropZone.IsCrossWindowDrag)
                {
                    // If it's a cross-window drag, the changes will for some reason be lost if we don't do this.
                    GUIHelper.RequestRepaint();
                    UnityEditorEventUtility.DelayAction(() =>
                    {
                        UnityEditorEventUtility.DelayAction(() =>
                        {
                            UnityEditorEventUtility.DelayAction(() =>
                            {
                                info.ListValueChanger.InsertListElementAt(Mathf.Clamp(info.InsertAt, 0, info.property.Children.Count), values, CHANGE_ID);
                            });
                        });
                    });
                }
                else
                {
                    info.ListValueChanger.InsertListElementAt(Mathf.Clamp(info.InsertAt, 0, info.property.Children.Count), values, CHANGE_ID);
                }
            }
            else
            {
                UnityEngine.Object[] droppedObjects = HandleUnityObjectsDrop(info);
                if (droppedObjects != null)
                {
                    foreach (var obj in droppedObjects)
                    {
                        object[] values = new object[info.ListValueChanger.ValueCount];

                        for (int i = 0; i < values.Length; i++)
                        {
                            values[i] = obj;
                        }

                        info.ListValueChanger.InsertListElementAt(Mathf.Clamp(info.InsertAt, 0, info.property.Children.Count), values, CHANGE_ID);
                    }
                }
            }
            DragAndDropManager.EndDropZone();
        }