Beispiel #1
0
        protected override void OnDrawProperty(string label)
        {
            var  flagAttrs  = DrawerProperty.ValueType.GetCustomAttributes(typeof(FlagsAttribute), false);
            bool isFlagEnum = false;

            if (flagAttrs != null && flagAttrs.Length > 0)
            {
                isFlagEnum = true;
            }

            label = label ?? "";
            Enum value = DrawerProperty.GetValue <Enum>();

            EditorGUI.BeginChangeCheck();
            {
                if (isFlagEnum)
                {
                    value = EditorGUILayout.EnumFlagsField(label, value);
                }
                else
                {
                    value = EditorGUILayout.EnumPopup(label, value);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                DrawerProperty.Value = value;
            }
        }
Beispiel #2
0
        protected override void OnDrawProperty(string label)
        {
            var attr = GetAttr <IntSliderAttribute>();

            int leftValue  = attr.LeftValue;
            int rightValue = attr.RightValue;

            if (!string.IsNullOrEmpty(attr.LeftValueMemberName))
            {
                leftValue = NativeDrawerUtility.GetMemberValue <int>(attr.LeftValueMemberName, DrawerProperty.Target);
            }
            if (!string.IsNullOrEmpty(attr.RightValueMemberName))
            {
                rightValue = NativeDrawerUtility.GetMemberValue <int>(attr.RightValueMemberName, DrawerProperty.Target);
            }

            label = label ?? "";

            int value = DrawerProperty.GetValue <int>();

            EditorGUI.BeginChangeCheck();
            {
                value = EditorGUILayout.IntSlider(label, value, leftValue, rightValue);
            }
            if (EditorGUI.EndChangeCheck())
            {
                DrawerProperty.Value = value;
            }
        }
Beispiel #3
0
        protected override void OnDrawProperty(string label)
        {
            var attr = GetAttr <StringPopupAttribute>();

            string[] options = attr.Options;
            if (!string.IsNullOrEmpty(attr.MemberName))
            {
                options = NativeDrawerUtility.GetMemberValue <string[]>(attr.MemberName, DrawerProperty.Target);
            }

            var value = DrawerProperty.GetValue <string>();

            label = label ?? "";

            if (attr.IsSearchable)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.PrefixLabel(label);
                    Rect btnRect = GUILayoutUtility.GetRect(new GUIContent(value), "dropdownbutton");

                    if (EditorGUI.DropdownButton(btnRect, new GUIContent(value), FocusType.Keyboard))
                    {
                        try
                        {
                            SearchablePopup.Show(btnRect, new Vector2(200, 400), Array.IndexOf(options, value), options, (selected) =>
                            {
                                DrawerProperty.Value = options[selected];
                            });
                        }
                        catch (ExitGUIException)
                        {
                            lastSearchableWindow = EditorWindow.focusedWindow;
                            throw;
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (lastSearchableWindow && lastSearchableWindow != EditorWindow.mouseOverWindow)
                {
                    if (Event.current.type == EventType.ScrollWheel)
                    {
                        Event.current.Use();
                    }
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                {
                    value = EGUILayout.DrawPopup <string>(label, options, options, value);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    DrawerProperty.Value = value;
                }
            }
        }
Beispiel #4
0
        private void InitList()
        {
            list = DrawerProperty.GetValue <IList>();

            elementProperties.Clear();
            for (int i = 0; i < list.Count; ++i)
            {
                elementProperties.Add(new NativeDrawerProperty(DrawerProperty.Target, DrawerProperty.Field, i));
            }
        }
Beispiel #5
0
        protected override void OnDrawProperty(string label)
        {
            if (list == null)
            {
                list = DrawerProperty.GetValue <IList>();
            }

            EditorGUILayout.BeginVertical(EGUIStyles.BoxStyle);
            {
                EditorGUILayout.LabelField(GUIContent.none, EditorStyles.toolbar, GUILayout.ExpandWidth(true));

                Rect lastRect = GUILayoutUtility.GetLastRect();
                EditorGUI.LabelField(lastRect, label, EGUIStyles.BoldLabelStyle);

                Rect clearBtnRect = new Rect(lastRect.x + lastRect.width - 40, lastRect.y, 40, lastRect.height);
                if (GUI.Button(clearBtnRect, "C", EditorStyles.toolbarButton))
                {
                    DrawerProperty.ClearArrayElement();
                    InitList();
                }

                for (int i = 0; i < list.Count; ++i)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.BeginVertical();
                        {
                            elementProperties[i].OnGUILayout();
                        }
                        EditorGUILayout.EndVertical();
                        EditorGUILayout.BeginVertical(GUILayout.Width(20));
                        {
                            if (GUILayout.Button("-", GUILayout.Width(20)))
                            {
                                DrawerProperty.RemoveArrayElementAtIndex(i);
                                InitList();
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();

                    EGUILayout.DrawHorizontalLine();
                }
                Rect addBtnRect = GUILayoutUtility.GetRect(lastRect.width, 20);
                addBtnRect.x    += addBtnRect.width - 40;
                addBtnRect.width = 40;
                if (GUI.Button(addBtnRect, "+"))
                {
                    DrawerProperty.AddArrayElement();
                    InitList();
                }
            }
            EditorGUILayout.EndVertical();
        }
        protected override void OnDrawProperty(string label)
        {
            label = label ?? "";
            float value = DrawerProperty.GetValue <float>();

            EditorGUI.BeginChangeCheck();
            {
                value = EditorGUILayout.FloatField(label, value);
            }
            if (EditorGUI.EndChangeCheck())
            {
                DrawerProperty.Value = value;
            }
        }
        protected override void OnDrawProperty(string label)
        {
            string value = DrawerProperty.GetValue <string>();
            var    attr  = GetAttr <OpenFolderPathAttribute>();

            EditorGUI.BeginChangeCheck();
            {
                value = EGUILayout.DrawOpenFolder(label, value, attr.IsAbsolute);
            }
            if (EditorGUI.EndChangeCheck())
            {
                DrawerProperty.Value = value;
            }
        }
Beispiel #8
0
        protected override void OnDrawProperty(string label)
        {
            label = label ?? "";
            bool value = DrawerProperty.GetValue <bool>();

            EditorGUI.BeginChangeCheck();
            {
                value = EditorGUILayout.Toggle(label, value);
            }
            if (EditorGUI.EndChangeCheck())
            {
                DrawerProperty.Value = value;
            }
        }
        protected override void OnDrawProperty(string label)
        {
            label = label ?? "";
            UnityObject value = DrawerProperty.GetValue <UnityObject>();

            EditorGUI.BeginChangeCheck();
            {
                value = EditorGUILayout.ObjectField(label, value, DrawerProperty.ValueType, true);
            }
            if (EditorGUI.EndChangeCheck())
            {
                DrawerProperty.Value = value;
            }
        }
Beispiel #10
0
        protected override void OnDrawProperty(string label)
        {
            string value = DrawerProperty.GetValue <string>();
            var    attr  = GetAttr <OpenFilePathAttribute>();

            EditorGUI.BeginChangeCheck();
            {
                if (attr.Filters != null && attr.Filters.Length > 0)
                {
                    value = EGUILayout.DrawOpenFileWithFilter(label, value, attr.Filters, attr.IsAbsolute);
                }
                else
                {
                    value = EGUILayout.DrawOpenFile(label, value, attr.Extension, attr.IsAbsolute);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                DrawerProperty.Value = value;
            }
        }
Beispiel #11
0
        protected override void OnDrawProperty(string label)
        {
            var attr = GetAttr <MultilineTextAttribute>();

            label = label ?? "";
            string value = DrawerProperty.GetValue <string>();

            EditorGUILayout.LabelField(label);
            EditorGUI.BeginChangeCheck();
            {
                EGUI.BeginIndent();
                {
                    value = EditorGUILayout.TextArea(value, GUILayout.Height(EditorGUIUtility.singleLineHeight * attr.LineCount));
                }
                EGUI.EndIndent();
            }
            if (EditorGUI.EndChangeCheck())
            {
                DrawerProperty.Value = value;
            }
        }