Beispiel #1
0
        public override void Draw(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (fieldInspector.Field.FieldType == typeof(string))
            {
                string value = (string)fieldInspector.Field.GetValue(inspector.target);
                int    layer = LayerMask.NameToLayer(value);
                if (layer < 0)
                {
                    layer = 0;
                }
                if (layer > 31)
                {
                    layer = 31;
                }

                GUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                int newLayer = EditorGUILayout.LayerField(fieldInspector.Label, layer);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(inspector.target, "Layer");
                    fieldInspector.Field.SetValue(inspector.target, LayerMask.LayerToName(newLayer));
                    inspector.HasChanged();
                }
                GUILayout.EndHorizontal();
            }
            else if (fieldInspector.Field.FieldType == typeof(int))
            {
                int layer = (int)fieldInspector.Field.GetValue(inspector.target);
                if (layer < 0)
                {
                    layer = 0;
                }
                if (layer > 31)
                {
                    layer = 31;
                }

                GUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                int newLayer = EditorGUILayout.LayerField(fieldInspector.Label, layer);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(inspector.target, "Layer");
                    fieldInspector.Field.SetValue(inspector.target, newLayer);
                    inspector.HasChanged();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox("[" + fieldInspector.Field.Name + "] can't used Layer! because the types don't match!", MessageType.Error);
                GUILayout.EndHorizontal();
            }
        }
Beispiel #2
0
        public override void SceneHandle(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (fieldInspector.Field.FieldType == typeof(Bounds))
            {
                Bounds value = (Bounds)fieldInspector.Field.GetValue(inspector.target);
                BoundsHandle.center = value.center;
                BoundsHandle.size   = value.size;

                using (new Handles.DrawingScope(fieldInspector.UseColor))
                {
                    EditorGUI.BeginChangeCheck();
                    BoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(inspector.target, "Bounds Handler");
                        value.center = BoundsHandle.center;
                        value.size   = BoundsHandle.size;
                        fieldInspector.Field.SetValue(inspector.target, value);
                        inspector.HasChanged();
                    }
                    if (BAttribute.Display != null)
                    {
                        Handles.Label(BoundsHandle.center, BAttribute.Display);
                    }
                }
            }
        }
Beispiel #3
0
        public override void Draw(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (fieldInspector.Field.FieldType == typeof(string))
            {
                string value = (string)fieldInspector.Field.GetValue(inspector.target);
                if (value == null)
                {
                    value = "";
                }

                GUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                string newValue = EditorGUILayout.PasswordField(fieldInspector.Label, value);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(inspector.target, "Password");
                    fieldInspector.Field.SetValue(inspector.target, newValue);
                    inspector.HasChanged();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox("[" + fieldInspector.Field.Name + "] can't used Password! because the types don't match!", MessageType.Error);
                GUILayout.EndHorizontal();
            }
        }
Beispiel #4
0
        public override void Draw(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (DAttribute.ValueType == fieldInspector.Field.FieldType)
            {
                object value       = fieldInspector.Field.GetValue(inspector.target);
                int    selectIndex = Array.IndexOf(DAttribute.Values, value);
                if (selectIndex < 0)
                {
                    selectIndex = 0;
                }

                GUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                int newIndex = EditorGUILayout.Popup(fieldInspector.Label, selectIndex, DAttribute.DisplayOptions);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(inspector.target, "Dropdown");
                    fieldInspector.Field.SetValue(inspector.target, DAttribute.Values[newIndex]);
                    inspector.HasChanged();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox("[" + fieldInspector.Field.Name + "] used a mismatched Dropdown!", MessageType.Error);
                GUILayout.EndHorizontal();
            }
        }
Beispiel #5
0
        public override void SceneHandle(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (fieldInspector.Field.FieldType == typeof(float))
            {
                Component component = inspector.target as Component;
                Vector3   center    = component != null ? component.transform.position : Vector3.zero;
                float     value     = (float)fieldInspector.Field.GetValue(inspector.target);

                using (new Handles.DrawingScope(fieldInspector.UseColor))
                {
                    EditorGUI.BeginChangeCheck();
                    float newValue = Handles.RadiusHandle(Quaternion.identity, center, value);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(inspector.target, "Radius Handler");
                        fieldInspector.Field.SetValue(inspector.target, newValue);
                        inspector.HasChanged();
                    }
                    if (RAttribute.Display != null)
                    {
                        Handles.Label(center, RAttribute.Display);
                    }
                }
            }
            else if (fieldInspector.Field.FieldType == typeof(int))
            {
                Component component = inspector.target as Component;
                Vector3   center    = component != null ? component.transform.position : Vector3.zero;
                int       value     = (int)fieldInspector.Field.GetValue(inspector.target);

                using (new Handles.DrawingScope(fieldInspector.UseColor))
                {
                    EditorGUI.BeginChangeCheck();
                    int newValue = (int)Handles.RadiusHandle(Quaternion.identity, center, value);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(inspector.target, "Radius Handler");
                        fieldInspector.Field.SetValue(inspector.target, newValue);
                        inspector.HasChanged();
                    }
                    if (RAttribute.Display != null)
                    {
                        Handles.Label(center, RAttribute.Display);
                    }
                }
            }
        }
