diff --git a/README.md b/README.md index 885f16c..4909823 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ This is an extension project for the new Unity UI system which can be found at: [Unity UI Source](https://bitbucket.org/Unity-Technologies/ui) #Updated for 5.2.1P+/5.3 - new asset package# +#For Unity 5.2.2 - Use the new 5.3 package!# ##Intro## For more info, here's a little introduction video for the project: diff --git a/Scripts/BoundTooltip/BoundTooltipTrigger.cs b/Scripts/BoundTooltip/BoundTooltipTrigger.cs index 9776722..415d70e 100644 --- a/Scripts/BoundTooltip/BoundTooltipTrigger.cs +++ b/Scripts/BoundTooltip/BoundTooltipTrigger.cs @@ -1,39 +1,54 @@ -///Credit Martin Nerurkar // www.martin.nerurkar.de // www.sharkbombs.com -///Sourced from - http://www.sharkbombs.com/2015/02/10/tooltips-with-the-new-unity-ui-ugui/ - -using UnityEngine.EventSystems; - -namespace UnityEngine.UI.Extensions -{ - [AddComponentMenu("UI/Extensions/Bound Tooltip/Tooltip Trigger")] - public class BoundTooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler - { - public string text; - - public void OnPointerEnter(PointerEventData eventData) - { - StartHover(new Vector3(eventData.position.x, eventData.position.y, 0f)); - } - public void OnSelect(BaseEventData eventData) - { - StartHover(transform.position); - } - public void OnPointerExit(PointerEventData eventData) - { - StopHover(); - } - public void OnDeselect(BaseEventData eventData) - { - StopHover(); - } - - void StartHover(Vector3 position) - { - BoundTooltipItem.Instance.ShowTooltip(text, position); - } - void StopHover() - { - BoundTooltipItem.Instance.HideTooltip(); - } - } -} +///Credit Martin Nerurkar // www.martin.nerurkar.de // www.sharkbombs.com +///Sourced from - http://www.sharkbombs.com/2015/02/10/tooltips-with-the-new-unity-ui-ugui/ +using UnityEngine.EventSystems; + +namespace UnityEngine.UI.Extensions +{ + [AddComponentMenu("UI/Extensions/Bound Tooltip/Tooltip Trigger")] + public class BoundTooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler + { + [TextAreaAttribute] + public string text; + + public bool useMousePosition = false; + + public Vector3 offset; + + public void OnPointerEnter(PointerEventData eventData) + { + if (useMousePosition) + { + StartHover(new Vector3(eventData.position.x, eventData.position.y, 0f)); + } + else + { + StartHover(transform.position + offset); + } + } + + public void OnSelect(BaseEventData eventData) + { + StartHover(transform.position); + } + + public void OnPointerExit(PointerEventData eventData) + { + StopHover(); + } + + public void OnDeselect(BaseEventData eventData) + { + StopHover(); + } + + void StartHover(Vector3 position) + { + BoundTooltipItem.Instance.ShowTooltip(text, position); + } + + void StopHover() + { + BoundTooltipItem.Instance.HideTooltip(); + } + } +} diff --git a/Scripts/Layout/ScrollSnap.cs b/Scripts/Layout/ScrollSnap.cs index 849f521..0b311fb 100644 --- a/Scripts/Layout/ScrollSnap.cs +++ b/Scripts/Layout/ScrollSnap.cs @@ -9,23 +9,23 @@ /// if you dont wish to use this auto resize turn of autoLayoutItems /// - fixed current page made it independant from pivot /// - replaced pagination with delegate function - using System; using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { [ExecuteInEditMode] - [RequireComponent(typeof(ScrollRect))] - [AddComponentMenu("UI/Extensions/Scroll Snap")] - public class ScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler + [RequireComponent(typeof(ScrollRect))] + [AddComponentMenu("UI/Extensions/Scroll Snap")] + public class ScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler { // needed becouse of reversed behavior of axis Y compared to X // (positions of children lower in children list in horizontal directions grows when in vertical it gets smaller) - public enum ScrollDirection { + public enum ScrollDirection + { Horizontal, Vertical - }; + } public delegate void PageSnapChange(int page); @@ -34,11 +34,12 @@ namespace UnityEngine.UI.Extensions public ScrollDirection direction = ScrollDirection.Horizontal; protected ScrollRect scrollRect; - protected RectTransform scrollRectTransform; - protected Transform listContainerTransform; - protected RectTransform rectTransform; - protected int items = 0; + protected RectTransform scrollRectTransform; + + protected Transform listContainerTransform; + + protected RectTransform rectTransform; int pages; @@ -46,22 +47,31 @@ namespace UnityEngine.UI.Extensions // anchor points to lerp to to see child on certain indexes protected Vector3[] pageAnchorPositions; + protected Vector3 lerpTarget; + protected bool lerp; // item list related protected float listContainerMinPosition; + protected float listContainerMaxPosition; + protected float listContainerSize; + protected RectTransform listContainerRectTransform; + protected Vector2 listContainerCachedSize; protected float itemSize; + + protected int itemsCount = 0; - [Tooltip("Button to go to the next page. (optional)")] - public GameObject nextButton; - [Tooltip("Button to go to the previous page. (optional)")] - public GameObject prevButton; + [Tooltip("Button to go to the next page. (optional)")] + public Button nextButton; + + [Tooltip("Button to go to the previous page. (optional)")] + public Button prevButton; [Tooltip("Number of items visible in one page of scroll frame.")] [RangeAttribute(1,100)] @@ -72,74 +82,97 @@ namespace UnityEngine.UI.Extensions [Tooltip("If you wish to update scrollbar numberOfSteps to number of active children on list.")] public bool linkScrolbarSteps = false; + + [Tooltip("If you wish to update scrollrect sensitivity to size of list element.")] + public bool linkScrolrectScrollSensitivity = false; - public Boolean useFastSwipe = true; - public int fastSwipeThreshold = 100; + public Boolean useFastSwipe = true; + + public int fastSwipeThreshold = 100; // drag related protected bool startDrag = true; + protected Vector3 positionOnDragStart = new Vector3(); + protected int pageOnDragStart; protected bool fastSwipeTimer = false; + protected int fastSwipeCounter = 0; + protected int fastSwipeTarget = 10; - // Use this for initialization - void Start() + // Use this for initialization + void Awake() { lerp = false; - scrollRect = gameObject.GetComponent (); - scrollRectTransform = gameObject.GetComponent (); + scrollRect = gameObject.GetComponent(); + scrollRectTransform = gameObject.GetComponent(); listContainerTransform = scrollRect.content; - listContainerRectTransform = listContainerTransform.GetComponent (); + listContainerRectTransform = listContainerTransform.GetComponent(); - rectTransform = listContainerTransform.gameObject.GetComponent (); + rectTransform = listContainerTransform.gameObject.GetComponent(); UpdateListItemsSize(); UpdateListItemPositions(); - ChangePage (CurrentPage ()); + PageChanged(CurrentPage()); if (nextButton) { - nextButton.GetComponent