Ejemplo n.º 1
0
 internal void ClearArrayElement()
 {
     if (ValueType.IsArrayOrListType())
     {
         if (ValueType.IsArray)
         {
             Value = DrawerUtility.CreateInstance(ValueType);
         }
         else
         {
             ((IList)Value).Clear();
         }
     }
 }
Ejemplo n.º 2
0
        internal void AddArrayElement()
        {
            if (ValueType.IsArrayOrListType())
            {
                object element = DrawerUtility.CreateInstance(ValueType.GetElementTypeInArrayOrList());
                if (ValueType.IsArray)
                {
                    Array array = (Array)Value;
                    ArrayUtility.Add(ref array, element);

                    Value = array;
                }
                else
                {
                    ((IList)Value).Add(element);
                }
            }
        }
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();
                }
            }
        }