コード例 #1
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        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();
            }
        }
コード例 #2
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        public override void SceneHandle(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (fieldInspector.Field.FieldType == typeof(Vector3))
            {
                Vector3 value = (Vector3)fieldInspector.Field.GetValue(inspector.target);

                if (value != Vector3.zero)
                {
                    using (new Handles.DrawingScope(fieldInspector.UseColor))
                    {
                        ExternalSize = GetExternalSize(inspector.target);
                        InternalSize = GetInternalSize(inspector.target);
                        Handles.CircleHandleCap(0, Position, Quaternion.FromToRotation(Vector3.forward, value), ExternalSize, EventType.Repaint);
                        Handles.CircleHandleCap(0, Position, Quaternion.FromToRotation(Vector3.forward, value), InternalSize, EventType.Repaint);
                        Handles.Slider(Position, value);
                    }
                }
            }
            else if (fieldInspector.Field.FieldType == typeof(Vector2))
            {
                Vector2 value = (Vector2)fieldInspector.Field.GetValue(inspector.target);

                if (value != Vector2.zero)
                {
                    using (new Handles.DrawingScope(fieldInspector.UseColor))
                    {
                        ExternalSize = GetExternalSize(inspector.target);
                        InternalSize = GetInternalSize(inspector.target);
                        Handles.CircleHandleCap(0, Position, Quaternion.FromToRotation(Vector3.forward, value), ExternalSize, EventType.Repaint);
                        Handles.CircleHandleCap(0, Position, Quaternion.FromToRotation(Vector3.forward, value), InternalSize, EventType.Repaint);
                        Handles.Slider(Position, value);
                    }
                }
            }
        }
コード例 #3
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        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();
            }
        }
コード例 #4
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        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);
                    }
                }
            }
        }
コード例 #5
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
 public void Draw(MonoComponentInspector inspector)
 {
     if (IsDisplay)
     {
         GUI.color = UseColor;
         if (Drawers.Count > 0)
         {
             GUI.enabled = IsEnable;
             for (int i = 0; i < Drawers.Count; i++)
             {
                 Drawers[i].Draw(inspector, this);
             }
             GUI.enabled = true;
         }
         else
         {
             if (Property.name == "m_Script")
             {
                 GUI.enabled = false;
                 EditorGUILayout.PropertyField(Property);
                 GUI.enabled = true;
             }
             else
             {
                 GUI.enabled = IsEnable;
                 EditorGUILayout.PropertyField(Property, new GUIContent(Label), true);
                 GUI.enabled = true;
             }
         }
         GUI.color = Color.white;
     }
 }
コード例 #6
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        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();
            }
        }
コード例 #7
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
 public void SceneHandle(MonoComponentInspector inspector)
 {
     if (IsDisplay)
     {
         if (SceneHandlers.Count > 0)
         {
             for (int i = 0; i < SceneHandlers.Count; i++)
             {
                 SceneHandlers[i].SceneHandle(inspector, this);
             }
         }
     }
 }
コード例 #8
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        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);
                    }
                }
            }
        }
コード例 #9
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        public override void SceneHandle(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (fieldInspector.Field.FieldType == typeof(float))
            {
                float value = (float)fieldInspector.Field.GetValue(inspector.target);

                using (new Handles.DrawingScope(fieldInspector.UseColor))
                {
                    Position = GetPosition(inspector.target);
                    Size     = GetSize(inspector.target, value);
                    Handles.CircleHandleCap(0, Position, Rotation, Size, EventType.Repaint);
                    if (Target)
                    {
                        Handles.Slider(Position, Target.forward);
                    }
                }
            }
        }
コード例 #10
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        public override void Draw(MonoComponentInspector inspector, FieldInspector fieldInspector)
        {
            if (fieldInspector.Property.isArray)
            {
                if (List == null)
                {
                    GenerateList(fieldInspector);
                }

                List.DoLayoutList();
            }
            else
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox("[" + fieldInspector.Field.Name + "] can't use the ReorderableList!", MessageType.Error);
                GUILayout.EndHorizontal();
            }
        }
コード例 #11
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        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);
                    }
                }
            }
        }
コード例 #12
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
 public override void Draw(MonoComponentInspector inspector, FieldInspector fieldInspector)
 {
     if (fieldInspector.Field.FieldType == typeof(string))
     {
         GUILayout.BeginHorizontal();
         bool isClick = (bool)LinkLabel.Invoke(null, Parameter);
         if (isClick)
         {
             Application.OpenURL((string)fieldInspector.Field.GetValue(inspector.target));
         }
         GUILayout.EndHorizontal();
     }
     else
     {
         GUILayout.BeginHorizontal();
         EditorGUILayout.HelpBox("[" + fieldInspector.Field.Name + "] can't used Hyperlink! because the types don't match!", MessageType.Error);
         GUILayout.EndHorizontal();
     }
 }
