Exemplo n.º 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Rect optionsRect = RectUtility.SliceVertical(position, buttonsHeight, out position);

            if (typeNames == null)
            {
                RefreshTypeList(property);
            }

            //Draw type selection popup
            Rect popupRect = RectUtility.SliceHoriozntal(optionsRect, position.width - 25, out Rect menuPosition);

            selected = EditorGUI.IntPopup(popupRect, selected, typeNames, optionsValue);

            if (GUI.Button(RectUtility.SliceHoriozntal(menuPosition, 5, false), "...", EditorStyles.miniButtonRight)) //TODO: Add icon
            {
                var menu = new GenericMenu();
                menu.AddItem(new GUIContent("Inject"), false, OnInjectSelectedTypeSelected, property);
                menu.AddItem(new GUIContent("Refresh"), false, OnRefreshTypeListSelected, property);
                menu.DropDown(menuPosition);
            }

            //Draw property field
            EditorGUI.PropertyField(position, property, new GUIContent(property.displayName), true);
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GT_MinMaxRangeAttribute minMaxRangeAttr = attribute as GT_MinMaxRangeAttribute;
            Rect labelRect = RectUtility.SliceVertical(position, EditorGUIUtility.singleLineHeight, out Rect slidersRect);

            EditorGUI.LabelField(labelRect, minMaxRangeAttr.Name);
            SerializedProperty minSliderProp = property.serializedObject.FindProperty(property.propertyPath);

            if (property.Next(false))
            {
                SerializedProperty maxSliderProp = property;
                if (string.IsNullOrEmpty(maxSliderControlName))
                {
                    maxSliderControlName = "Slider_" + maxSliderProp.name;
                }


                if (minSliderProp.propertyType != maxSliderProp.propertyType)
                {
                    EditorGUI.HelpBox(position, "Properties type don't match", MessageType.Warning);
                    return;
                }


                Rect minSliderRect = RectUtility.SliceHoriozntal(slidersRect, 10, false); // make 10 pixel indent
                minSliderRect = RectUtility.SliceVertical(minSliderRect, EditorGUI.GetPropertyHeight(property), out Rect maxSliderRect);

                EditorGUI.BeginChangeCheck();
                DrawSlider(minSliderRect, minSliderProp, "Min", minMaxRangeAttr.Min, minMaxRangeAttr.Max);
                if (EditorGUI.EndChangeCheck())
                {
                    ChangeValue(minSliderProp, maxSliderProp, false);
                }

                EditorGUI.BeginChangeCheck();

                GUI.SetNextControlName(maxSliderControlName);
                DrawSlider(maxSliderRect, maxSliderProp, "Max", minMaxRangeAttr.Min, minMaxRangeAttr.Max);

                if ((EditorGUI.EndChangeCheck() && EditorGUIUtility.editingTextField == false) ||
                    GUI.GetNameOfFocusedControl() != maxSliderControlName)
                {
                    ChangeValue(minSliderProp, maxSliderProp);
                }
            }
        }