Added new control template (editor menu only) - progress bar

--HG--
branch : develop
pull/413/head
Simon (darkside) Jackson 2015-02-11 20:55:13 +00:00
parent 6902d8dc64
commit e648e09beb
1 changed files with 47 additions and 1 deletions

View File

@ -24,7 +24,7 @@ namespace UnityEditor.UI
private const string kCheckmarkPath = "UI/Skin/Checkmark.psd";
private static Vector2 s_ThickGUIElementSize = new Vector2(kWidth, kThickHeight);
//private static Vector2 s_ThinGUIElementSize = new Vector2(kWidth, kThinHeight);
private static Vector2 s_ThinGUIElementSize = new Vector2(kWidth, kThinHeight);
private static Vector2 s_ImageGUIElementSize = new Vector2(100f, 100f);
private static Color s_DefaultSelectableColor = new Color(1f, 1f, 1f, 1f);
private static Color s_TextColor = new Color(50f / 255f, 50f / 255f, 50f / 255f, 1f);
@ -747,6 +747,52 @@ namespace UnityEditor.UI
}
}
[MenuItem("GameObject/UI/Extensions/Progress Bar", false)]
static public void AddSlider(MenuCommand menuCommand)
{
// Create GOs Hierarchy
GameObject root = CreateUIElementRoot("Progress Bar", menuCommand, s_ThinGUIElementSize);
GameObject background = CreateUIObject("Background", root);
GameObject fillArea = CreateUIObject("Fill Area", root);
GameObject fill = CreateUIObject("Fill", fillArea);
// Background
Image backgroundImage = background.AddComponent<Image>();
backgroundImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kBackgroundSpriteResourcePath);
backgroundImage.type = Image.Type.Sliced;
backgroundImage.color = s_DefaultSelectableColor;
RectTransform backgroundRect = background.GetComponent<RectTransform>();
backgroundRect.anchorMin = new Vector2(0, 0.25f);
backgroundRect.anchorMax = new Vector2(1, 0.75f);
backgroundRect.sizeDelta = new Vector2(0, 0);
// Fill Area
RectTransform fillAreaRect = fillArea.GetComponent<RectTransform>();
fillAreaRect.anchorMin = new Vector2(0, 0.25f);
fillAreaRect.anchorMax = new Vector2(1, 0.75f);
fillAreaRect.anchoredPosition = Vector2.zero;
fillAreaRect.sizeDelta = Vector2.zero;
// Fill
Image fillImage = fill.AddComponent<Image>();
fillImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
fillImage.type = Image.Type.Sliced;
fillImage.color = s_DefaultSelectableColor;
RectTransform fillRect = fill.GetComponent<RectTransform>();
fillRect.sizeDelta = Vector2.zero;
// Setup slider component
Slider slider = root.AddComponent<Slider>();
slider.value = 0;
slider.fillRect = fill.GetComponent<RectTransform>();
slider.targetGraphic = fillImage;
slider.direction = Slider.Direction.LeftToRight;
SetDefaultColorTransitionValues(slider);
}
#endregion
#region Helper Functions