Exemplo n.º 1
0
 public static object DrawField(string _name, Type _fieldType, object _value)
 {
     if (typeof(IList).IsAssignableFrom(_fieldType))
     {
         return(EditorGUILayoutExtension.DrawArrayField(EditorGUIExtension.GetGUIContent(_name), null, _fieldType, _value));
     }
     return(EditorGUILayoutExtension.DrawSingleField(EditorGUIExtension.GetGUIContent(_name), null, _fieldType, _value));
 }
Exemplo n.º 2
0
        public static object DrawField(FieldInfo _fieldInfo, object _value)
        {
            GUIContent content = null;

            if (Utility_Attribute.TryGetFieldInfoAttribute(_fieldInfo, out TooltipAttribute tooltipAtt))
            {
                content = EditorGUIExtension.GetGUIContent(ObjectNames.NicifyVariableName(_fieldInfo.Name), tooltipAtt.tooltip);
            }
            else
            {
                content = EditorGUIExtension.GetGUIContent(ObjectNames.NicifyVariableName(_fieldInfo.Name));
            }
            return(DrawField(content, _fieldInfo, _value));
        }
Exemplo n.º 3
0
        public static bool DrawFoldout(int hash, GUIContent guiContent)
        {
            string text = string.Concat(new object[]
            {
                c_EditorPrefsFoldoutKey,
                hash,
                ".",
                guiContent.text
            });
            bool @bool = EditorGUIExtension.GetFoldoutBool(text);
            bool flag  = EditorGUILayout.Foldout(@bool, guiContent, true, EditorStylesExtension.FoldoutStyle);

            if (flag != @bool)
            {
                EditorGUIExtension.SetFoldoutBool(text, flag);
            }
            return(flag);
        }