Beispiel #6
0
        public override void SceneHandle(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (fieldInspector.Field.FieldType == typeof(Vector3))
            {
                Vector3 value = (Vector3)fieldInspector.Field.GetValue(inspector.target);

                using (new Handles.DrawingScope(fieldInspector.UseColor))
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 newValue = Handles.PositionHandle(value, Quaternion.identity);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(inspector.target, "Move Handler");
                        fieldInspector.Field.SetValue(inspector.target, newValue);
                        inspector.HasChanged();
                    }
                    if (MAttribute.Display != null)
                    {
                        Handles.Label(newValue, MAttribute.Display);
                    }
                }
            }
            else if (fieldInspector.Field.FieldType == typeof(Vector2))
            {
                Vector2 value = (Vector2)fieldInspector.Field.GetValue(inspector.target);

                using (new Handles.DrawingScope(fieldInspector.UseColor))
                {
                    EditorGUI.BeginChangeCheck();
                    Vector2 newValue = Handles.PositionHandle(value, Quaternion.identity);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(inspector.target, "Move Handler");
                        fieldInspector.Field.SetValue(inspector.target, newValue);
                        inspector.HasChanged();
                    }
                    if (MAttribute.Display != null)
                    {
                        Handles.Label(newValue, MAttribute.Display);
                    }
                }
            }
        }
Beispiel #7
0
        public override void Draw(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (fieldInspector.Field.FieldType == typeof(string))
            {
                string value = (string)fieldInspector.Field.GetValue(inspector.target);
                if (value == null)
                {
                    value = "";
                }

                GUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                string newValue = EditorGUILayout.TextField(fieldInspector.Label, value);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(inspector.target, "FolderPath");
                    fieldInspector.Field.SetValue(inspector.target, newValue);
                    inspector.HasChanged();
                }
                if (GUILayout.Button(OpenGC, "IconButton", GUILayout.Width(20), GUILayout.Height(EditorGUIUtility.singleLineHeight)))
                {
                    string path = EditorUtility.OpenFolderPanel("Select Folder", Application.dataPath, "");
                    if (path.Length != 0)
                    {
                        Undo.RecordObject(inspector.target, "FolderPath");
                        fieldInspector.Field.SetValue(inspector.target, "Assets" + path.Replace(Application.dataPath, ""));
                        inspector.HasChanged();
                    }
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox("[" + fieldInspector.Field.Name + "] can't used FolderPath! because the types don't match!", MessageType.Error);
                GUILayout.EndHorizontal();
            }
        }
Beispiel #8
0
            public void Draw(MonoComponentInspector inspector)
            {
                GUI.enabled = Attribute.Mode == ButtonAttribute.EnableMode.Always ||
                              (Attribute.Mode == ButtonAttribute.EnableMode.Editor && !EditorApplication.isPlaying) ||
                              (Attribute.Mode == ButtonAttribute.EnableMode.Playmode && EditorApplication.isPlaying);

                GUILayout.BeginHorizontal();
                if (GUILayout.Button(Name, Attribute.Style))
                {
                    inspector.HasChanged();

                    if (Method.ReturnType.Name != "Void")
                    {
                        object result = null;
                        if (Method.IsStatic)
                        {
                            result = Method.Invoke(null, null);
                        }
                        else
                        {
                            result = Method.Invoke(inspector.target, null);
                        }
                        //Log.Info("点击按钮 " + Name + " 后,存在返回值:" + result);
                    }
                    else
                    {
                        if (Method.IsStatic)
                        {
                            Method.Invoke(null, null);
                        }
                        else
                        {
                            Method.Invoke(inspector.target, null);
                        }
                    }
                }
                GUILayout.EndHorizontal();

                GUI.enabled = true;
            }