예제 #1
0
        public void OnGui(Rect position, bool addSearchField, Action <Type> onSelect, Type activeType)
        {
            var collection = TypeUtilities.GetCollection(AppearanceContext);
            var values     = collection.Values;
            var labels     = collection.Labels;
            var index      = collection.IndexOf(activeType);

            var addEmptyValue = AppearanceContext.AddEmptyValue;

            if (addSearchField)
            {
                var buttonLabel = new GUIContent(labels[index]);
                ToolboxEditorGui.DrawSearchablePopup(position, buttonLabel, index, labels, (i) =>
                {
                    var type = RetriveSelectedType(values, i, addEmptyValue);
                    onSelect?.Invoke(type);
                });
            }
            else
            {
                using (new ZeroIndentScope())
                {
                    EditorGUI.BeginChangeCheck();
                    index = EditorGUI.Popup(position, index, labels);
                    if (EditorGUI.EndChangeCheck())
                    {
                        var type = RetriveSelectedType(values, index, addEmptyValue);
                        onSelect?.Invoke(type);
                    }
                }
            }
        }
        private void DrawElement(int index)
        {
            var element = List.GetArrayElementAtIndex(index);
            var content = GetElementContent(element, index);

            ToolboxEditorGui.DrawToolboxProperty(element, content);
        }
예제 #3
0
        protected override void OnGuiSafe(SerializedProperty property, GUIContent label, float minValue, float maxValue)
        {
            ToolboxEditorGui.BeginProperty(property, ref label, out var position);
            EditorGUI.BeginChangeCheck();
            switch (property.propertyType)
            {
            case SerializedPropertyType.Integer:
                var intValue = EditorGUI.IntSlider(position, label, property.intValue, (int)minValue, (int)maxValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.intValue = intValue;
                }
                break;

            case SerializedPropertyType.Float:
                var floatValue = EditorGUI.Slider(position, label, property.floatValue, minValue, maxValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.floatValue = floatValue;
                }
                break;

            default:
                break;
            }

            ToolboxEditorGui.CloseProperty();
        }
예제 #4
0
 public PropertyScope(SerializedProperty property, GUIContent label)
 {
     this.property = property;
     ToolboxEditorGui.BeginProperty(property, ref label, out var labelRect);
     HandleEvents(labelRect);
     TryDrawLabel(labelRect, label);
 }
 protected override void OnGuiBeginSafe(LineAttribute attribute)
 {
     ToolboxEditorGui.DrawLine(attribute.Thickness,
                               attribute.Padding,
                               attribute.GuiColor,
                               attribute.IsHorizontal,
                               attribute.ApplyIndent);
 }
