internal void ClearArrayElement()
 {
     if (TypeUtility.IsArrayOrList(ValueType))
     {
         if (ValueType.IsArray)
         {
             Value = NativeDrawerUtility.CreateDefaultInstance(ValueType);
         }
         else
         {
             ((IList)Value).Clear();
         }
     }
 }
 private void InitDrawer()
 {
     typeDrawer = NativeDrawerUtility.CreateDefaultTypeDrawer(this);
     if (typeDrawer == null)
     {
         if (NativeDrawerUtility.IsTypeSupported(ValueType))
         {
             if (TypeUtility.IsStructOrClass(ValueType) && Value != null)
             {
                 drawerObject = new NativeDrawerObject(Value);
             }
         }
     }
 }
        internal void AddArrayElement()
        {
            if (TypeUtility.IsArrayOrList(ValueType))
            {
                object element = NativeDrawerUtility.CreateDefaultInstance(TypeUtility.GetArrayOrListElementType(ValueType));
                if (ValueType.IsArray)
                {
                    Array array = (Array)Value;
                    ArrayUtility.Add(ref array, element);

                    Value = array;
                }
                else
                {
                    ((IList)Value).Add(element);
                }
            }
        }
Ejemplo n.º 4
0
        private void InitField()
        {
            Type[] allTypes = NativeDrawerUtility.GetAllBaseTypes(drawerObject.GetType());
            if (allTypes != null)
            {
                foreach (var type in allTypes)
                {
                    TypeDrawerProperty typeDrawerProperty = new TypeDrawerProperty()
                    {
                        type = type,
                    };

                    FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                    foreach (var field in fields)
                    {
                        NativeDrawerProperty drawerProperty = new NativeDrawerProperty(drawerObject, field);
                        typeDrawerProperty.drawerProperties.Add(drawerProperty);
                    }

                    typeDrawerProperties.Add(typeDrawerProperty);
                }
            }
        }
        internal void OnGUILayout()
        {
            bool isVisible = IsVisible();

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

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

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

                foreach (var drawer in propertyControlDrawers)
                {
                    drawer.OnStartGUILayout();
                }

                string label = GetFieldLabel();
                if (!string.IsNullOrEmpty(label))
                {
                    label = UnityEditor.ObjectNames.NicifyVariableName(label);
                }
                if (propertyDrawers.Count == 0)
                {
                    if (typeDrawer != null)
                    {
                        typeDrawer.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 (!NativeDrawerUtility.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 = NativeDrawerUtility.CreateDefaultInstance(ValueType);
                                    InitDrawer();
                                }
                            }
                            UnityEditor.EditorGUILayout.EndHorizontal();
                        }
                        else
                        {
                            EGUI.BeginGUIColor(UnityEngine.Color.red);
                            {
                                UnityEditor.EditorGUILayout.LabelField(string.IsNullOrEmpty(label) ? "" : label, "Unknown Drawer");
                            }
                            EGUI.EndGUIColor();
                        }
                    }
                }
                else
                {
                    foreach (var drawer in propertyDrawers)
                    {
                        drawer.OnGUILayout(label);
                    }
                }

                foreach (var drawer in propertyControlDrawers)
                {
                    drawer.OnEndGUILayout();
                }
            }
        }
        private void InitFieldAttr()
        {
            var decoratorAttrEnumerable = Field.GetCustomAttributes <DecoratorAttribute>();

            foreach (var attr in decoratorAttrEnumerable)
            {
                decoratorDrawers.Add(NativeDrawerUtility.CreateDecoratorDrawer(this, attr));
            }

            var layoutAttrEnumerable = Field.GetCustomAttributes <LayoutAttribute>();

            foreach (var attr in layoutAttrEnumerable)
            {
                layoutDrawers.Add(NativeDrawerUtility.CreateLayoutDrawer(attr));
            }

            var verificationAttrEnumerable = Field.GetCustomAttributes <VerificationCompareAttribute>();

            foreach (var attr in verificationAttrEnumerable)
            {
                verificationDrawers.Add(NativeDrawerUtility.CreateVerificationDrawer(Target, attr));
            }

            var visibleAttrEnumerable = Field.GetCustomAttributes <VisibleAtrribute>();

            foreach (var attr in visibleAttrEnumerable)
            {
                visibleDrawers.Add(NativeDrawerUtility.CreateVisibleDrawer(attr));
            }

            var visibleCompareAttrEnumerable = Field.GetCustomAttributes <VisibleCompareAttribute>();

            foreach (var attr in visibleCompareAttrEnumerable)
            {
                visibleCompareDrawers.Add(NativeDrawerUtility.CreateVisibleCompareDrawer(Target, attr));
            }

            var propertyLabelAttrEnumerable = Field.GetCustomAttributes <PropertyLabelAttribute>();

            foreach (var attr in propertyLabelAttrEnumerable)
            {
                propertyLabelDrawers.Add(NativeDrawerUtility.CreatePropertyLabelDrawer(attr));
            }

            var propertyControlAttrEnumerable = Field.GetCustomAttributes <PropertyControlAttribute>();

            foreach (var attr in propertyControlAttrEnumerable)
            {
                propertyControlDrawers.Add(NativeDrawerUtility.CreatePropertyControlDrawer(attr));
            }

            var propertyAttrEnumerable = Field.GetCustomAttributes <PropertyDrawerAttribute>();

            foreach (var attr in propertyAttrEnumerable)
            {
                propertyDrawers.Add(NativeDrawerUtility.CreatePropertyDrawer(this, attr));
            }

            var listenerAttrEnumerable = Field.GetCustomAttributes <ListenerAttribute>();

            foreach (var attr in listenerAttrEnumerable)
            {
                listenerDrawers.Add(NativeDrawerUtility.CreateListenerDrawer(Target, attr));
            }
        }
        protected bool IsEqual()
        {
            CompareDrawerAttribute attr = GetAttr <CompareDrawerAttribute>();

            if (string.IsNullOrEmpty(attr.MemberName))
            {
                return(true);
            }

            object comparedValue = NativeDrawerUtility.GetMemberValue(attr.MemberName, Target);

            if (comparedValue == null && attr.Value == null)
            {
                return(true);
            }
            if (comparedValue == null || attr.Value == null)
            {
                return(false);
            }

            if (comparedValue.GetType() != attr.Value.GetType())
            {
                return(false);
            }

            if (TypeUtility.IsCastableTo(comparedValue.GetType(), typeof(IComparable)))
            {
                int compared = ((IComparable)comparedValue).CompareTo((IComparable)attr.Value);

                if (compared == 0)
                {
                    if (attr.Symbol == CompareSymbol.Gte || attr.Symbol == CompareSymbol.Lte || attr.Symbol == CompareSymbol.Eq)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (attr.Symbol == CompareSymbol.Neq)
                    {
                        return(true);
                    }
                    else if (attr.Symbol == CompareSymbol.Eq)
                    {
                        return(false);
                    }

                    if (compared > 0 && (attr.Symbol == CompareSymbol.Gt || attr.Symbol == CompareSymbol.Gte))
                    {
                        return(true);
                    }
                    else if (compared < 0 && (attr.Symbol == CompareSymbol.Lt || attr.Symbol == CompareSymbol.Lte))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                bool result = comparedValue == attr.Value;
                if (result && (attr.Symbol == CompareSymbol.Eq || attr.Symbol == CompareSymbol.Lte || attr.Symbol == CompareSymbol.Gte))
                {
                    return(true);
                }
                else if (!result && (attr.Symbol == CompareSymbol.Neq))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }