Ejemplo n.º 1
0
 protected virtual void OnEnable()
 {
     drawerObject = new DrawerObject(target)
     {
         IsShowScroll  = IsShowScroll(),
         IsShowInherit = IsShowInherit(),
     };
 }
Ejemplo n.º 2
0
        void OnEnable()
        {
            Type targetType = target.GetType();
            var  attrs      = targetType.GetCustomAttributes(typeof(CustomDrawerEditorAttribute), true);

            if (attrs != null && attrs.Length > 0)
            {
                attr = (CustomDrawerEditorAttribute)attrs[0];
            }
            if (attr != null)
            {
                drawerObject = new DrawerObject(target)
                {
                    IsShowScroll  = attr.IsShowScroll,
                    IsShowInherit = attr.IsShowInherit,
                };
            }
        }
Ejemplo n.º 3
0
        internal void OnGUILayout()
        {
            foreach (var drawer in layoutDrawers)
            {
                LayoutAttribute attr = drawer.GetAttr <LayoutAttribute>();
                if (attr.Occasion == LayoutOccasion.Before)
                {
                    drawer.OnGUILayout();
                }
            }

            bool isVisible = IsVisible();

            if (isVisible)
            {
                foreach (var drawer in controlDrawers)
                {
                    drawer.OnStartGUILayout();
                }

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

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

                string label = FieldName;
                if (labelDrawer != null)
                {
                    label = labelDrawer.GetLabel();
                }
                if (!string.IsNullOrEmpty(label))
                {
                    label = UnityEditor.ObjectNames.NicifyVariableName(label);
                }
                if (contentDrawer != null)
                {
                    contentDrawer.OnGUILayout(label);
                }
                else if (drawerObject != null)
                {
                    if (!IsArrayElement)
                    {
                        UnityEditor.EditorGUILayout.LabelField(label);
                        UnityEditor.EditorGUI.indentLevel++;
                        {
                            drawerObject.OnGUILayout();
                        }
                        UnityEditor.EditorGUI.indentLevel--;
                    }
                    else
                    {
                        UnityEditor.EditorGUILayout.BeginHorizontal();
                        {
                            UnityEditor.EditorGUILayout.LabelField(label, UnityEngine.GUILayout.Width(25));
                            UnityEditor.EditorGUILayout.BeginVertical();
                            {
                                drawerObject.OnGUILayout();
                            }
                            UnityEditor.EditorGUILayout.EndVertical();
                        }
                        UnityEditor.EditorGUILayout.EndHorizontal();
                    }
                }
                else if (drawerObject == null)
                {
                    if (!DrawerUtility.IsTypeSupported(ValueType))
                    {
                        EGUI.BeginGUIColor(UnityEngine.Color.red);
                        {
                            UnityEditor.EditorGUILayout.LabelField(string.IsNullOrEmpty(label) ? "" : label, $"The type isn't supported.type = {ValueType}");
                        }
                        EGUI.EndGUIColor();
                    }
                    else if (Value == null)
                    {
                        UnityEditor.EditorGUILayout.BeginHorizontal();
                        {
                            UnityEditor.EditorGUILayout.PrefixLabel(label);
                            if (UnityEngine.GUILayout.Button("Create"))
                            {
                                Value = DrawerUtility.CreateInstance(ValueType);

                                if (DrawerUtility.IsTypeSupported(ValueType))
                                {
                                    if (ValueType.IsStructOrClassType() && Value != null)
                                    {
                                        drawerObject = new DrawerObject(Value);
                                    }
                                }
                            }
                        }
                        UnityEditor.EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        EGUI.BeginGUIColor(UnityEngine.Color.red);
                        {
                            UnityEditor.EditorGUILayout.LabelField(string.IsNullOrEmpty(label) ? "" : label, "Unknown Drawer");
                        }
                        EGUI.EndGUIColor();
                    }
                }

                foreach (var drawer in controlDrawers)
                {
                    drawer.OnEndGUILayout();
                }
            }

            foreach (var drawer in layoutDrawers)
            {
                LayoutAttribute attr = drawer.GetAttr <LayoutAttribute>();
                if (attr.Occasion == LayoutOccasion.After)
                {
                    drawer.OnGUILayout();
                }
            }
        }
Ejemplo n.º 4
0
        internal void Init()
        {
            if (!IsArrayElement)
            {
                var drawerAttrs = Field.GetCustomAttributes <DrawerAttribute>();
                foreach (var attr in drawerAttrs)
                {
                    var drawer = DrawerUtility.CreateAttrDrawer(this, attr);
                    if (drawer == null)
                    {
                        Debug.LogWarning("DrawerProperty::Init->drawer not found.attr = " + attr.GetType().Name);
                    }
                    else
                    {
                        if (drawer.GetType().IsSubclassOf(typeof(DecoratorDrawer)))
                        {
                            decoratorDrawers.Add(drawer as DecoratorDrawer);
                        }
                        else if (drawer.GetType().IsSubclassOf(typeof(LayoutDrawer)))
                        {
                            layoutDrawers.Add(drawer as LayoutDrawer);
                        }
                        else if (drawer.GetType().IsSubclassOf(typeof(ListenerDrawer)))
                        {
                            listenerDrawers.Add(drawer as ListenerDrawer);
                        }
                        else if (drawer.GetType().IsSubclassOf(typeof(PropertyControlDrawer)))
                        {
                            controlDrawers.Add(drawer as PropertyControlDrawer);
                        }
                        else if (drawer.GetType().IsSubclassOf(typeof(VisibleDrawer)))
                        {
                            visibleDrawers.Add(drawer as VisibleDrawer);
                        }
                        else if (drawer.GetType().IsSubclassOf(typeof(VerificationDrawer)))
                        {
                            verificationDrawers.Add(drawer as VerificationDrawer);
                        }
                        else if (drawer.GetType().IsSubclassOf(typeof(PropertyLabelDrawer)))
                        {
                            if (labelDrawer != null)
                            {
                                Debug.LogWarning("DrawerProperty::Init->labelDrawer has been found.attr = " + attr.GetType().Name);
                            }
                            else
                            {
                                labelDrawer = drawer as PropertyLabelDrawer;
                            }
                        }
                        else if (drawer.GetType().IsSubclassOf(typeof(PropertyContentDrawer)))
                        {
                            if (contentDrawer != null)
                            {
                                Debug.LogWarning("DrawerProperty::Init->contentDrawer has been found.attr = " + attr.GetType().Name);
                            }
                            else
                            {
                                contentDrawer = drawer as PropertyContentDrawer;
                            }
                        }
                    }
                }
            }

            if (contentDrawer == null)
            {
                contentDrawer = DrawerUtility.CreateCustomTypeDrawer(this);
                if (contentDrawer == null)
                {
                    if (DrawerUtility.IsTypeSupported(ValueType))
                    {
                        if (ValueType.IsStructOrClassType() && Value != null)
                        {
                            drawerObject = new DrawerObject(Value);
                        }
                    }
                }
            }
        }