Inheritance: UnityEditor.PropertyDrawer
Beispiel #1
0
    public static object ObjectField(string title, object value, Type type, FieldInfo info, object owner = null, params GUILayoutOption[] options)
    {
        FieldDrawer drawer = FieldDrawerUtil.Get(type);

        if (drawer != null)
        {
            FieldDrawer instance = drawer.Clone();
            instance.owner = owner;
            instance.OnEnbale(title, value, type, info);
            return(instance.OnGUI(options));
        }
        else
        {
            EditorGUILayout.LabelField(title, "Cant get Drawer", options);
        }
        return(value);
    }
 public StateGraphPropertyEditor(StateGraph graph)
 {
     Graph = graph;
     var type = graph.GetType();
     var fields = type.GetFields();
     foreach (var field in fields)
     {
         var fieldDrawer = FieldDrawer.Create(field);
         if (fieldDrawer != null)
         {
             if (field.DeclaringType != type)
             {
                 Fields.Insert(0, fieldDrawer);
             }
             else
             {
                 Fields.Add(fieldDrawer);
             }
         }
     }
 }
            protected DrawCommand[] GenerateDrawCommands(FieldInfo[] fields)
            {
                List <DrawCommand> drawers = new List <DrawCommand>();

                for (int i = 0; i < fields.Length; ++i)
                {
                    FieldInfo field     = fields[i];
                    Type      fieldType = field.FieldType;
                    StratusSerializedFieldType serializedPropertyType = SerializedFieldTypeExtensions.Deduce(field);

                    // Unity is supported by Unity if it's not a generic array
                    bool   isArray = IsArray(fieldType);
                    bool   isUnitySupportedType = (serializedPropertyType != StratusSerializedFieldType.Generic || isArray);                   //  OdinSerializer.FormatterUtilities.IsPrimitiveType(fieldType);
                    Drawer drawer = null;


                    if (isUnitySupportedType)
                    {
                        drawer = new FieldDrawer(field);
                    }
                    else
                    {
                        drawer = new DefaultObjectDrawer(field, fieldType);                         //  GetDrawer(field);
                        //drawer.displayName = field.Name;
                    }

                    //drawer.displayName = field.Name;
                    DrawCommand drawCommand = new DrawCommand(drawer, field, isUnitySupportedType);
                    if (drawer.isDrawable)
                    {
                        this.height += drawer.height;
                    }

                    drawers.Add(drawCommand);
                }

                return(drawers.ToArray());
            }