Exemplo n.º 4
0
        private static object DrawArrayField(GUIContent _content, FieldInfo _fieldInfo, Type _fieldType, object _value)
        {
            Type elementType;

            if (_fieldType.IsArray)
            {
                elementType = _fieldType.GetElementType();
            }
            else
            {
                Type type2 = _fieldType;
                while (!type2.IsGenericType)
                {
                    type2 = type2.BaseType;
                }
                elementType = type2.GetGenericArguments()[0];
            }
            IList list;

            if (_value == null)
            {
                if (_fieldType.IsGenericType || _fieldType.IsArray)
                {
                    _value = list = (Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[]
                    {
                        elementType
                    }), true) as IList);
                }
                else
                {
                    _value = list = (Activator.CreateInstance(_fieldType, true) as IList);
                }
                if (_fieldType.IsArray)
                {
                    Array array = Array.CreateInstance(elementType, list.Count);
                    list.CopyTo(array, 0);
                    _value = list = array;
                }
                GUI.changed = true;
            }
            else
            {
                list = (IList)_value;
            }
            if (EditorGUILayoutExtension.DrawFoldout(_value.GetHashCode(), _content))
            {
                EditorGUI.indentLevel++;
                bool flag     = _value.GetHashCode() == EditorGUILayoutExtension.editingFieldHash;
                int  count    = (!flag) ? list.Count : EditorGUILayoutExtension.savedArraySize;
                int  newCount = EditorGUILayout.IntField(EditorGUIExtension.GetGUIContent("Size"), count);
                if (flag && EditorGUILayoutExtension.editingArray && (GUIUtility.keyboardControl != EditorGUILayoutExtension.currentKeyboardControl ||
                                                                      (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return)))
                {
                    if (newCount != list.Count)
                    {
                        int currentCount = list.Count;
                        if (newCount > currentCount)
                        {
                            if (_fieldType.IsArray)
                            {
                                Array array2 = Array.CreateInstance(elementType, newCount);
                                int   num3   = -1;
                                for (int i = 0; i < newCount; i++)
                                {
                                    if (i < list.Count)
                                    {
                                        num3 = i;
                                    }
                                    if (num3 == -1)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                Type type = list.Count > 0 ? list[list.Count - 1].GetType() : elementType;
                                if (!typeof(UnityObject).IsAssignableFrom(type))
                                {
                                    for (int i = currentCount; i < newCount; i++)
                                    {
                                        list.Add(Activator.CreateInstance(type, true));
                                    }
                                }
                                else
                                {
                                    for (int i = currentCount; i < newCount; i++)
                                    {
                                        list.Add(null);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (!_fieldType.IsArray)
                            {
                                while (list.Count > newCount)
                                {
                                    list.RemoveAt(list.Count - 1);
                                }
                            }
                        }
                    }
                    EditorGUILayoutExtension.editingArray     = false;
                    EditorGUILayoutExtension.savedArraySize   = -1;
                    EditorGUILayoutExtension.editingFieldHash = -1;
                    GUI.changed = true;
                }
                else if (newCount != count)
                {
                    if (!EditorGUILayoutExtension.editingArray)
                    {
                        EditorGUILayoutExtension.currentKeyboardControl = GUIUtility.keyboardControl;
                        EditorGUILayoutExtension.editingArray           = true;
                        EditorGUILayoutExtension.editingFieldHash       = _value.GetHashCode();
                    }
                    EditorGUILayoutExtension.savedArraySize = newCount;
                }

                if (_fieldInfo != null &&
                    (Utility_Attribute.TryGetFieldInfoAttribute(_fieldInfo, out FieldAttribute att) ||
                     Utility_Attribute.TryGetTypeAttribute(elementType, out att)))
                {
                    for (int k = 0; k < list.Count; k++)
                    {
                        FieldDrawer objectDrawer;
                        if ((objectDrawer = ObjectDrawerUtility.GetObjectDrawer(att)) != null)
                        {
                            _content.text      = "Element " + k;
                            objectDrawer.Value = list[k];
                            objectDrawer.OnGUI(_content);
                            if (objectDrawer.Value != list[k])
                            {
                                list[k]     = objectDrawer.Value;
                                GUI.changed = true;
                            }
                        }
                    }
                }
                else
                {
                    for (int k = 0; k < list.Count; k++)
                    {
                        _content.text = "Element " + k;
                        list[k]       = EditorGUILayoutExtension.DrawField(_content, elementType, list[k]);
                    }
                }
                EditorGUI.indentLevel--;
            }
            return(list);
        }
Exemplo n.º 5
0
 public static object DrawField(string _name, FieldInfo _fieldInfo, object _value)
 {
     return(DrawField(EditorGUIExtension.GetGUIContent(_name), _fieldInfo, _value));
 }
Exemplo n.º 6
0
        /// <summary> 绘制一个可接收拖拽资源的区域 </summary>
        public static UnityObject DragDropAreaSingle(Rect _rect, DragAndDropVisualMode _dropVisualMode, Color _hightlightColor, params GUILayoutOption[] _options)
        {
            Rect rect = GUILayoutUtility.GetRect(new GUIContent(), GUI.skin.label, _options);

            return(EditorGUIExtension.DragDropAreaSingle(rect, _dropVisualMode, _hightlightColor));
        }
Exemplo n.º 7
0
        /// <summary> 绘制一个可接收拖拽资源的区域 </summary>
        public static UnityObject DragDropAreaSingle(params GUILayoutOption[] _options)
        {
            Rect rect = GUILayoutUtility.GetRect(new GUIContent(), GUI.skin.label, _options);

            return(EditorGUIExtension.DragDropAreaSingle(rect));
        }
Exemplo n.º 8
0
        /// <summary> 绘制一个可接收拖拽资源的区域 </summary>
        public static UnityObject[] DragDropAreaMulti(Color _hightlightColor, params GUILayoutOption[] _options)
        {
            Rect rect = GUILayoutUtility.GetRect(new GUIContent(), GUI.skin.label, _options);

            return(EditorGUIExtension.DragDropAreaMulti(rect, _hightlightColor));
        }
Exemplo n.º 9
0
        /// <summary> 绘制一个可接收拖拽资源的区域 </summary>
        public static UnityObject[] DragDropAreaMulti(DragAndDropVisualMode _dropVisualMode, params GUILayoutOption[] _options)
        {
            Rect rect = GUILayoutUtility.GetRect(new GUIContent(), GUI.skin.label, _options);

            return(EditorGUIExtension.DragDropAreaMulti(rect, _dropVisualMode));
        }