예제 #6
0
 protected override void OnGUISafe(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
 {
     position      = EditorGUI.IndentedRect(position);
     position.yMin = position.yMax - EditorGUIUtility.singleLineHeight;
     ToolboxEditorGui.BoldLabel(position, header);
     position.yMin = position.yMax - EditorGUIUtility.standardVerticalSpacing;
     ToolboxEditorGui.DrawLine(position, padding: 0);
 }
        /// <inheritdoc/>
        public override void DrawStandardElement(Rect rect, int index, bool selected, bool focused, bool draggable)
        {
            var element = List.GetArrayElementAtIndex(index);
            var label   = HasLabels
                ? new GUIContent(GetElementDisplayName(element, index))
                : new GUIContent();

            ToolboxEditorGui.DrawToolboxProperty(element, label);
        }
        protected override void OnGuiSafe(SerializedProperty property, GUIContent label, IgnoreParentAttribute attribute)
        {
            if (!property.hasVisibleChildren)
            {
                ToolboxEditorGui.DrawNativeProperty(property, label);
                return;
            }

            ToolboxEditorGui.DrawPropertyChildren(property);
        }
예제 #9
0
 static ReorderableListAttributeDrawer()
 {
     storage = new DrawerDataStorage <ReorderableList, ReorderableListAttribute>(false, (p, a) =>
     {
         return(ToolboxEditorGui.CreateList(p,
                                            a.ListStyle,
                                            a.ElementLabel,
                                            a.FixedSize,
                                            a.Draggable,
                                            a.HasHeader));
     });
 }
 /// <summary>
 /// Native call to draw the provided property.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="property"></param>
 /// <param name="label"></param>
 public override sealed void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
     if (IsPropertyValid(property))
     {
         OnGUISafe(position, property, label);
     }
     else
     {
         var warningContent = new GUIContent(property.displayName + " has invalid property drawer");
         ToolboxEditorLog.WrongAttributeUsageWarning(attribute, property);
         ToolboxEditorGui.DrawEmptyProperty(position, property, warningContent);
     }
 }
        protected override void OnGuiSafe(SerializedProperty property, GUIContent label, float minValue, float maxValue)
        {
            var xValue = property.vector2Value.x;
            var yValue = property.vector2Value.y;

            ToolboxEditorGui.BeginProperty(property, ref label, out var position);
            EditorGUI.BeginChangeCheck();
            ToolboxEditorGui.DrawMinMaxSlider(position, label, ref xValue, ref yValue, minValue, maxValue);
            if (EditorGUI.EndChangeCheck())
            {
                property.vector2Value = new Vector2(xValue, yValue);
            }

            ToolboxEditorGui.CloseProperty();
        }
        protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ReferencePickerAttribute attribute)
        {
            using (var propertyScope = new PropertyScope(property, label))
            {
                if (!propertyScope.IsVisible)
                {
                    return;
                }

                EditorGUI.indentLevel++;
                CreateTypeProperty(property);
                ToolboxEditorGui.DrawPropertyChildren(property);
                EditorGUI.indentLevel--;
            }
        }
        /// <summary>
        /// Draws <see cref="ReorderableList"/> if provided property is previously cached array/list or creates completely new instance.
        /// </summary>
        /// <param name="property">Property to draw.</param>
        /// <param name="attribute"></param>
        public override void OnGui(SerializedProperty property, ReorderableListAttribute attribute)
        {
            var key = GenerateKey(property);

            if (!listInstances.TryGetValue(key, out ReorderableList list))
            {
                listInstances[key] = list = ToolboxEditorGui.CreateList(property,
                                                                        attribute.ListStyle,
                                                                        attribute.ElementLabel,
                                                                        attribute.FixedSize,
                                                                        attribute.Draggable);
            }

            list.DoLayoutList();
        }
        /// <summary>
        /// Draws <see cref="ReorderableList"/> if provided property is previously cached array/list or creates completely new instance.
        /// </summary>
        /// <param name="property">Property to draw.</param>
        /// <param name="attribute"></param>
        protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ReorderableListAttribute attribute)
        {
            var key = property.GetPropertyKey();

            if (!listInstances.TryGetValue(key, out ReorderableList list))
            {
                listInstances[key] = list = ToolboxEditorGui.CreateList(property,
                                                                        attribute.ListStyle,
                                                                        attribute.ElementLabel,
                                                                        attribute.FixedSize,
                                                                        attribute.Draggable);
            }

            list.DoLayoutList();
        }
예제 #15
0
        /// <summary>
        /// Native call to draw the provided property.
        /// </summary>
        public override sealed void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (IsPropertyValid(property))
            {
                OnGUISafe(position, property, label);
                return;
            }

            var warningContent = new GUIContent(property.displayName + " has invalid property drawer");

            //create additional warning log to the console window
            ToolboxEditorLog.WrongAttributeUsageWarning(attribute, property);
            //create additional warning label based on the property name
            ToolboxEditorGui.DrawEmptyProperty(position, property, warningContent);
        }
        private void DrawElementsBody(SerializedProperty property, ScrollableItemsAttribute attribute, int size, Vector2 indexRange)
        {
            if (size == 0 || indexRange.x - indexRange.y == 0)
            {
                return;
            }

            var minRange = (int)indexRange.x;
            var maxRange = (int)indexRange.y;

            //draw all visible (in the range) properties
            for (var i = minRange; i < maxRange; i++)
            {
                ToolboxEditorGui.DrawToolboxProperty(property.GetArrayElementAtIndex(i));
            }
        }
 static ReorderableListExposedAttributeDrawer()
 {
     storage = new DrawerDataStorage <ReorderableListBase, ReorderableListExposedAttribute>(false, (p, a) =>
     {
         //create list in the standard way
         var list = ToolboxEditorGui.CreateList(p,
                                                a.ListStyle,
                                                a.ElementLabel,
                                                a.FixedSize,
                                                a.Draggable,
                                                a.HasHeader,
                                                a.HasLabels);
         //additionaly subscribe callbacks
         ConnectCallbacks(list, a);
         return(list);
     });
 }
