Example #1
0
        private static void AddDefineIfMissingAndShowWelcomeScreenIfNotShown()
        {
            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += AddDefineIfMissingAndShowWelcomeScreenIfNotShown;
                return;
            }

            if (!ScriptingDefines.Contains(Define))
            {
                                #if DEV_MODE
                EditorPrefs.SetBool("PI.WelcomeScreenShown", false);                 // this makes testing welcome screen showing up easier
                                #endif

                UnityEngine.Debug.Log("Detected install of Power Inspector. Adding " + Define + " to Scripting Define Symbols in Player Settings.");
                ScriptingDefines.Add(Define);
                return;
            }

            if (ShouldShowWelcomeScreen())
            {
                // A NullReferenceException would occur in Unity 2019.3 beta when ShowUtility was called for the Welcome Screen without this delay
                EditorApplication.delayCall += ShowWelcomeScreen;
            }
        }
Example #2
0
        public static void SetupDelayed()
        {
            if (setupDone != SetupPhase.Unstarted)
            {
                return;
            }

            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += SetupDelayed;
                return;
            }

            // TypeExtensions is currently needed for popupmenu generation
            if (!TypeExtensions.IsReady)
            {
                EditorApplication.delayCall += SetupDelayed;
                return;
            }

            setupDone = SetupPhase.InProgress;

            // Make sure that Preferences have been fetched via AssetDatabase.LoadAssetAtPath before moving on to threaded code
            var preferences = InspectorUtility.Preferences;

            UnityEngine.Debug.Assert(preferences != null);

            // build syntax formatting on another thread to avoid UI slow downs when user
            // selects a large formatted text file
            ThreadPool.QueueUserWorkItem(SetupThreaded);
        }
Example #3
0
        private static void DelayedSetup()
        {
            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += DelayedSetup;
                return;
            }

            DrawGUI.OnNextBeginOnGUI(Setup, false);
        }
        private static void ApplyPreferencesWhenAssetDatabaseReady()
        {
            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += ApplyPreferencesWhenAssetDatabaseReady;
                return;
            }

            DrawGUI.OnNextBeginOnGUI(ApplyContextMenuPreferences, false);
        }
        public void ApplyRelevantUpdates()
        {
            if (currentVersion >= Version.CurrentAsInt)
            {
                return;
            }

            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += ApplyRelevantUpdates;
                return;
            }

            Platform.SetEditorMode();

            int  appliedUpdateCount = 0;
            bool updateWasApplied;
            var  updates = InspectorPreferencesUpdate.GetAllUpdates(this);

            do
            {
                updateWasApplied = false;

                foreach (var update in updates)
                {
                    if (update.ShouldApplyNext(currentVersion))
                    {
                        appliedUpdateCount++;
                        update.UpdateNow(this);
                        updateWasApplied = true;
                                                #if DEV_MODE && PI_ASSERTATIONS
                        Debug.Assert(currentVersion < update.ToVersion);
                                                #endif
                        currentVersion = update.ToVersion;
                        break;
                    }
                }

                if (appliedUpdateCount > 100)
                {
                    Debug.LogError("InspectorPreferences updater seems to have gotten stuck on an infinite loop!");
                    break;
                }
            }while(updateWasApplied);

                        #if DEV_MODE
            if (appliedUpdateCount > 0)
            {
                Debug.Log("Successfully applied " + appliedUpdateCount + "/" + updates.Length + " updates to preferences.");
            }
                        #endif
        }
Example #6
0
        private static void SubscribeForOnBeginOnGUIEvent()
        {
            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += SubscribeForOnBeginOnGUIEvent;
                return;
            }

            if (!initialized)
            {
                initialized = true;
                DrawGUI.OnEveryBeginOnGUI(DetectObjectPickerOpen, false);
                InspectorUtility.OnExecuteCommand += OnExecuteCommand;
            }
        }
