Exemple #1
0
        public ClassTypeDrawer(Type type)
        {
            Type = type;
            var validFunc = type.GetCustomAttribute <ValidFuncAttribute>();

            if (validFunc != null)
            {
                ValidMethod = type.GetMethod(validFunc.Name);
            }
            BaseTypeDrawer = DrawerCollector.CreateDrawer(type.BaseType);
            var fields = type.GetFields();

            foreach (var field in fields)
            {
                if (field.DeclaringType != type)
                {
                    continue;
                }
                var fieldDrawer = FieldDrawer.Create(field);
                if (fieldDrawer != null)
                {
                    Fields.Add(fieldDrawer);
                }
            }
        }
Exemple #2
0
        private bool Draw(object val, StateGraph context)
        {
            if (val == null)
            {
                return(true);
            }
            IList list = val as IList;

            while (Drawers.Count < list.Count)
            {
                Drawers.Add(DrawerCollector.CreatContainerDrawer(Field, ElementType));
            }
            for (int i = 0; i < list.Count; ++i)
            {
                string style = selectIndex == i ? "MeTransitionSelect" : "RL Element";
                using (new GUILayout.HorizontalScope(style))
                {
                    var drawer = Drawers[i];
                    if (GUILayout.Button("", "RL DragHandle", GUILayout.ExpandHeight(true)))
                    {
                        selectIndex = i;
                    }
                    using (new GUILayout.VerticalScope())
                    {
                        if (drawer.Draw(null, list[i], context))
                        {
                            DrawerCollector.OnPropertyModify(context);
                            list[i] = drawer.GetValue();
                        }
                    }
                }
                GUILayout.Space(4);
            }
            return(false);
        }
Exemple #3
0
        public static FieldDrawer Create(FieldInfo info)
        {
            IDrawer drawer = DrawerCollector.CreateDrawer(info);

            if (drawer == null)
            {
                return(null);
            }
            return(new FieldDrawer(info, drawer));
        }
Exemple #4
0
 public bool Draw(object data, StateGraph context)
 {
     if (Drawer == null || ValidMethod != null && !(bool)ValidMethod.Invoke(data, null))
     {
         return(false);
     }
     if (Drawer.Draw(Content, Info.GetValue(data), context))
     {
         DrawerCollector.OnPropertyModify(context);
         Info.SetValue(data, Drawer.GetValue());
         return(true);
     }
     return(false);
 }
 public StructTypeDrawer(Type type)
 {
     BaseTypeDrawer = DrawerCollector.CreateDrawer(type.BaseType);
     foreach (var field in type.GetFields())
     {
         if (field.DeclaringType != type)
         {
             continue;
         }
         var fieldDrawer = FieldDrawer.Create(field);
         if (fieldDrawer != null)
         {
             Fields.Add(fieldDrawer);
         }
     }
 }
Exemple #6
0
 private bool Draw(object val, StateGraph context, bool offset)
 {
     if (val == null)
     {
         DrawerCollector.OnPropertyModify(context);
         return(true);
     }
     if (BaseTypeDrawer != null)
     {
         BaseTypeDrawer.Draw(null, val, context);
     }
     if (ValidMethod == null || (bool)ValidMethod.Invoke(val, null))
     {
         using (new GUILayout.VerticalScope(offset ? ContentStyle : Empty))
         {
             foreach (var field in Fields)
             {
                 field.Draw(val, context);
             }
         }
     }
     return(false);
 }
Exemple #7
0
        public bool Draw(GUIContent content, object val, StateGraph context)
        {
            using (new GUILayout.HorizontalScope("RL Header"))
            {
                foldout = EditorGUILayout.Foldout(foldout, content ?? empty, true);
                if (!foldout)
                {
                    return(false);
                }
            }
            bool modify = false;

            using (new GUILayout.VerticalScope("RL Background"))
            {
                modify = Draw(val, context);
            }
            int btnWidth = 25;

            using (new GUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                IList list = val as IList;
                using (new GUILayout.HorizontalScope("RL Footer"))
                {
                    using (new EditorGUI.DisabledScope(selectIndex <= 0))
                    {
                        if (GUILayout.Button("▲", "RL FooterButton", GUILayout.Width(btnWidth)))
                        {
                            int idx = selectIndex;
                            DrawerCollector.OnPropertyModify(context);
                            GUI.FocusControl(null);
                            var old = list[idx];
                            list[idx]     = list[idx - 1];
                            list[idx - 1] = old;
                            var oldDrawer = Drawers[idx];
                            Drawers[idx]     = Drawers[idx - 1];
                            Drawers[idx - 1] = oldDrawer;
                            selectIndex--;
                        }
                    }
                    using (new EditorGUI.DisabledScope(selectIndex >= list.Count - 1))
                    {
                        if (GUILayout.Button("▼", "RL FooterButton", GUILayout.Width(btnWidth)))
                        {
                            int idx = selectIndex;
                            DrawerCollector.OnPropertyModify(context);
                            GUI.FocusControl(null);
                            var old = list[idx];
                            list[idx]     = list[idx + 1];
                            list[idx + 1] = old;
                            var oldDrawer = Drawers[idx];
                            Drawers[idx]     = Drawers[idx + 1];
                            Drawers[idx + 1] = oldDrawer;
                            selectIndex++;
                        }
                    }
                    if (GUILayout.Button(iconToolbarPlusMore, "RL FooterButton", GUILayout.Width(btnWidth)))
                    {
                        DrawerCollector.OnPropertyModify(context);
                        list.Add(CreatNew());
                        selectIndex = list.Count - 1;
                    }
                    using (new EditorGUI.DisabledScope(selectIndex < 0))
                    {
                        if (GUILayout.Button(iconToolbarMinus, "RL FooterButton", GUILayout.Width(btnWidth)))
                        {
                            DrawerCollector.OnPropertyModify(context);
                            list.RemoveAt(selectIndex);
                            Drawers.RemoveAt(selectIndex);
                            if (selectIndex >= list.Count)
                            {
                                selectIndex--;
                            }
                        }
                    }
                }
                GUILayout.Space(10);
            }
            return(modify);
        }