Пример #1
0
        protected override void OnBound(MemberInfo variable)
        {
            base.OnBound(variable);

            int prevLineCount = lineCount;

            if (variable == null)
            {
                lineCount = 1;
            }
            else
            {
                MultilineAttribute multilineAttribute = variable.GetAttribute <MultilineAttribute>();
                if (multilineAttribute != null)
                {
                    lineCount = Mathf.Max(1, multilineAttribute.lines);
                }
                else if (variable.HasAttribute <TextAreaAttribute>())
                {
                    lineCount = 3;
                }
                else
                {
                    lineCount = 1;
                }
            }

            if (prevLineCount != lineCount)
            {
                input.BackingField.lineType = lineCount > 1 ? InputField.LineType.MultiLineNewline : InputField.LineType.SingleLine;
                input.BackingField.textComponent.alignment = lineCount > 1 ? TextAnchor.UpperLeft : TextAnchor.MiddleLeft;

                OnSkinChanged();
            }
        }
Пример #2
0
        public EditorGUIElement_EditPropertySingleValue_Basic_BuiltIn_String(EditProperty_Single_Value p) : base(p)
        {
            use_word_wrap = p.HasCustomAttributeOfType <WordWrapAttribute>(true);

            multiline_attribute      = p.GetCustomAttributeOfType <MultilineAttribute>(true);
            auto_multiline_attribute = p.GetCustomAttributeOfType <AutoMultilineAttribute>(true);
        }
Пример #3
0
 public override object OnGUI(params GUILayoutOption[] options)
 {
     if (this.customAttribute != null)
     {
         MultilineAttribute multiline = customAttribute.Find(e => e is MultilineAttribute) as MultilineAttribute;
         if (multiline != null)
         {
             GUILayout.BeginVertical();
             EditorGUILayout.LabelField(Title);
             OnGUIUtility.Layout.IndentBegin();
             int    lines = Mathf.Max(3, multiline.lines);
             string str   = EditorGUILayout.TextArea((string)instance, GUILayout.Height(lines * 16));
             OnGUIUtility.Layout.IndentEnd();
             GUILayout.EndVertical();
             return(str);
         }
     }
     return(EditorGUILayout.DelayedTextField(Title, (string)instance, options));
 }