예제 #18
0
        /// <summary>
        /// Tool initialization.
        /// </summary>
        protected override void OnEnable()
        {
            settingsSectionToggle = EditorPrefs.GetBool("TerrainEditor.settingsSectionToggle", true);
            paintingSectionToggle = EditorPrefs.GetBool("TerrainEditor.paintingSectionToggle", true);

            gridSize     = EditorPrefs.GetFloat("TerrainEditor.gridSize", 1.0f);
            brushRadius  = EditorPrefs.GetFloat("TerrainEditor.brushRadius", 8.0f);
            brushDensity = EditorPrefs.GetFloat("TerrainEditor.brushDensity", 50.0f);

            base.OnEnable();

            layerProperty        = serializedObject.FindProperty("terrainLayer");
            terrainProperty      = serializedObject.FindProperty("terrain");
            brushPrefabsProperty = serializedObject.FindProperty("brushPrefabs");

            brushPrefabsList = ToolboxEditorGui.CreateLinedList(brushPrefabsProperty, "Item");
        }
        protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
        {
            var minValue = Attribute.MinValue;
            var maxValue = Attribute.MaxValue;
            var xValue   = property.vector2Value.x;
            var yValue   = property.vector2Value.y;

            label = EditorGUI.BeginProperty(position, label, property);
            EditorGUI.BeginChangeCheck();
            ToolboxEditorGui.DrawMinMaxSlider(position, label, ref xValue, ref yValue, minValue, maxValue);
            if (EditorGUI.EndChangeCheck())
            {
                property.vector2Value = new Vector2(xValue, yValue);
            }

            EditorGUI.EndProperty();
        }
예제 #20
0
        public void OnGui(SerializedProperty property, GUIContent label, T attribute)
        {
            if (attribute == null)
            {
                return;
            }

            if (IsPropertyValid(property))
            {
                OnGuiSafe(property, label, attribute);
            }
            else
            {
                var warningContent = new GUIContent(property.displayName + " has invalid property drawer");
                ToolboxEditorLog.WrongAttributeUsageWarning(attribute, property);
                ToolboxEditorGui.DrawLayoutEmptyProperty(property, warningContent);
            }
        }