Example #7
0
        private static void InstallPackages()
        {
            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += InstallPackages;
                return;
            }

            var packageInstallerGuids = AssetDatabase.FindAssets("t:PluginCompatibilityPackageInstaller");
            int count = packageInstallerGuids.Length;

                        #if DEV_MODE && DEBUG_ENABLED
            UnityEngine.Debug.Log("CompatibilityPackageManager found " + count + " PluginCompatibilityPackageInstallers");
                        #endif

            packageInstallers = new PluginCompatibilityPackageInstaller[count];

            List <PluginCompatibilityPackageInstaller> installPackages = null;

            for (int n = count - 1; n >= 0; n--)
            {
                var packageInstaller = AssetDatabase.LoadAssetAtPath <PluginCompatibilityPackageInstaller>(AssetDatabase.GUIDToAssetPath(packageInstallerGuids[n]));
                packageInstallers[n] = packageInstaller;

                                #if DEV_MODE
                UnityEngine.Debug.Log(StringUtils.ToColorizedString("PluginIsInstalled=", packageInstaller.PluginIsInstalled, ", CompatibilityPackageIsInstalled=", packageInstaller.CompatibilityPackageIsInstalled));
                                #endif

                if (packageInstaller.autoInstallEnabled && packageInstaller.PluginIsInstalled && !packageInstaller.CompatibilityPackageIsInstalled)
                {
                    if (installPackages == null)
                    {
                        installPackages = new List <PluginCompatibilityPackageInstaller>();
                    }
                    installPackages.Add(packageInstaller);
                }
            }

            if (installPackages != null)
            {
                AssetDatabase.StartAssetEditing();
                for (int n = installPackages.Count - 1; n >= 0; n--)
                {
                    installPackages[n].Install();
                }
                AssetDatabase.StopAssetEditing();
            }
        }
Example #8
0
        private static void Initialize()
        {
            if (initialized)
            {
                return;
            }

            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += Initialize;
                return;
            }

            initialized = true;

            DrawGUI.OnEveryBeginOnGUI(UpdateMousePosition, false);
        }
        private static void Setup()
        {
            // This helps fix issue where OdinEditor has not yet been injected into Unity's internal systems before building custom editor types for inspected components.
            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += Setup;
                return;
            }

            // Wait until Inspector contents have been rebuilt using deserialized cached drawers
            // until moving on to fully rebuilding drawers from scratch.
            // This is because the process of building all the drawers can take a couple of seconds,
            // and we don't want to keep the user waiting for this duration.
            if (isReady)
            {
                foreach (var inspector in InspectorManager.Instance().ActiveInstances)
                {
                    if (!inspector.SetupDone)
                    {
                                                #if DEV_MODE && DEBUG_SETUP
                        UnityEngine.Debug.Log("DefaultDrawerProviders - waiting until inspector Setup Done...");
                                                #endif
                        EditorApplication.delayCall += Setup;
                        return;
                    }
                }
                                #if DEV_MODE && DEBUG_SETUP
                UnityEngine.Debug.Log("Setup now done for all " + InspectorManager.Instance().ActiveInstances.Count + " inspectors");
                                #endif
            }

            isReady = false;

            // Make sure that Preferences have been fetched via AssetDatabase.LoadAssetAtPath before moving on to threaded code
            var preferences = InspectorUtility.Preferences;
            UnityEngine.Debug.Assert(preferences != null);

            ThreadPool.QueueUserWorkItem(SetupThreaded);
        }
Example #10
0
        private static void ApplyPreferences()
        {
            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += ApplyPreferences;
                return;
            }

            if (InspectorUtility.ActiveManager == null || !InspectorUtility.Preferences.SetupDone)
            {
                EditorApplication.delayCall += ApplyPreferences;
                return;
            }

            var addProperties = InspectorUtility.Preferences.propertyBlacklist;

            for (int n = addProperties.Length - 1; n >= 0; n--)
            {
                if (!Add(addProperties[n].ownerTypeName, addProperties[n].propertyName))
                {
                    Debug.LogWarning("Blacklisted property " + addProperties[n].ownerTypeName + "." + addProperties[n].propertyName + " does not exist.");
                }
            }
        }
Example #11
0
        private static void Initialize()
        {
            if (initialized)
            {
                return;
            }

                        #if UNITY_EDITOR
            if (!ApplicationUtility.IsReady())
            {
                EditorApplication.delayCall += Initialize;
                return;
            }
                        #endif


            initialized = true;

                        #if UNITY_2017_2_OR_NEWER
            EditorApplication.playModeStateChanged += OnPlaymodeStateChanged;
                        #else
            DrawGUI.OnEveryBeginOnGUI(DetectPlaymodeStateChanges, false);
                        #endif
        }