Пример #4
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            GUILayout.BeginHorizontal();

            float width = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 0;

            TextFieldAttribute text      = field.GetAttribute <TextFieldAttribute>();
            MultilineAttribute multiline = field.GetAttribute <MultilineAttribute>();
            TextAreaAttribute  area      = field.GetAttribute <TextAreaAttribute>();

            object value = GetValue(field);

            EditorGUI.BeginChangeCheck();
            GUIUtility.GetControlID(field.Path.GetHashCode(), FocusType.Passive);

            string result = "";

            if ((text == null && multiline == null && area == null) || (text != null && text.Type == TextFieldType.Standard))
            {
                if (style != null)
                {
                    result = EditorGUILayout.TextField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TextField((string)value);
                }
            }
            else if (multiline != null || area != null || text.Type == TextFieldType.Area)
            {
                if (style != null)
                {
                    result = EditorGUILayout.TextArea((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TextArea((string)value);
                }
            }
            else if (text.Type == TextFieldType.Password)
            {
                if (style != null)
                {
                    result = EditorGUILayout.PasswordField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.PasswordField((string)value);
                }
            }
            else if (text.Type == TextFieldType.Tag)
            {
                if (style != null)
                {
                    result = EditorGUILayout.TagField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TagField((string)value);
                }
            }
            else if (text.Type == TextFieldType.File)
            {
                if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
                {
                    result = EditorUtility.OpenFilePanel(text.Title, text.Path, text.Extension);
                }

                if (field.Mixed)
                {
                    GUILayout.Label("---");
                }
                else
                {
                    GUILayout.Label((string)value);
                }
            }
            else if (text.Type == TextFieldType.Folder)
            {
                if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
                {
                    result = EditorUtility.OpenFolderPanel(text.Title, "", "");
                }

                if (field.Mixed)
                {
                    GUILayout.Label("---");
                }
                else
                {
                    GUILayout.Label((string)value);
                }
            }

            //Custom
            else if (text.Type == TextFieldType.Prefab)
            {
                if (String.IsNullOrEmpty(text.Path))
                {
                    string prefabRemoved = field.GetValue <string>().Replace("Prefabs/", "");
                    //string prefabRemoved = field.GetValue<string>();
                    string[] PrefabListNoPrefix = UnityDrawerStatics.PrefabList
                                                  .Select(x => x.Replace("Prefabs/", ""))
                                                  .ToArray();
                    PrefabListNoPrefix = AddNoneToStringArray(PrefabListNoPrefix);

                    //int sel = Math.Max(Array.IndexOf(UnityDrawerStatics.PrefabList, prefabRemoved), 0);
                    int sel = Math.Max(Array.IndexOf(PrefabListNoPrefix, prefabRemoved), 0);
                    int idx = EditorGUILayout.Popup(sel, PrefabListNoPrefix);
                    //result = "Prefabs/" + UnityDrawerStatics.PrefabList[idx];
                    //result = UnityDrawerStatics.PrefabList[idx];
                    result = "Prefabs/" + PrefabListNoPrefix[idx];
                }
                else
                {
                    //Debug.Log($"Pruning by {text.Path}");
                    string[] pruned = PrunePrefabListByPath(UnityDrawerStatics.PrefabList, text.Path);
                    pruned = AddNoneToStringArray(pruned);
                    string prefabRemoved = field.GetValue <string>().Replace("Prefabs/", "");
                    int    sel           = Math.Max(Array.IndexOf(pruned, prefabRemoved), 0);
                    int    idx           = EditorGUILayout.Popup(sel, pruned);
                    result = "Prefabs/" + pruned[idx];
                    //Debug.Log($"Result of prune is {result}");
                }
            }
            else if (text.Type == TextFieldType.Entity)
            {
                int sel = Math.Max(Array.IndexOf(UnityDrawerStatics.EntityList, field.GetValue <string>()), 0);

                int idx = EditorGUILayout.Popup(sel, UnityDrawerStatics.EntityList);
                result = UnityDrawerStatics.EntityList[idx];
            }
            else if (text.Type == TextFieldType.Component)
            {
                int sel = Math.Max(Array.IndexOf(UnityDrawerStatics.ComponentList, field.GetValue <string>()), 0);

                int idx = EditorGUILayout.Popup(sel, UnityDrawerStatics.ComponentList);
                result = UnityDrawerStatics.ComponentList[idx];
            }

            if (EditorGUI.EndChangeCheck())
            {
                field.SetValue(result);
            }

            EditorGUIUtility.labelWidth = width;

            GUILayout.EndHorizontal();
        }
        /// <inheritdoc />
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Retrieve attributes
            List <ConditionalAttribute> conditionalAttributes = new List <ConditionalAttribute>();

            // ColorUsageAttribute colorUsageAttribute = null;
#if UNITY_5_3_OR_NEWER
            DelayedAttribute delayedAttribute = null;
#endif
            MultilineAttribute multilineAttribute = null;
            TextAreaAttribute  textAreaAttribute  = null;
            RangeAttribute     rangeAttribute     = null;
            ReadOnlyAttribute  readOnlyAttribute  = null;

            object[] customAttributes = fieldInfo.GetCustomAttributes(false);
            for (int i = 0; i < customAttributes.Length; i++)
            {
                if (customAttributes[i] is ConditionalAttribute)
                {
                    conditionalAttributes.Add((ConditionalAttribute)customAttributes[i]);
                }
                // else if (customAttributes[i] is ColorUsageAttribute)
                // {
                //     colorUsageAttribute = (ColorUsageAttribute)customAttributes[i];
                // }
#if UNITY_5_3_OR_NEWER
                else if (customAttributes[i] is DelayedAttribute)
                {
                    delayedAttribute = (DelayedAttribute)customAttributes[i];
                }
#endif
                else if (customAttributes[i] is MultilineAttribute)
                {
                    multilineAttribute = (MultilineAttribute)customAttributes[i];
                }
                else if (customAttributes[i] is TextAreaAttribute)
                {
                    textAreaAttribute = (TextAreaAttribute)customAttributes[i];
                }
                else if (customAttributes[i] is RangeAttribute)
                {
                    rangeAttribute = (RangeAttribute)customAttributes[i];
                }
                else if (customAttributes[i] is ReadOnlyAttribute)
                {
                    readOnlyAttribute = (ReadOnlyAttribute)customAttributes[i];
                }
                else if (customAttributes[i] is TooltipAttribute ||
                         customAttributes[i] is SerializeField ||
                         customAttributes[i] is NonSerializedAttribute)
                {
                    // Ignored attributes
                }
                else
                {
                    Debug.LogWarning("ConditionalPropertyDrawer needs implementation for type " + customAttributes[i].ToString());
                }
            }

            int conditionCount = 0;
            for (int i = 0; i < conditionalAttributes.Count; i++)
            {
                if (conditionalAttributes[i].Conditions != null)
                {
                    conditionCount += conditionalAttributes[i].Conditions.Length;
                }
            }

            ConditionalAttribute.Condition[] conditions = new ConditionalAttribute.Condition[conditionCount];

            int index = 0;
            for (int i = 0; i < conditionalAttributes.Count; i++)
            {
                if (conditionalAttributes[i].Conditions != null)
                {
                    ConditionalAttribute.Condition[] conds = conditionalAttributes[i].Conditions;
                    for (int j = 0; j < conds.Length; j++)
                    {
                        conditions[index++] = conds[j];
                    }
                }
            }

            Attribute.Show = true;
            try
            {
                Attribute.Show = ShouldShow(property, conditions);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            if (Attribute.Show)
            {
                if (readOnlyAttribute != null)
                {
                    GUI.enabled = false;
                }

                // Implementations obtained through inspection
#if UNITY_5_3_OR_NEWER
                if (delayedAttribute != null)
                {
                    PropertyDrawer propertyDrawer = GetPropertyDrawer("UnityEditor.DelayedDrawer,UnityEditor");
                    propertyDrawer.OnGUI(position, property, label);
                }
                else
#endif

/*                 if (colorUsageAttribute != null)
 *              {
 *
 *                  EditorGUI.BeginChangeCheck();
 #if UNITY_5_3_OR_NEWER
 *                  ColorPickerHDRConfig hdrConfig = new ColorPickerHDRConfig(
 *                      colorUsageAttribute.minBrightness, colorUsageAttribute.maxBrightness,
 *                      colorUsageAttribute.minExposureValue, colorUsageAttribute.maxExposureValue);
 *                  Color color = EditorGUI.ColorField(position, label, property.colorValue,
 *                      true, colorUsageAttribute.showAlpha, colorUsageAttribute.hdr, hdrConfig);
 #else
 *                                      Color color = EditorGUI.ColorField(position, label, property.colorValue);
 #endif
 *                  if (EditorGUI.EndChangeCheck())
 *                  {
 *                      property.colorValue = color;
 *                  }
 *              }
 *              else
 */
                if (multilineAttribute != null)
                {
                    PropertyDrawer propertyDrawer = GetPropertyDrawer("UnityEditor.MultilineDrawer,UnityEditor");
                    propertyDrawer.OnGUI(position, property, label);
                }
                else if (textAreaAttribute != null)
                {
                    PropertyDrawer propertyDrawer = GetPropertyDrawer("UnityEditor.TextAreaDrawer,UnityEditor");
                    propertyDrawer.OnGUI(position, property, label);
                }
                else if (rangeAttribute != null)
                {
                    if (property.propertyType == SerializedPropertyType.Float)
                    {
                        EditorGUI.Slider(position, property, rangeAttribute.min, rangeAttribute.max, label);
                    }
                    else if (property.propertyType == SerializedPropertyType.Integer)
                    {
                        EditorGUI.IntSlider(position, property, (int)rangeAttribute.min, (int)rangeAttribute.max, label);
                    }
                    else
                    {
                        EditorGUI.LabelField(position, label.text, "Use Range with float or int.");
                    }
                }
                else
                {
                    EditorGUI.PropertyField(position, property, label, false);
                }

                if (readOnlyAttribute != null)
                {
                    GUI.enabled = true;
                }
            }
        }
Пример #6
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            GUILayout.BeginHorizontal();

            float width = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 0;

            TextFieldAttribute text      = field.GetAttribute <TextFieldAttribute>();
            MultilineAttribute multiline = field.GetAttribute <MultilineAttribute>();
            TextAreaAttribute  area      = field.GetAttribute <TextAreaAttribute>();

            object value = GetValue(field);

            EditorGUI.BeginChangeCheck();
            GUIUtility.GetControlID(field.Path.GetHashCode(), FocusType.Passive);

            string result = "";

            if ((text == null && multiline == null && area == null) || (text != null && text.Type == TextFieldType.Standard))
            {
                if (style != null)
                {
                    result = EditorGUILayout.TextField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TextField((string)value);
                }
            }
            else if (multiline != null || area != null || text.Type == TextFieldType.Area)
            {
                if (style != null)
                {
                    result = EditorGUILayout.TextArea((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TextArea((string)value);
                }
            }
            else if (text.Type == TextFieldType.Password)
            {
                if (style != null)
                {
                    result = EditorGUILayout.PasswordField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.PasswordField((string)value);
                }
            }
            else if (text.Type == TextFieldType.Tag)
            {
                if (style != null)
                {
                    result = EditorGUILayout.TagField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TagField((string)value);
                }
            }
            else if (text.Type == TextFieldType.File)
            {
                if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
                {
                    result = EditorUtility.OpenFilePanel(text.Title, text.Path, text.Extension);
                }

                if (field.Mixed)
                {
                    GUILayout.Label("---");
                }
                else
                {
                    GUILayout.Label((string)value);
                }
            }
            else if (text.Type == TextFieldType.Folder)
            {
                if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
                {
                    result = EditorUtility.OpenFolderPanel(text.Title, "", "");
                }

                if (field.Mixed)
                {
                    GUILayout.Label("---");
                }
                else
                {
                    GUILayout.Label((string)value);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                field.SetValue(result);
            }

            EditorGUIUtility.labelWidth = width;

            GUILayout.EndHorizontal();
        }