Example #1
0
        private string GenerateUniqueName(IInspector inspector)
        {
            var type = inspector.GetType();

            List <IInspector> activeInstancesOfSameType;

            if (!activeInstancesByType.TryGetValue(type, out activeInstancesOfSameType))
            {
                                #if DEV_MODE
                Debug.LogError("GenerateUniqueName for inspector but activeInstancesByType did not yet contain the inspector");
                                #endif
                return(type.Name);
            }

            int count = activeInstancesOfSameType.Count;
            if (count <= 1)
            {
                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(count == 1 && activeInstancesOfSameType[0] == inspector);
                                #endif
                return(type.Name);
            }

            return(type.Name + " (" + StringUtils.ToString(count) + ")");
        }
Example #2
0
        private void AddToActiveInstances([NotNull] IInspector inspector)
        {
            activeInstances.Add(inspector);

            var inspectorType = inspector.GetType();

            List <IInspector> activeInstancesOfSameType;

            if (!activeInstancesByType.TryGetValue(inspectorType, out activeInstancesOfSameType))
            {
                activeInstancesOfSameType            = new List <IInspector>(1);
                activeInstancesByType[inspectorType] = activeInstancesOfSameType;
            }
            activeInstancesOfSameType.Add(inspector);

            InstanceUniqueNames.Add(GenerateUniqueName(inspector));

                        #if DEV_MODE
            Debug.Assert(activeInstances.Count == InstanceUniqueNames.Count);
                        #endif

            if (OnNewInspectorRegistered != null)
            {
                OnNewInspectorRegistered(inspector);
            }
        }
Example #3
0
        public void OnDisposing([NotNull] IInspector disposing)
        {
            if (lastSelectedInspector == disposing)
            {
                lastSelectedInspector = null;
            }

            var type = disposing.GetType();
            var lastSelectedInspectorOfSameType = GetLastSelectedInspector(type);

            if (lastSelectedInspectorOfSameType == disposing)
            {
                lastSelectedInspectors.Remove(type);
            }

            var inspectorDrawer = disposing.InspectorDrawer;

            if (inspectorDrawer != null)
            {
                if (inspectorDrawer.NowClosing)
                {
                                        #if DEV_MODE && DEBUG_DISPOSE
                    UnityEngine.Debug.Log("OnDisposing(" + disposing + "): NowClosing was " + StringUtils.True);
                                        #endif

                    var inspectorDrawerType         = inspectorDrawer.GetType();
                    var lastSelectedInspectorDrawer = GetLastSelectedInspectorDrawer(inspectorDrawerType);
                    if (lastSelectedInspectorDrawer == inspectorDrawer)
                    {
                                                #if DEV_MODE && DEBUG_DISPOSE
                        UnityEngine.Debug.Log("OnDisposing(" + disposing + "): removed " + inspectorDrawer.GetType().Name + " from lastSelectedInspectorDrawers");
                                                #endif
                        lastSelectedInspectorDrawers.Remove(inspectorDrawerType);
                    }

                                        #if UNITY_EDITOR
                    if (lastSelectedEditorWindow == inspectorDrawer)
                    {
                                                #if DEV_MODE && DEBUG_DISPOSE
                        UnityEngine.Debug.Log("OnDisposing(" + disposing + "): setting lastSelectedEditorWindow to null");
                                                #endif
                        lastSelectedEditorWindow = null;
                    }
                                        #endif
                }
                                #if DEV_MODE && DEBUG_DISPOSE
                else
                {
                    UnityEngine.Debug.Log("OnDisposing(" + disposing + "): NowClosing was " + StringUtils.False);
                }
                                #endif
            }
            else
            {
                                #if DEV_MODE && DEBUG_DISPOSE
                UnityEngine.Debug.Log("OnDisposing(" + disposing + "): inspectorDrawer was null!");
                                #endif

                CleanUpLastSelectedInspectorDrawers();
            }
        }
Example #4
0
        public string GetUniqueName([NotNull] IInspector inspector)
        {
            int index = activeInstances.IndexOf(inspector);

            return(index == -1 ? inspector.GetType().Name : instanceUniqueNames[index]);
        }