예제 #21
0
        protected override void OnGUISafe(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
        {
            using (new FixedFieldsScope())
            {
                EditorGUIUtility.labelWidth = 0;

                var vectorValue = prop.vectorValue;
                var xValue      = vectorValue.x;
                var yValue      = vectorValue.y;

                EditorGUI.BeginChangeCheck();
                ToolboxEditorGui.DrawMinMaxSlider(position, label, ref xValue, ref yValue, minValue, maxValue);
                if (EditorGUI.EndChangeCheck())
                {
                    vectorValue.x    = xValue;
                    vectorValue.y    = yValue;
                    prop.vectorValue = vectorValue;
                }
            }
        }
        public void OnGui(SerializedProperty property, GUIContent label, T attribute)
        {
            if (attribute == null)
            {
                return;
            }

            if (IsPropertyValid(property))
            {
                OnGuiSafe(property, label, attribute);
            }
            else
            {
                var warningContent = new GUIContent(property.displayName + " has invalid property drawer");
                //create additional warning log to the console window
                ToolboxEditorLog.WrongAttributeUsageWarning(attribute, property);
                //create additional warning label based on the property name
                ToolboxEditorGui.DrawEmptyProperty(property, warningContent);
            }
        }
        protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
        {
            //prepare pick button label
            var buttonLabel = property.enumValueIndex >= 0 &&
                              property.enumValueIndex < property.enumDisplayNames.Length
                ? new GUIContent(property.enumDisplayNames[property.enumValueIndex])
                : new GUIContent();
            var id = GUIUtility.GetControlID(FocusType.Keyboard, position);

            //begin the true property
            label = EditorGUI.BeginProperty(position, label, property);
            //draw the prefix label
            position = EditorGUI.PrefixLabel(position, id, label);
            //draw dropdown button, will be used to activate popup
            ToolboxEditorGui.DrawSearchablePopup(position, buttonLabel, property.enumValueIndex, property.enumDisplayNames, (i) =>
            {
                property.serializedObject.Update();
                property.enumValueIndex = i;
                property.serializedObject.ApplyModifiedProperties();
            });
            EditorGUI.EndProperty();
        }
예제 #24
0
 public void Dispose()
 {
     ToolboxEditorGui.CloseProperty();
 }
 protected override void OnGuiBeginSafe(LineAttribute attribute)
 {
     ToolboxEditorGui.DrawLayoutLine(attribute.Thickness, attribute.Padding, attribute.GetLineColor());
 }
예제 #26
0
 public override void OnGuiBegin(LineAreaAttribute attribute)
 {
     ToolboxEditorGui.DrawLayoutLine(attribute.Thickness, attribute.Padding);
 }
예제 #27
0
        /// <inheritdoc/>
        public override void DrawStandardElement(Rect rect, int index, bool selected, bool focused, bool draggable)
        {
            var element = List.GetArrayElementAtIndex(index);

            ToolboxEditorGui.DrawToolboxProperty(element, GetElementContent(element, index));
        }
 protected virtual void OnGuiSafe(SerializedProperty property, GUIContent label, T attribute)
 {
     ToolboxEditorGui.DrawDefaultProperty(property, label);
 }
예제 #29
0
        protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ScrollableItemsAttribute attribute)
        {
            if (!EditorGUILayout.PropertyField(property, label, false))
            {
                return;
            }

            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(property.GetSize());
            var size = property.arraySize;

            //get or initialize current ranges
            var indexRange = storage.ReturnItem(property, attribute);

            //create a min-max slider to determine the range of visible properties
            {
                var enabled = GUI.enabled;
                GUI.enabled = true;
                EditorGUILayout.MinMaxSlider(Style.rangeContent, ref indexRange.x, ref indexRange.y, 0, size);
                GUI.enabled = enabled;
            }

            //fix values to the integral part
            indexRange.x = Mathf.Max(Mathf.RoundToInt(indexRange.x), 0);
            indexRange.y = Mathf.Min(Mathf.RoundToInt(indexRange.y), size);
            storage.ApplyItem(property, indexRange);
            EditorGUI.indentLevel--;

            if (size == 0 || indexRange.x - indexRange.y == 0)
            {
                return;
            }

            EditorGUILayout.BeginHorizontal();
            //NOTE1: we have to handle indentation for group
            //NOTE2: 15.0f - internal 'indentPerLevel' value
            GUILayout.Space(15.0f * EditorGUI.indentLevel);

            EditorGUILayout.BeginVertical(Style.backgroundStyle);
            var space = EditorGUIUtility.standardVerticalSpacing;

            GUILayout.Space(space);
            GUILayout.Space(space);

            var minRange = (int)indexRange.x;
            var maxRange = (int)indexRange.y;

            if (minRange > 0)
            {
                EditorGUILayout.LabelField(Style.spaceContent, Style.spaceLabelStyle);
            }

            //draw all visible (in the range) properties
            for (var i = minRange; i < maxRange; i++)
            {
                ToolboxEditorGui.DrawToolboxProperty(property.GetArrayElementAtIndex(i));
            }

            if (maxRange < size)
            {
                EditorGUILayout.LabelField(Style.spaceContent, Style.spaceLabelStyle);
            }

            GUILayout.Space(space);
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        }