From f72eb7268fa7fcbd59b73f07226e5f8b8e00fe92 Mon Sep 17 00:00:00 2001 From: "Simon (darkside) Jackson" Date: Wed, 23 Dec 2015 14:54:32 +0000 Subject: [PATCH] Added initial version of the UI Vertical scroller from Mrs. YakaYocha Complete with component and editor menu options --HG-- branch : develop_5.3 --- Scripts/Editor/UIExtensionsMenuOptions.cs | 81 ++++++ Scripts/Layout/UIVerticalScroller.cs | 188 ++++++++++++++ Scripts/Layout/UIVerticalScroller.cs.meta | 12 + Scripts/Layout/UIVerticalScrollerDemo.meta | 9 + .../UIVerticalScrollerDemo/Prefabs.meta | 9 + .../Prefabs/DaysVertical.prefab | Bin 0 -> 15108 bytes .../Prefabs/DaysVertical.prefab.meta | 8 + .../Prefabs/MonthsVertical.prefab | Bin 0 -> 15116 bytes .../Prefabs/MonthsVertical.prefab.meta | 8 + .../Prefabs/YearsVertical.prefab | Bin 0 -> 15116 bytes .../Prefabs/YearsVertical.prefab.meta | 8 + .../Layout/UIVerticalScrollerDemo/Scenes.meta | 9 + .../Scenes/VerticalCalendar.unity | Bin 0 -> 73504 bytes .../Scenes/VerticalCalendar.unity.meta | 8 + .../UIVerticalScrollerDemo/Scripts.meta | 9 + .../Scripts/ScrollingCalendar.cs | 231 ++++++++++++++++++ .../Scripts/ScrollingCalendar.cs.meta | 12 + .../UIVerticalScrollerDemo/Sprites.meta | 9 + .../Sprites/MrsYakaYochaMedium.png | Bin 0 -> 30152 bytes .../Sprites/MrsYakaYochaMedium.png.meta | 56 +++++ 20 files changed, 657 insertions(+) create mode 100644 Scripts/Layout/UIVerticalScroller.cs create mode 100644 Scripts/Layout/UIVerticalScroller.cs.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Prefabs.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Prefabs/DaysVertical.prefab create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Prefabs/DaysVertical.prefab.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Prefabs/MonthsVertical.prefab create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Prefabs/MonthsVertical.prefab.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Prefabs/YearsVertical.prefab create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Prefabs/YearsVertical.prefab.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Scenes.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Scenes/VerticalCalendar.unity create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Scenes/VerticalCalendar.unity.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Scripts.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Scripts/ScrollingCalendar.cs create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Scripts/ScrollingCalendar.cs.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Sprites.meta create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Sprites/MrsYakaYochaMedium.png create mode 100644 Scripts/Layout/UIVerticalScrollerDemo/Sprites/MrsYakaYochaMedium.png.meta diff --git a/Scripts/Editor/UIExtensionsMenuOptions.cs b/Scripts/Editor/UIExtensionsMenuOptions.cs index cbebdb5..eef2dd1 100644 --- a/Scripts/Editor/UIExtensionsMenuOptions.cs +++ b/Scripts/Editor/UIExtensionsMenuOptions.cs @@ -470,6 +470,87 @@ namespace UnityEditor.UI #endregion + #region UIVertical Scroller + [MenuItem("GameObject/UI/Extensions/UI Vertical Scroller", false)] + static public void AddUIVerticallScroller(MenuCommand menuCommand) + { + GameObject uiVerticalScrollerRoot = CreateUIElementRoot("UI Vertical Scroller", menuCommand, s_ThickGUIElementSize); + + GameObject uiScrollerCenter = CreateUIObject("Center", uiVerticalScrollerRoot); + + GameObject childContent = CreateUIObject("Content", uiVerticalScrollerRoot); + + // Set RectTransform to stretch + RectTransform rectTransformScrollSnapRoot = uiVerticalScrollerRoot.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 = uiVerticalScrollerRoot.AddComponent(); + sr.vertical = true; + sr.horizontal = false; + sr.movementType = ScrollRect.MovementType.Unrestricted; + var uiscr = uiVerticalScrollerRoot.AddComponent(); + + //Setup container center point + RectTransform rectTransformCenter = uiScrollerCenter.GetComponent(); + rectTransformCenter.anchorMin = new Vector2(0f, 0.3f); + rectTransformCenter.anchorMax = new Vector2(1f, 0.6f); + 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(0f, 0.5f); + rectTransformPage.anchorMax = new Vector2(1f, 0.5f); + rectTransformPage.sizeDelta = new Vector2(0f, 80f); + rectTransformPage.pivot = new Vector2(0.5f, 0.5f); + rectTransformPage.localPosition = new Vector3(0, 80 * i, 0); + childPage.AddComponent