예제 #1
0
        /// <summary>
        /// Checks if inspected contains any targets that equal null, and if so,
        /// attempts to recover references to them. Any targets that remain null
        /// after these attempts get removed from the inspected array.
        /// </summary>
        /// <returns> True if there were no null targets, or any null targets could be recovered. Returns false if there were unrecoverable null targets. </returns>
        public bool TryRecoverAnyNullUnityObjects()
        {
            bool noUnfixableNullsFound = true;

            for (int n = inspected.Length - 1; n >= 0; n--)
            {
                var target = inspected[n];
                if (target == null)
                {
                    if (UnityObjectExtensions.TryToFixNull(ref target))
                    {
                                                #if DEV_MODE
                        Debug.LogWarning("InspectorState.inspected[" + n + "] (\"" + target.name + "\") was null, but was able to recover it using InstanceID.");
                                                #endif
                        continue;
                    }

                                        #if DEV_MODE
                    Debug.LogWarning("InspectorState.inspected[" + n + "] (\"" + (ReferenceEquals(target, null) ? "null" : target.name) + "\") was null and unrecoverable. Removing from array");
                                        #endif

                    // if could not recover target, remove null entry from array
                    inspected             = inspected.RemoveAt(n);
                    noUnfixableNullsFound = false;
                }
            }
            return(noUnfixableNullsFound);
        }
예제 #2
0
        /// <inheritdoc/>
        public void OnProjectOrHierarchyChanged(OnChangedEventSubject changed, ref bool hasNullReferences)
        {
            if (changed != OnChangedEventSubject.Project && changed != OnChangedEventSubject.Undefined)
            {
                return;
            }

            for (int n = targets.Length - 1; n >= 0; n--)
            {
                var target = targets[n];
                if (target == null)
                {
                    if (UnityObjectExtensions.TryToFixNull(ref target))
                    {
                                                #if DEV_MODE
                        Debug.LogWarning(ToString() + ".OnHierarchyChanged fixed targets[" + n + "] (\"" + target.name + "\") being null.");
                                                #endif
                        continue;
                    }

                                        #if DEV_MODE
                    Debug.Log(ToString() + ".OnHierarchyChanged targets[" + n + "] was null and could not be fixed.");
                                        #endif

                    hasNullReferences = true;
                }
            }

                        #if UNITY_EDITOR
            if (editor != null && Editors.DisposeIfInvalid(ref editor))
            {
                hasNullReferences = true;                 // set to true so that drawers get rebuilt, in case e.g. asset paths have changed.
            }

            if (assetEditor != null && Editors.DisposeIfInvalid(ref assetEditor))
            {
                hasNullReferences = true;                 // set to true so that drawers get rebuilt, in case e.g. asset paths have changed.
            }
                        #endif

            FetchAssetEditor();
            UpdateEditor();
        }
예제 #3
0
        public void RemoveUnloadedAndInvalidTargets()
        {
                        #if DEV_MODE && DEBUG_REMOVE_INVALID
            Debug.Log("SelectionHistory.RemoveReferencesToUnloadedOrInvalidScenes()");
                        #endif

            int count = history.Count;
            for (int n = count - 1; n >= 0; n--)
            {
                var objs = history[n];

                for (int o = objs.Length - 1; o >= 0; o--)
                {
                    var obj = objs[o];
                    if (obj == null)
                    {
                        if (!UnityObjectExtensions.TryToFixNull(ref obj))
                        {
                                                        #if DEV_MODE && DEBUG_REMOVE_INVALID
                            Debug.Log("Removing history[" + n + "][" + o + "]: because target no longer exists");
                                                        #endif

                            objs = objs.RemoveAt(o);
                        }
                    }
                }

                if (objs.Length == 0)
                {
                    history.RemoveAt(n);
                    if (currentIndex > n)
                    {
                        currentIndex--;
                    }

                                        #if DEV_MODE && DEBUG_REMOVE_INVALID
                    Debug.Log("Removed history[" + n + "] because none of the targets existed any longer. Index now " + index + " nad history.Count=" + history.Count);
                                        #endif
                }
            }
        }