コード例 #13
0
            public void Draw(MonoComponentInspector inspector)
            {
                Delegate[] delegates = Field.GetValue(inspector.target) is MulticastDelegate multicast?multicast.GetInvocationList() : null;

                GUILayout.BeginHorizontal();
                GUILayout.Space(10);
                IsFoldout = EditorGUILayout.Foldout(IsFoldout, string.Format("{0} [{1}]", Name, delegates != null ? delegates.Length : 0));
                GUILayout.EndHorizontal();

                if (IsFoldout && delegates != null)
                {
                    for (int i = 0; i < delegates.Length; i++)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(30);
                        GUILayout.Label(string.Format("{0}->{1}", delegates[i].Target, delegates[i].Method), "Textfield");
                        GUILayout.EndHorizontal();
                    }
                }
            }
コード例 #14
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;
            }
コード例 #15
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        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();
            }
        }
コード例 #16
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
 public abstract void SceneHandle(MonoComponentInspector inspector, FieldInspector fieldInspector);
コード例 #17
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
 public abstract void Draw(MonoComponentInspector inspector, FieldInspector fieldInspector);
コード例 #18
0
ファイル: CustomDrawers.cs プロジェクト: xdedzl/XFramework
        public FieldInspector(SerializedProperty property)
        {
            BindingFlags flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            Field    = property.serializedObject.targetObject.GetType().GetField(property.name, flags);
            Property = property;
            Label    = property.displayName;

            if (Field != null)
            {
                InspectorAttribute[] iattributes = (InspectorAttribute[])Field.GetCustomAttributes(typeof(InspectorAttribute), true);
                for (int i = 0; i < iattributes.Length; i++)
                {
                    if (iattributes[i] is EnableAttribute)
                    {
                        EnableCondition = property.serializedObject.targetObject.GetType().GetMethod(iattributes[i].Cast <EnableAttribute>().Condition, flags);
                        if (EnableCondition != null && EnableCondition.ReturnType != typeof(bool))
                        {
                            EnableCondition = null;
                        }
                    }
                    else if (iattributes[i] is DisplayAttribute)
                    {
                        DisplayCondition = property.serializedObject.targetObject.GetType().GetMethod(iattributes[i].Cast <DisplayAttribute>().Condition, flags);
                        if (DisplayCondition != null && DisplayCondition.ReturnType != typeof(bool))
                        {
                            DisplayCondition = null;
                        }
                    }
                    else if (iattributes[i] is LabelAttribute)
                    {
                        Label = iattributes[i].Cast <LabelAttribute>().Name;
                    }
                    else if (iattributes[i] is ColorAttribute)
                    {
                        ColorAttribute attribute = iattributes[i] as ColorAttribute;
                        UseColor = new Color(attribute.R, attribute.G, attribute.B, attribute.A);
                    }
                    else if (iattributes[i] is ReadOnlyAttribute)
                    {
                        IsReadOnly = true;
                    }
                    else
                    {
                        var attr       = iattributes[i];
                        var drawerType = MonoComponentInspector.GetDrawerType(attr.GetType());
                        Drawers.Add(Utility.Reflection.CreateInstance <FieldDrawer>(drawerType, attr));
                    }
                }

                SceneHandlerAttribute[] sattributes = (SceneHandlerAttribute[])Field.GetCustomAttributes(typeof(SceneHandlerAttribute), true);
                for (int i = 0; i < sattributes.Length; i++)
                {
                    if (sattributes[i] is MoveHandlerAttribute)
                    {
                        SceneHandlers.Add(new MoveHandler(sattributes[i]));
                    }
                    else if (sattributes[i] is RadiusHandlerAttribute)
                    {
                        SceneHandlers.Add(new RadiusHandler(sattributes[i]));
                    }
                    else if (sattributes[i] is BoundsHandlerAttribute)
                    {
                        SceneHandlers.Add(new BoundsHandler(sattributes[i]));
                    }
                    else if (sattributes[i] is DirectionHandlerAttribute)
                    {
                        SceneHandlers.Add(new DirectionHandler(sattributes[i]));
                    }
                    else if (sattributes[i] is CircleAreaHandlerAttribute)
                    {
                        SceneHandlers.Add(new CircleAreaHandler(sattributes[i]));
                    }
                }
            }
        }