예제 #1
0
        protected override void DrawContent()
        {
            FloatSliderAttribute attr = GetAttr <FloatSliderAttribute>();

            if (drawer == null)
            {
                drawer = new FloatSliderDrawer();
                drawer.IsExpandWidth  = attr.IsExpandWidth;
                drawer.Text           = ItemDrawer.Label;
                drawer.OnValueChanged = (value) =>
                {
                    ItemDrawer.Value = value;
                };
                drawer.Value = (float)ItemDrawer.Value;
            }

            float leftValue  = attr.MinValue;
            float rightValue = attr.MaxValue;

            if (!string.IsNullOrEmpty(attr.MinValueMemberName))
            {
                leftValue = DrawerUtility.GetMemberValue <float>(attr.MinValueMemberName, ItemDrawer.Target);
            }
            if (!string.IsNullOrEmpty(attr.MaxValueMemberName))
            {
                rightValue = DrawerUtility.GetMemberValue <float>(attr.MaxValueMemberName, ItemDrawer.Target);
            }
            drawer.MinValue = leftValue;
            drawer.MaxValue = rightValue;
            drawer.OnGUILayout();
        }
예제 #2
0
        protected override void RefreshDrawers()
        {
            itemDrawers.Clear();
            if (Target != null && Target is IList list)
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    Type itemType        = list[i].GetType();
                    bool isTypeSupported = DrawerUtility.IsTypeSupported(itemType);

                    if (!isTypeSupported)
                    {
                        itemDrawers.Add(new UnsupportedTypeDrawer()
                        {
                            Label      = "" + i,
                            TargetType = itemType
                        });
                    }
                    else
                    {
                        ItemDrawer itemDrawer = new ItemDrawer(Target, i);
                        itemDrawer.ParentDrawer = this;

                        itemDrawers.Add(itemDrawer);
                    }
                }
            }
        }
        public override bool IsVisible()
        {
            VisibleIfAttribute attr = GetAttr <VisibleIfAttribute>();

            if (!string.IsNullOrEmpty(attr.MemberName))
            {
                return(DrawerUtility.GetMemberValue <bool>(attr.MemberName, ItemDrawer.Target));
            }
            return(false);
        }
예제 #4
0
        protected override void RefreshDrawers()
        {
            itemDrawers.Clear();
            if (Target == null)
            {
                return;
            }

            Type[] allTypes = DrawerUtility.GetAllBaseTypes(Target.GetType());
            if (allTypes != null && allTypes.Length > 0)
            {
                if (!IsShowInherit)
                {
                    itemDrawers.Add(new HeaderDrawer()
                    {
                        Header = allTypes[allTypes.Length - 1].Name,
                    });
                }
                foreach (var type in allTypes)
                {
                    if (IsShowInherit)
                    {
                        itemDrawers.Add(new HeaderDrawer()
                        {
                            Header = type.Name,
                        });
                    }

                    FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                    foreach (var field in fields)
                    {
                        if (DrawerUtility.IsTypeSupported(field.FieldType))
                        {
                            ItemDrawer fieldDrawer = new ItemDrawer(Target, field);
                            fieldDrawer.ParentDrawer = this;

                            itemDrawers.Add(fieldDrawer);
                        }
                        else
                        {
                            itemDrawers.Add(new UnsupportedTypeDrawer()
                            {
                                Label      = field.Name,
                                TargetType = field.FieldType,
                            });
                        }
                    }
                    if (IsShowInherit)
                    {
                        itemDrawers.Add(new HorizontalLineDrawer());
                    }
                }
            }
        }
예제 #5
0
        public override bool IsVisible()
        {
            CompareVisibleAttribute attr = GetAttr <CompareVisibleAttribute>();

            if (string.IsNullOrEmpty(attr.MemberName))
            {
                return(false);
            }
            else
            {
                SystemObject result = DrawerUtility.GetMemberValue(attr.MemberName, ItemDrawer.Target);
                return(DrawerUtility.Compare(result, attr.Value, attr.Symbol));
            }
        }
