From aadba190c856fea9d6d1d6f44d2bfb0edd189a9c Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Fri, 30 Dec 2016 15:44:36 +0000 Subject: [PATCH] Fixed PageChanged event for HSS/VSS Fixed WorldSpace use of HSS/VSS (also created a new feature :D) Minor editor options fix for boxslider --HG-- branch : develop_5.3 --- Editor/UIExtensionsMenuOptions.cs | 55 ++++++++++++++++++++++++++++--- Scripts/Layout/ScrollSnapBase.cs | 24 +++++++++++--- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/Editor/UIExtensionsMenuOptions.cs b/Editor/UIExtensionsMenuOptions.cs index da15245..f7d1ddf 100644 --- a/Editor/UIExtensionsMenuOptions.cs +++ b/Editor/UIExtensionsMenuOptions.cs @@ -1654,10 +1654,46 @@ namespace UnityEditor.UI Selection.activeGameObject = go; } - #endregion + #region BoxSlider + [MenuItem("GameObject/UI/Extensions/Box Slider", false)] + static public void AddBoxSlider(MenuCommand menuCommand) + { - #region Helper Functions - private static GameObject AddInputFieldAsChild(GameObject parent) + GameObject uiboxSliderRoot = CreateUIElementRoot("Box Slider", menuCommand, s_ImageGUIElementSize); + + GameObject handleSlideArea = CreateUIObject("Handle Slide Area", uiboxSliderRoot); + + GameObject handle = CreateUIObject("Handle", handleSlideArea); + + // Set RectTransform to stretch + SetAnchorsAndStretch(uiboxSliderRoot); + Image backgroundImage = uiboxSliderRoot.AddComponent(); + backgroundImage.sprite = AssetDatabase.GetBuiltinExtraResource(kBackgroundSpriteResourcePath); + backgroundImage.type = Image.Type.Sliced; + backgroundImage.fillCenter = false; + backgroundImage.color = new Color(1f, 1f, 1f, 0.392f); + + RectTransform handleRect = SetAnchorsAndStretch(handle); + handleRect.sizeDelta = new Vector2(25, 25); + Image handleImage = handle.AddComponent(); + handleImage.sprite = AssetDatabase.GetBuiltinExtraResource(kKnobPath); + handleImage.type = Image.Type.Simple; + handleImage.fillCenter = false; + handleImage.color = new Color(1f, 1f, 1f, 0.392f); + + + BoxSlider selectableArea = uiboxSliderRoot.AddComponent(); + selectableArea.HandleRect = handle.GetComponent(); + selectableArea.ValueX = selectableArea.ValueY = 0.5f; + + Selection.activeGameObject = uiboxSliderRoot; + } + #endregion + + #endregion + + #region Helper Functions + private static GameObject AddInputFieldAsChild(GameObject parent) { GameObject root = CreateUIObject("InputField", parent); @@ -1787,7 +1823,16 @@ namespace UnityEditor.UI return buttonRoot; } - #endregion + private static RectTransform SetAnchorsAndStretch(GameObject root) + { + RectTransform rectTransformRoot = root.GetComponent(); + rectTransformRoot.anchorMin = new Vector2(0.5f, 0.5f); + rectTransformRoot.anchorMax = new Vector2(0.5f, 0.5f); + rectTransformRoot.anchoredPosition = Vector2.zero; + return rectTransformRoot; + } - } + #endregion + + } } diff --git a/Scripts/Layout/ScrollSnapBase.cs b/Scripts/Layout/ScrollSnapBase.cs index 466dfa6..ea1c8a9 100644 --- a/Scripts/Layout/ScrollSnapBase.cs +++ b/Scripts/Layout/ScrollSnapBase.cs @@ -80,12 +80,16 @@ namespace UnityEngine.UI.Extensions { _previousPage = _currentPage; _currentPage = value; - ChangeBulletsInfo(_currentPage); if(MaskArea) UpdateVisible(); + ScreenChange(); + ChangeBulletsInfo(_currentPage); } } } + [Tooltip("(Experimental)\nBy default, child array objects will use the parent transform\nHowever you can disable this for some interesting effects")] + public bool UseParentTransform = true; + [Tooltip("Scroll Snap children. (optional)\nEither place objects in the scene as children OR\nPrefabs in this array, NOT BOTH")] public GameObject[] ChildObjects; @@ -156,10 +160,21 @@ namespace UnityEngine.UI.Extensions internal void InitialiseChildObjectsFromArray() { int childCount = ChildObjects.Length; + RectTransform childRect; + GameObject child; for (int i = 0; i < childCount; i++) { - ChildObjects[i] = GameObject.Instantiate(ChildObjects[i]); - ChildObjects[i].transform.SetParent(_screensContainer.transform); + child = GameObject.Instantiate(ChildObjects[i]); + //Optionally, use original GO transform when initialising, by default will use parent RectTransform position/rotation + if (UseParentTransform) + { + childRect = child.GetComponent(); + childRect.rotation = _screensContainer.rotation; + childRect.localScale = _screensContainer.localScale; + childRect.position = _screensContainer.position; + } + child.transform.SetParent(_screensContainer.transform); + ChildObjects[i] = child; if (MaskArea && ChildObjects[i].activeSelf) { ChildObjects[i].SetActive(false); @@ -306,9 +321,8 @@ namespace UnityEngine.UI.Extensions OnSelectionChangeStartEvent.Invoke(); } - internal void ScreenChange(int previousScreen) + internal void ScreenChange() { - OnSelectionPageChangedEvent.Invoke(_currentPage); }