diff --git a/Editor/UIExtensionsMenuOptions.cs b/Editor/UIExtensionsMenuOptions.cs index 01c7770..75711d6 100644 --- a/Editor/UIExtensionsMenuOptions.cs +++ b/Editor/UIExtensionsMenuOptions.cs @@ -620,7 +620,7 @@ namespace UnityEditor.UI rectTransformCenter.anchorMax = new Vector2(1f, 0.6f); rectTransformCenter.sizeDelta = Vector2.zero; - uiscr.center = uiScrollerCenter.GetComponent(); + uiscr.Center = uiScrollerCenter.GetComponent(); //Setup Content container RectTransform rectTransformContent = childContent.GetComponent(); @@ -669,10 +669,91 @@ namespace UnityEditor.UI Selection.activeGameObject = uiVerticalScrollerRoot; } - #endregion + #endregion - #region UI Button - [MenuItem("GameObject/UI/Extensions/Controls/UI Button", false)] + #region UIHorizontal Scroller + [MenuItem("GameObject/UI/Extensions/Layout/UI Horizontal Scroller", false)] + static public void AddUIHorizontalScroller(MenuCommand menuCommand) + { + GameObject uiHorizontalScrollerRoot = CreateUIElementRoot("UI Horizontal Scroller", menuCommand, s_ThickGUIElementSize); + + GameObject uiScrollerCenter = CreateUIObject("Center", uiHorizontalScrollerRoot); + + GameObject childContent = CreateUIObject("Content", uiHorizontalScrollerRoot); + + // Set RectTransform to stretch + RectTransform rectTransformScrollSnapRoot = uiHorizontalScrollerRoot.GetComponent(); + rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero; + rectTransformScrollSnapRoot.sizeDelta = new Vector2(500f, 150f); + + // Add required ScrollRect + ScrollRect sr = uiHorizontalScrollerRoot.AddComponent(); + sr.vertical = false; + sr.horizontal = true; + sr.movementType = ScrollRect.MovementType.Unrestricted; + var uiscr = uiHorizontalScrollerRoot.AddComponent(); + + //Setup container center point + RectTransform rectTransformCenter = uiScrollerCenter.GetComponent(); + rectTransformCenter.anchorMin = new Vector2(0.3f,0f); + rectTransformCenter.anchorMax = new Vector2(0.6f,1f); + rectTransformCenter.sizeDelta = Vector2.zero; + + uiscr.Center = uiScrollerCenter.GetComponent(); + + //Setup Content container + RectTransform rectTransformContent = childContent.GetComponent(); + rectTransformContent.anchorMin = Vector2.zero; + rectTransformContent.anchorMax = new Vector2(1f, 1f); + rectTransformContent.sizeDelta = Vector2.zero; + + sr.content = rectTransformContent; + + // Add sample children + for (int i = 0; i < 10; i++) + { + GameObject childPage = CreateUIObject("Page_" + i, childContent); + + GameObject childText = CreateUIObject("Text", childPage); + + //Setup 1st Child + Image pageImage = childPage.AddComponent(); + pageImage.sprite = AssetDatabase.GetBuiltinExtraResource(kStandardSpritePath); + pageImage.type = Image.Type.Sliced; + pageImage.color = s_DefaultSelectableColor; + + RectTransform rectTransformPage = childPage.GetComponent(); + rectTransformPage.anchorMin = new Vector2(0.5f, 0); + rectTransformPage.anchorMax = new Vector2(0.5f, 1f); + rectTransformPage.sizeDelta = new Vector2(80f, 0f); + rectTransformPage.pivot = new Vector2(0.5f, 0.5f); + rectTransformPage.localPosition = new Vector3(80 * i, 0, 0); + childPage.AddComponent