예제 #6
0
        private void InitAttrs()
        {
            if (Field != null)
            {
                VisibleAttribute visibleAttribute = Field.GetCustomAttribute <VisibleAttribute>();
                if (visibleAttribute != null)
                {
                    visibleAttrDrawer            = (VisibleAttrDrawer)DrawerUtility.GetAttrDrawerInstance(visibleAttribute);
                    visibleAttrDrawer.Attr       = visibleAttribute;
                    visibleAttrDrawer.ItemDrawer = this;
                }

                decoratorAttrDrawers.Clear();
                DecoratorAttribute[] decoratorAttributes = (DecoratorAttribute[])Field.GetCustomAttributes(typeof(DecoratorAttribute), false);
                if (decoratorAttributes != null && decoratorAttributes.Length > 0)
                {
                    foreach (var attr in decoratorAttributes)
                    {
                        DecoratorAttrDrawer drawer = (DecoratorAttrDrawer)DrawerUtility.GetAttrDrawerInstance(attr);
                        drawer.ItemDrawer = this;
                        decoratorAttrDrawers.Add(drawer);
                    }
                }

                layoutAttrDrawers.Clear();
                LayoutAttribute[] layoutAttributes = (LayoutAttribute[])Field.GetCustomAttributes(typeof(LayoutAttribute), false);
                if (layoutAttributes != null && layoutAttributes.Length > 0)
                {
                    foreach (var attr in layoutAttributes)
                    {
                        LayoutAttrDrawer drawer = (LayoutAttrDrawer)DrawerUtility.GetAttrDrawerInstance(attr);
                        drawer.Occasion = attr.Occasion;
                        layoutAttrDrawers.Add(drawer);
                    }
                }

                ContentAttribute contentAttribute = Field.GetCustomAttribute <ContentAttribute>();
                if (contentAttribute != null)
                {
                    ContentAttrDrawer contentAttrDrawer = (ContentAttrDrawer)DrawerUtility.GetAttrDrawerInstance(contentAttribute);
                    contentAttrDrawer.ItemDrawer = this;
                    innerDrawer = contentAttrDrawer;
                }
            }
        }
예제 #7
0
        private void RefreshDrawer()
        {
            if (innerDrawer != null)
            {
                return;
            }
            if (Target != null && Value != null)
            {
                TypeDrawer typeDrawer = DrawerUtility.GetTypeDrawerInstance(ValueType);
                if (typeDrawer != null)
                {
                    typeDrawer.Label      = Label;
                    typeDrawer.ItemDrawer = this;
                    innerDrawer           = typeDrawer;
                }
                else
                {
                    InstanceDrawer instanceDrawer = null;
                    if (TypeUtility.IsArrayOrListType(ValueType))
                    {
                        instanceDrawer = new ArrayDrawer(Value);
                    }
                    else if (TypeUtility.IsStructOrClassType(ValueType))
                    {
                        instanceDrawer = new ObjectDrawer(Value);
                    }

                    if (instanceDrawer != null)
                    {
                        instanceDrawer.Header     = Label;
                        instanceDrawer.ItemDrawer = this;

                        instanceDrawer.IsShowInherit = ParentDrawer.IsShowInherit;
                        instanceDrawer.IsShowBox     = ParentDrawer.IsShowBox;

                        innerDrawer = instanceDrawer;
                    }
                }
            }
        }
예제 #8
0
        private void AddNewItemAtLast()
        {
            if (Target != null && Target is IList list)
            {
                SystemObject item = DrawerUtility.GetTypeInstance(ItemType);
                if (item != null)
                {
                    if (list.GetType().IsArrayType())
                    {
                        Array array = (Array)list;
                        DotEngine.Core.Utilities.ArrayUtility.Add(ref array, item);

                        Target = array;
                    }
                    else
                    {
                        list.Add(item);
                    }
                }

                Refresh();
            }
        }
예제 #9
0
        public override void OnGUILayout()
        {
            if (!GetVisible())
            {
                return;
            }

            if (isNeedRefresh)
            {
                RefreshDrawer();
                isNeedRefresh = false;
            }

            foreach (var drawer in layoutAttrDrawers)
            {
                if (drawer.Occasion == LayoutOccasion.Before)
                {
                    drawer.OnGUILayout();
                }
            }

            foreach (var drawer in decoratorAttrDrawers)
            {
                drawer.OnGUILayout();
            }

            object value = Value;

            if (value == null)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(Label, GUILayout.Width(EditorGUIUtility.labelWidth));
                    if (GUILayout.Button("Create"))
                    {
                        Value = DrawerUtility.GetTypeInstance(ValueType);

                        RefreshDrawer();
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            else if (innerDrawer != null)
            {
                innerDrawer.OnGUILayout();
            }
            else
            {
                EGUI.BeginGUIColor(Color.red);
                {
                    EditorGUILayout.LabelField(Label, $"The drawer of {ValueType} is not found");
                }
                EGUI.EndGUIColor();
            }

            foreach (var drawer in layoutAttrDrawers)
            {
                if (drawer.Occasion == LayoutOccasion.After)
                {
                    drawer.OnGUILayout();
                }
            }
        }