예제 #1
0
        public virtual void Dispose()
        {
            var disposing = this;

            pool.Pool(ref disposing);
        }
예제 #2
0
        /// <summary>
        /// Handles disposing references to the inspector from everywhere in InspectorManager such as from lists active and last selected instances.
        ///
        /// It is important that this gets called every time an inspector is no longer used (i.e. it's drawer is closed).
        /// </summary>
        /// <typeparam name="TInspector"> Type of the inspector. </typeparam>
        /// <param name="disposing"> [in,out] The disposing. </param>
        /// <param name="poolForReuse"> (Optional) True to pool for reuse. </param>
        public void Dispose <TInspector>(ref TInspector disposing, bool poolForReuse = true) where TInspector : class, IInspector
        {
            int index = activeInstances.IndexOf(disposing);

            if (index != -1)
            {
                activeInstances.RemoveAt(index);
                InstanceUniqueNames.RemoveAt(index);
            }

            var type = disposing.GetType();
            List <IInspector> activeInstancesOfSameType;

            if (activeInstancesByType.TryGetValue(type, out activeInstancesOfSameType))
            {
                activeInstancesOfSameType.Remove(disposing);
            }

            if (ReferenceEquals(selected.Inspector, disposing))
            {
                                #if DEV_MODE
                Debug.Log("Clearing selected because selected inspector (" + StringUtils.ToString(selected.Inspector) + ") was equal to inspector being disposed (" + StringUtils.ToString(selected.Inspector) + ")");
                                #endif
                selected.Clear(ReasonSelectionChanged.Dispose, null);
            }

            if (mouseovered.Inspector == disposing)
            {
                mouseovered.Clear();
            }

            if (mouseDownInfo.Inspector == disposing)
            {
                mouseDownInfo.Clear();
            }

            selected.OnDisposing(disposing);

            disposing.Dispose();

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(!activeInstances.Contains(disposing));
            Debug.Assert(activeInstancesOfSameType != null && !activeInstancesOfSameType.Contains(disposing));
            Debug.Assert(!pool.Contains(disposing));
            Debug.Assert(LastSelectedInspector != disposing);
                        #endif

            if (poolForReuse)
            {
                IInspector dispose = disposing;
                pool.Pool(ref dispose);
            }

            if (activeInspector == disposing)
            {
                int count = activeInstances.Count;
                ActiveInspector = count > 0 ? activeInstances[count - 1] : null;
            }

            disposing = null;
        }