Пример #1
0
        public override void OnInspectorGUI()
        {
            EditorUI.Reset();
            ProxyEditor.GetInspector(this).SetTitle(this.title);
            ProxyEditor.GetInspectors().ForEach(x => x.wantsMouseMove = true);
            if (!Event.current.IsUseful())
            {
                return;
            }
            if (this.target is MonoBehaviour && this.target.As <MonoBehaviour>().InPrefabFile())
            {
                return;
            }
            this.BeginArea();
            bool fastInspector = EditorPref.Get <bool>("MonoBehaviourEditor-FastInspector");

            /*if(fastInspector && MonoBehaviourEditor.offScreen.ContainsKey(this)){
             *      GUILayout.Space(this.area.height);
             *      this.CheckChanges();
             *      return;
             * }*/
            if (Event.current.type == EventType.MouseMove)
            {
                Call.Delay(ProxyEditor.RepaintInspectors, 0.1f);
            }
            bool hideAllDefault = EditorPref.Get <bool>("MonoBehaviourEditor-HideAllDefault", false);

            this.hideDefault = EditorPref.Get <bool>("MonoBehaviourEditor-" + this.target.GetInstanceID() + "HideDefault", false);
            bool hideDefault = hideAllDefault || this.hideDefault;

            if (hideDefault)
            {
                this.SortDefaults();
            }
            this.serializedObject.Update();
            this.SortProperties();
            this.Setup();
            Type type = this.target.GetType();

            this.changed = false;
            bool showAdvanced   = EditorPref.Get <bool>("MonoBehaviourEditor-Advanced");
            bool showInternal   = EditorPref.Get <bool>("MonoBehaviourEditor-Internal");
            bool showDictionary = EditorPref.Get <bool>("MonoBehaviourEditor-Dictionary");

            EditorGUILayout.BeginVertical();
            foreach (var property in this.properties)
            {
                string[] attributes = this.serializedObject.targetObject.ListAttributes(property.name).Select(x => x.GetType().Name).ToArray();
                bool     isInternal = attributes.Contains("InternalAttribute");
                bool     isAdvanced = attributes.Contains("AdvancedAttribute");
                bool     isReadOnly = isInternal || attributes.Contains("ReadOnlyAttribute");
                bool     isHidden   = !this.showAll && this.hidden.Contains(property);
                if (isAdvanced && !showAdvanced)
                {
                    isHidden = true;
                }
                if (isInternal && !showInternal)
                {
                    isHidden = true;
                }
                object currentValue = property.GetObject <object>();
                bool   hasDefault   = MonoBehaviourEditor.defaults.ContainsKey(type) && MonoBehaviourEditor.defaults[type].ContainsKey(property.name);
                if (!this.showAll && hideDefault && hasDefault)
                {
                    object defaultValue = MonoBehaviourEditor.defaults[type][property.name];
                    if (defaultValue.IsNull())
                    {
                        continue;
                    }
                    bool isDefault = defaultValue.Equals(currentValue);
                    if (isDefault)
                    {
                        isHidden = true;
                    }
                }
                if (!isHidden)
                {
                    bool hasArea = this.propertyArea.ContainsKey(property);
                    if (hasArea)
                    {
                        if (Event.current.shift)
                        {
                            bool canHide = (this.properties.Count - this.hidden.Count) > 1;
                            if (this.propertyArea[property].Clicked(0) && canHide)
                            {
                                string path = "MonoBehaviourEditor-PropertyHide-" + this.target.GetInstanceID() + "-" + property.propertyPath;
                                EditorPref.Set <bool>(path, true);
                                this.hidden.Add(property);
                            }
                            if (this.propertyArea[property].Clicked(1))
                            {
                                this.DrawMenu();
                            }
                        }
                        if (fastInspector && this.propertyVisible.ContainsKey(property) && !this.propertyVisible[property])
                        {
                            GUILayout.Space(this.propertyArea[property].height);
                            continue;
                        }
                    }
                    string propertyName = null;
                    if (isReadOnly)
                    {
                        GUI.enabled = false;
                    }
                    GUI.changed = false;
                    EditorGUILayout.BeginVertical();
                    if (hasArea)
                    {
                        EditorGUI.BeginProperty(this.propertyArea[property], new GUIContent(property.displayName), property);
                    }
                    property.Draw(propertyName);
                    if (hasArea)
                    {
                        EditorGUI.EndProperty();
                    }
                    EditorGUILayout.EndVertical();
                    this.changed = this.changed || GUI.changed;
                    if (isReadOnly)
                    {
                        GUI.enabled = true;
                    }
                    if (Proxy.IsRepainting())
                    {
                        Rect area = GUILayoutUtility.GetLastRect();
                        if (!area.IsEmpty())
                        {
                            this.propertyArea[property] = area.AddHeight(2);
                        }
                    }
                }
            }
            if (showDictionary)
            {
                GUI.enabled = false;
                foreach (var item in this.dictionaries)
                {
                    item.Value.DrawAuto(item.Key, null, true);
                }
                GUI.enabled = true;
            }
            EditorGUILayout.EndVertical();
            this.EndArea();
            if (this.changed)
            {
                this.serializedObject.ApplyModifiedProperties();
                //this.serializedObject.targetObject.CallMethod("OnValidate");
                ProxyEditor.SetDirty(this.serializedObject.targetObject, false, true);
            }
            this.CheckChanges();
            if (Proxy.IsRepainting())
            {
                ProxyEditor.GetInspector(this).SetTitle("Inspector");
            }
        }