Added Editor Menu Option to create a Min/Max slider

Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/270
pull/413/head
Simon Jackson 2022-12-30 17:54:17 +00:00
parent 2848008f63
commit 4ffa631059
1 changed files with 433 additions and 423 deletions

View File

@ -2068,63 +2068,71 @@ namespace UnityEditor.UI
static public void AddMinMaxSlider(MenuCommand menuCommand)
{
GameObject minMaxSliderRoot = CreateUIElementRoot("Min Max Slider", menuCommand, new Vector2(390, 60));
//GameObject background = CreateUIObject("Background", rangeSliderRoot);
GameObject sliderBounds = CreateUIObject("Slider Bounds", minMaxSliderRoot);
GameObject middleGraphic = CreateUIObject("Middle Graphic", minMaxSliderRoot);
GameObject minHandle = CreateUIObject("Min Handle", minMaxSliderRoot);
GameObject minHandleText = CreateUIObject("Min Text", minHandle);
GameObject maxHandle = CreateUIObject("Max Handle", minMaxSliderRoot);
GameObject maxHandleText = CreateUIObject("Max Text", maxHandle);
SetAnchorsAndStretch(minMaxSliderRoot);
Image backgroundImage = minMaxSliderRoot.AddComponent<Image>();
backgroundImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
backgroundImage.type = Image.Type.Sliced;
backgroundImage.fillCenter = false;
backgroundImage.color = new Color(27, 41, 89);
RectTransform backgroundRect = backgroundImage.rectTransform;
backgroundRect.anchorMin = new Vector2(0.5f, 0.5f);
backgroundRect.anchorMax = new Vector2(0.5f, 0.5f);
backgroundRect.sizeDelta = Vector2.zero;
backgroundImage.color = new Color32(27, 41, 89, 255);
backgroundImage.fillCenter = true;
RectTransform sliderBoundsRect = SetAnchorsAndStretch(sliderBounds);
sliderBoundsRect.anchorMin = new Vector2(0, 0);
sliderBoundsRect.anchorMax = new Vector2(1, 1);
sliderBoundsRect.offsetMin = new Vector2(15, 0);
sliderBoundsRect.offsetMax = new Vector2(-15, 0);
RectTransform middleGraphicRect = SetAnchorsAndStretch(middleGraphic);
middleGraphicRect.anchorMin = new Vector2(0, 0);
middleGraphicRect.anchorMax = new Vector2(1, 1);
middleGraphicRect.offsetMin = new Vector2(82, 0);
middleGraphicRect.offsetMax = new Vector2(-90, 0);
Image fillImage = middleGraphic.AddComponent<Image>();
fillImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
fillImage.type = Image.Type.Sliced;
fillImage.fillCenter = true;
fillImage.color = new Color(41, 98, 164);
fillImage.color = new Color32(41, 98, 164, 255);
RectTransform minHandleRect = SetAnchorsAndStretch(minHandle);
Image lowHandleImage = minHandle.AddComponent<Image>();
lowHandleImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
minHandleRect.anchorMin = new Vector2(0, 0.5f);
minHandleRect.anchorMax = new Vector2(0, 0.5f);
minHandleRect.sizeDelta = new Vector2(30, 62);
minHandleRect.anchoredPosition = new Vector3(82, 0, 0);
Image minHandleImage = minHandle.AddComponent<Image>();
minHandleImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
minHandleImage.type = Image.Type.Sliced;
minHandleImage.fillCenter = true;
RectTransform minHandleTextRect = SetAnchorsAndStretch(minHandleText);
TextMeshProUGUI minHandleTextComponent = minHandleText.AddComponent<TextMeshProUGUI>();
minHandleTextComponent.text = "0";
minHandleTextComponent.fontSize = 36;
minHandleTextRect.sizeDelta = new Vector2(70, 50);
minHandleTextRect.position = new Vector3(0, -60,0);
minHandleTextRect.anchoredPosition = new Vector3(0, 60, 0);
TextMeshProUGUI minHandleTextComponent = minHandleText.AddComponent<TextMeshProUGUI>();
minHandleTextComponent.fontSize = 36;
minHandleTextComponent.alignment = TextAlignmentOptions.Center;
RectTransform maxHandleRect = SetAnchorsAndStretch(maxHandle);
maxHandleRect.anchorMin = new Vector2(1, 0.5f);
maxHandleRect.anchorMax = new Vector2(1, 0.5f);
maxHandleRect.sizeDelta = new Vector2(30, 62);
maxHandleRect.anchoredPosition = new Vector3(-82, 0, 0);
Image maxHandleImage = maxHandle.AddComponent<Image>();
maxHandleImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
maxHandleRect.sizeDelta = new Vector2(20, 0);
maxHandleImage.type = Image.Type.Sliced;
maxHandleImage.fillCenter = true;
RectTransform maxHandleTextRect = SetAnchorsAndStretch(maxHandleText);
TextMeshProUGUI maxHandleTextComponent = maxHandleText.AddComponent<TextMeshProUGUI>();
maxHandleTextComponent.text = "0";
maxHandleTextComponent.fontSize = 36;
maxHandleTextRect.sizeDelta = new Vector2(70, 50);
maxHandleTextRect.position = new Vector3(0, -60, 0);
maxHandleTextRect.anchoredPosition = new Vector3(0, 60, 0);
TextMeshProUGUI maxHandleTextComponent = maxHandleText.AddComponent<TextMeshProUGUI>();
maxHandleTextComponent.fontSize = 36;
maxHandleTextComponent.alignment = TextAlignmentOptions.Center;
MinMaxSlider minMaxSlider = minMaxSliderRoot.AddComponent<MinMaxSlider>();
minMaxSlider.SliderBounds = sliderBoundsRect;
@ -2134,6 +2142,8 @@ namespace UnityEditor.UI
minMaxSlider.MinText = minHandleTextComponent;
minMaxSlider.MaxText = maxHandleTextComponent;
minMaxSlider.SetValues(minMaxSlider.Values.minValue, minMaxSlider.Values.maxValue);
Selection.activeGameObject = minMaxSliderRoot;
}
#endregion