Beispiel #1
0
        public static IAttrSet Height(this IAttrSet attrSet, decimal value)
        {
            HeightAttribute a = new HeightAttribute(value);

            return(attrSet.Add(a));
        }
        private void DrawNormalValue(System.Reflection.FieldInfo filed, Rect rect, object o)
        {
            switch (filed.FieldType.ToString())
            {
            case "UnityEngine.Vector3":
                filed.SetValue(o, EditorGUI.Vector3Field(rect, "", (Vector3)filed.GetValue(o)));
                //检查是否需要帮助(拖动一个Object,同步其位置或旋转)
                Vector3Helper helper = Attribute.GetCustomAttribute(filed, typeof(Vector3Helper)) as Vector3Helper;
                if (helper != null)
                {
                    rect = GetGUILeftScrollAreaRect(60, rect.width, rect.height, true);
                    Transform t = null;
                    t = EditorGUI.ObjectField(rect, t, typeof(Transform), true) as Transform;
                    if (t)
                    {
                        switch (helper.Mode)
                        {
                        case VectorSyceMode.Position:
                            filed.SetValue(o, t.position);
                            break;

                        case VectorSyceMode.EulerAngle:
                            filed.SetValue(o, t.eulerAngles);
                            break;
                        }
                    }
                }
                break;

            case "UnityEngine.Vector2":
                filed.SetValue(o, EditorGUI.Vector2Field(rect, "", (Vector2)filed.GetValue(o)));
                break;

            case "System.Single":
                filed.SetValue(o, EditorGUI.FloatField(rect, (float)filed.GetValue(o)));
                break;

            case "System.Int32":
                filed.SetValue(o, EditorGUI.IntField(rect, (int)filed.GetValue(o)));
                break;

            case "System.String":
                HeightAttribute height = Attribute.GetCustomAttribute(filed, typeof(HeightAttribute)) as HeightAttribute;
                if (height != null)
                {
                    rect = GetGUILeftScrollAreaRect(60, rect.width, height.Height, true);
                }

                filed.SetValue(o, EditorGUI.TextField(rect, (string)filed.GetValue(o)));
                break;

            case "System.Boolean":
                filed.SetValue(o, EditorGUI.Toggle(rect, (bool)filed.GetValue(o)));
                break;

            case "System.String[]":
                //高级编辑功能
                rect = GetGUILeftScrollAreaRect(80, 90, 20, false);
                if (GUI.Button(rect, "<color=#00FF00>Advance Edit</color>", ResourcesManager.GetInstance.skin.button))
                {
                    AdvanceStringArrayEditor.Open(o, filed);
                }

                //通常编辑功能
                string[] array = filed.GetValue(o) as string[];
                rect = GetGUILeftScrollAreaRect(175, 20, 18);
                LeftHeightSpace(6);
                if (GUI.Button(rect, "+", ResourcesManager.GetInstance.skin.button))
                {
                    Array.Resize <string>(ref array, array.Length + 1);
                }
                if (array == null)
                {
                    array = new string[] { }
                }
                ;
                for (int j = 0; j < array.Length; j++)
                {
                    rect     = GetGUILeftScrollAreaRect(10, 160, 18, false);
                    array[j] = EditorGUI.TextField(rect, (string)array[j]);
                    rect     = GetGUILeftScrollAreaRect(175, 20, 18);
                    if (GUI.Button(rect, "-", ResourcesManager.GetInstance.skin.button))
                    {
                        for (int n = j; n < array.Length - 1; n++)
                        {
                            array[j] = array[j + 1];
                        }
                        Array.Resize <string>(ref array, array.Length - 1);
                        break;
                    }
                    LeftHeightSpace(2);
                }
                filed.SetValue(o, array);
                break;

            default:
                if (filed.FieldType.BaseType.ToString() == "System.Enum")
                {
                    //System.Enum.Parse(filed.FieldType.DeclaringType, (string)filed.GetValue(_currentNode));
                    filed.SetValue(o, EditorGUI.EnumPopup(rect, (System.Enum)filed.GetValue(o)));
                }
                else
                {
                    EditorGUI.LabelField(rect, "Not Deal Object.");
                }
                break;
            }
        }