Search Unity

[Scripts] Useful 4.6 Scripts Collection

Discussion in 'UGUI & TextMesh Pro' started by Melang, Aug 24, 2014.

  1. sabid_akhan

    sabid_akhan

    Joined:
    Oct 2, 2015
    Posts:
    1
    I am using unity personal 5.2.2f and i imported the package but i dont see UI extension as there are some errors on the console. Please let me know how to fix this.
     

    Attached Files:

  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    What patch release are you using? Generally we don't support patch releases with the UI Extensions as the asset store is also unable to support patch releases.

    The reason it's not showing up is because there are compile errors. We did get one report with 5.2.2p3 that there might be an issue, likely due to another API change. However, we're informed that all fixes should be patched in 5.3 before being included in 5.2.2 patches, however the project still works fine in the latest 5.3 beta.

    Will try and test and then update the homepage.
     
  3. DarkMath

    DarkMath

    Joined:
    Dec 9, 2009
    Posts:
    25
    Simon,
    Is there anyway you could add a menu control like the Radial Menu but instead of circle have the items in a horizontal or vertical layout?
    It would be like say the Start button on Windows where you click it and a menu is opened. Unlike the Start button this new menu would animate itself opening. And then after a selection it would animate itself closing.
    Thanks
    DarkMath
     
    GibTreaty likes this.
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Hi @DarkMath Just raise a request in the BitBucket site as a proposal and either I or one of the community will jump in.

    However, check out the Flyout Menu control which does what you are asking for I believe.
     
  5. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Looks interesting @idurvesh do you have a link to an article that explains the use of that script?
     
  7. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
  8. DevMan5000

    DevMan5000

    Joined:
    Jun 13, 2014
    Posts:
    14
    Hello all,

    This is ScrollSnapController which which is a rewrite of ScrollSnap.cs. So, you swipe or hit next and it scrolls to the next item and stops.

    Thank you to the authors of ScrollSnap, it was a great jumping off point for me.

    To Use:
    Apply it to a horizontal scroll view that also contains unity ui extension component ScrollRectTweener and you are good to go.

    Basically, I pared ScrollSnap down to the bare essentials. Here is what it does now:
    - Determines if fast swipe was performed
    - Figures out what item is closest to center
    - Calls functions to jump to prev and next items
    - Leverages ScrollRectTweener to do some heavy lifting (sliding of content panel).
    - Sends an event once scroll is complete

    Advantages over ScrollSnap:
    - Way less code
    - Way more comments
    - A lot easier to understand because I've consolidated a lot of stuff.
    - Handles content panels with horizontal layouts that contain padding (this was what prompted me to do a rewrite).
    - The lerp code in ScrollSnap didn't stop directly on items. It would scroll past the item, then come back. By having ScrollRectTweener do the scrolling, it stops right on the item.
    - ScrollSnap seemed to fire off events a ton of onPageChange events. My code only fires the event once after scroll is complete.
    - Fast swipe and button triggers were handled separately in ScrollSnap, in my code its the same function.

    Disadvantages to ScrollSnap:
    - Only handles horizontal scrolling
    - I think my code makes assumptions about anchors and pivot points. E.g. Items in list must have pivot at object's center and the left anchors and pivot for the content panel must be on the left edge.
    - Isn't as smart about items being added / removed (although my code might handle it just fine, not sure).
    - Doesn't have "itemsVisibleAtOnce", which I guess grouped several pages into one swipe (I don't know that was confusing). My code doesn't preclude multiple items from being seen at once.

    Caveats:
    - I made one modification to ScrollRectTweener so that it would send me an event when scrolling was done.

    I'm sure there are a few more quirks. Anyways, I just wanted to give back a bit. Thanks!

    Code (CSharp):
    1. using System;
    2. using UnityEngine.EventSystems;
    3. using UnityEngine.UI;
    4. using UnityEngine;
    5. using System.Collections;
    6. using System.Collections.Generic;
    7. using UnityEngine.UI.Extensions;
    8.  
    9. /// <summary>
    10. /// Allows scroll view to snap to items after user releases during scrolling.
    11. /// Provides the following
    12. /// - Lerping to be centered on an item after release
    13. /// - Functions to go back and forward
    14. /// - Event when focused item has changed
    15. /// </summary>
    16. [ExecuteInEditMode]
    17. [RequireComponent(typeof(ScrollRect))]
    18. [RequireComponent(typeof(ScrollRectTweener))]
    19. [AddComponentMenu("UI/Scroll View Controller")]
    20. public class ScrollSnapController : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler
    21. {
    22.     public delegate void ItemSnapChange(int itemIdx);
    23.     public event ItemSnapChange OnSnappedToItem;
    24.  
    25.     protected ScrollRect m_ScrollRect;
    26.     protected RectTransform m_ScrollViewRectTransform;
    27.     protected ScrollRectTweener m_ScrollRectTweener;
    28.     protected Transform m_ContentPanelTransform;
    29.     protected RectTransform m_ContentPanelRectTransform;
    30.     protected float m_ContentPanelMaxPosition;
    31.  
    32.     [Tooltip("Button to go to the next page. (optional)")]
    33.     public Button m_NextButton;
    34.  
    35.     [Tooltip("Button to go to the previous page. (optional)")]
    36.     public Button m_PrevButton;
    37.  
    38.     // Fast Swipe vars
    39.     public Boolean m_UseFastSwipe = true;
    40.     public int m_FastSwipeThreshold = 100;
    41.     protected bool m_TrackFastSwipeOnUpdate = false;
    42.     protected float m_SwipeTimer = 0.0f;
    43.     protected float m_FastSwipeMaxTime = 0.333f;
    44.  
    45.     // Drag related
    46.     protected bool m_bDragging = false;
    47.     protected Vector3 m_DragStartPosition = new Vector3();
    48.     protected int m_ItemIdxOnDragStart;
    49.  
    50.     void Awake()
    51.     {
    52.         m_ScrollRect = gameObject.GetComponent<ScrollRect>();
    53.         m_ScrollViewRectTransform = gameObject.GetComponent<RectTransform>();
    54.         m_ScrollRectTweener = GetComponent<ScrollRectTweener>();
    55.  
    56.         m_ScrollRectTweener.OnScrollComplete += HandleScrollComplete;
    57.  
    58.         m_ContentPanelTransform = m_ScrollRect.content;
    59.         m_ContentPanelRectTransform = m_ContentPanelTransform.GetComponent<RectTransform>();
    60.  
    61.         // NOTE: Since going forward in the list means that the content panel is moving left
    62.         // and thus more negative, the max position will actually be when scroll rect is at normalized 0.
    63.         // WARNING: setting the max position as we do below assumes that the left anchor is on the left edge
    64.         // and the pivot is on the left edge also (still a littly fuzzy on relationship of those things).
    65.         m_ScrollRect.horizontalNormalizedPosition = 0;
    66.         m_ContentPanelMaxPosition = m_ContentPanelTransform.localPosition.x;
    67.  
    68.         if(m_ContentPanelTransform.childCount > 0)
    69.         {
    70.             ScrollToItem(0);
    71.         }
    72.  
    73.         if (m_NextButton)
    74.         {
    75.             m_NextButton.GetComponent<Button>().onClick.AddListener(() =>
    76.             {
    77.                 SnapToNextItem();
    78.             });
    79.         }
    80.  
    81.         if (m_PrevButton)
    82.         {
    83.             m_PrevButton.GetComponent<Button>().onClick.AddListener(() =>
    84.             {
    85.                 SnapToPreviousItem();
    86.             });
    87.         }
    88.     }
    89.  
    90.     void Start()
    91.     {
    92.         Awake();
    93.     }
    94.  
    95.     // Function for switching screens with buttons
    96.     public void SnapToNextItem(bool bTriggeredByFastSwipe = false)
    97.     {
    98.         int itemIdx = -1;
    99.         if(bTriggeredByFastSwipe)
    100.         {
    101.             itemIdx = m_ItemIdxOnDragStart;
    102.         }
    103.         else
    104.         {
    105.             itemIdx = ClosestToCenterItemIdx;
    106.         }
    107.  
    108.         if (itemIdx < m_ContentPanelTransform.childCount - 1)
    109.         {
    110.             ScrollToItem(itemIdx + 1);
    111.         }
    112.     }
    113.  
    114.     // Function for switching screens with buttons
    115.     public void SnapToPreviousItem(bool bTriggeredByFastSwipe = false)
    116.     {
    117.         int itemIdx = -1;
    118.         if (bTriggeredByFastSwipe)
    119.         {
    120.             itemIdx = m_ItemIdxOnDragStart;
    121.         }
    122.         else
    123.         {
    124.             itemIdx = ClosestToCenterItemIdx;
    125.         }
    126.  
    127.         if (itemIdx > 0)
    128.         {
    129.             ScrollToItem(itemIdx - 1);
    130.         }
    131.     }
    132.  
    133.     void ScrollToItem(int idx)
    134.     {
    135.         Transform childTransform = m_ContentPanelTransform.GetChild(idx);
    136.         RectTransform rectTransform = childTransform.gameObject.GetComponent<RectTransform>();
    137.  
    138.         // The desiredContainerPos is the position at which the item we want is centered within the ScrollView.
    139.         // If container was placed at (-1 * rectTransform.anchoredPosition.x), then the item would be on the left
    140.         // edge of the scrollView. We add scrollViewWidth / 2 to get the item in the center of the ScrollView.
    141.         float scrollViewWidth = m_ScrollViewRectTransform.rect.width;
    142.         float desiredContainerPos = (-1 * rectTransform.anchoredPosition.x) + (scrollViewWidth / 2);
    143.  
    144.         // Figure out the min container positions. Counter-intuitive, but since the scroll list
    145.         // moves left as you scroll forward through the pages, this means the max container position will be 0.
    146.         // The min container position, attained when list is scroll at 100%, will be the container rect width times -1
    147.         // plus the scrollViewWidth so that the container doesn't move too far left.
    148.         float minContainerPos = (-1 * m_ContentPanelRectTransform.rect.width) + scrollViewWidth;
    149.  
    150.         // The scroll tween script takes a normalized value so get the position as a percentage.
    151.         // NOTE: Again, this is somewhat counter intuitive since the container's x is getting more negative as you
    152.         // move forward through the list. minContainerPos is actually the MOST negative the container can go so
    153.         // we get a percentage off that.
    154.         float percent = desiredContainerPos / minContainerPos;
    155.  
    156.         m_ScrollRectTweener.ScrollHorizontal(percent);
    157.  
    158.         // Update prev/next button interactability
    159.         if (m_NextButton)
    160.         {
    161.             m_NextButton.interactable = idx < m_ContentPanelTransform.childCount - 1;
    162.         }
    163.  
    164.         if (m_PrevButton)
    165.         {
    166.             m_PrevButton.interactable = idx > 0;
    167.         }
    168.     }
    169.  
    170.     /// <summary>
    171.     /// Called after a scroll has completed. Broadcasts OnSnappedToItem event.
    172.     /// </summary>
    173.     public void HandleScrollComplete()
    174.     {
    175.         // Broadcasts the OnSnappedToItem event.
    176.         if (OnSnappedToItem != null)
    177.         {
    178.             // Now that the list has snapped, send out the centered on item.
    179.             OnSnappedToItem(ClosestToCenterItemIdx);
    180.         }
    181.     }
    182.  
    183.     /// <summary>
    184.     ///  Returns the index of the item that is currently centered (or closest to center) in the scroll view.
    185.     /// </summary>
    186.     /// <returns></returns>
    187.     private int ClosestToCenterItemIdx
    188.     {
    189.         get
    190.         {
    191.             // Figure out which child object's position is closest to the scroll view's center.
    192.             // WARNING: Math here assumes content panel has anchors on left side.
    193.             float scrollViewWidth = m_ScrollViewRectTransform.rect.width;
    194.             float localScrollViewCenterPos = m_ContentPanelMaxPosition - m_ContentPanelTransform.localPosition.x + (scrollViewWidth / 2);
    195.             float minDist = Mathf.Infinity;
    196.             int minIdx = 0;
    197.             for (int i = 0; i < m_ContentPanelTransform.childCount; i++)
    198.             {
    199.                 Transform childTransform = m_ContentPanelTransform.GetChild(i);
    200.                 RectTransform rectTransform = childTransform.gameObject.GetComponent<RectTransform>();
    201.  
    202.                 float dist = Mathf.Abs(localScrollViewCenterPos - rectTransform.anchoredPosition.x);
    203.                 if (dist < minDist)
    204.                 {
    205.                     minDist = dist;
    206.                     minIdx = i;
    207.                 }
    208.             }
    209.  
    210.             return minIdx;
    211.         }
    212.     }
    213.  
    214.     /// <summary>
    215.     /// Returns the current item. This is useful for client code to get at and alter the current object.
    216.     /// NOTES: uses transform.GetChild(idx). If items were added in a weird order, then another method must be used.
    217.     /// </summary>
    218.     /// <returns></returns>
    219.     public GameObject GetCurrentItem()
    220.     {
    221.         int idx = ClosestToCenterItemIdx;
    222.  
    223.         GameObject curItem = m_ContentPanelTransform.GetChild(idx).gameObject;
    224.  
    225.         return curItem;
    226.     }
    227.  
    228.     // Wrapper so outside calling code doesn't have ClosestToCenterItemIdx which could really be confusing.
    229.     public int CurrentItemIdx
    230.     {
    231.         get
    232.         {
    233.             return ClosestToCenterItemIdx;
    234.         }
    235.     }
    236.  
    237.     void LateUpdate()
    238.     {
    239.         if (m_TrackFastSwipeOnUpdate)
    240.         {
    241.             m_SwipeTimer += Time.deltaTime;
    242.         }
    243.     }
    244.  
    245.     public void OnBeginDrag(PointerEventData eventData)
    246.     {
    247.         m_SwipeTimer = 0.0f;
    248.         m_TrackFastSwipeOnUpdate = true;
    249.  
    250.         m_DragStartPosition = eventData.position;
    251.         m_ItemIdxOnDragStart = ClosestToCenterItemIdx;
    252.     }
    253.  
    254.     public void OnDrag(PointerEventData eventData)
    255.     {
    256.         if (!m_bDragging)
    257.         {
    258.             OnBeginDrag(eventData);
    259.             m_bDragging = true;
    260.         }
    261.     }
    262.  
    263.     public void OnEndDrag(PointerEventData eventData)
    264.     {
    265.         m_bDragging = false;
    266.         m_TrackFastSwipeOnUpdate = false;
    267.  
    268.         float positionDelta = m_DragStartPosition.x - eventData.position.x;
    269.  
    270.         bool bFastSwipePerformed = false;
    271.         if (m_UseFastSwipe)
    272.         {
    273.             // If the user did a drag start and release within the time window specified by m_FastSwipeMaxTime,
    274.             // and the position change in that time was greater than the threshold, then a fast swipe was performed.
    275.             if (m_SwipeTimer <= m_FastSwipeMaxTime && (Math.Abs(positionDelta) > m_FastSwipeThreshold))
    276.             {
    277.                 if (positionDelta > 0)
    278.                 {
    279.                     SnapToNextItem(true);
    280.                 }
    281.                 else
    282.                 {
    283.                     SnapToPreviousItem(true);
    284.                 }
    285.  
    286.                 bFastSwipePerformed = true;
    287.             }
    288.         }
    289.  
    290.         // If we are not checking for fast swipe or if we are and one was not performed, then
    291.         // scroll to the object corresponding to CurrentItemIdx, which is object closest to scroll view center.
    292.         if(!bFastSwipePerformed)
    293.         {
    294.             ScrollToItem(ClosestToCenterItemIdx);
    295.         }
    296.     }
    297. }
    298.  
     
  9. dis-s

    dis-s

    Joined:
    Mar 25, 2013
    Posts:
    48
    Hi!
    DevMan5000, thanks for sharing the code. Can you provide also your modified code of ScrollRectTweener?
     
  10. zero3growlithe

    zero3growlithe

    Joined:
    Jul 7, 2012
    Posts:
    15
    Hello,

    I've updated my UIScrollToSelection script on request with new options that allow automatic scrolling in Vertical and Horizontal lists or supports both in case you want a to create a grid.
    I also optimized and refactored it for mobile usage.

    http://pastebin.com/gAAp7PNL

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine.UI;
    5. using UnityEngine.EventSystems;
    6.  
    7. public class UIScrollToSelection : MonoBehaviour {
    8.  
    9. //*** ATTRIBUTES ***//
    10.     [Header("[ Settings ]")]
    11.     [SerializeField]
    12.     private ScrollType scrollDirection;
    13.     [SerializeField]
    14.     private float scrollSpeed = 10f;
    15.  
    16.     [Header("[ Input ]")]
    17.     [SerializeField]
    18.     private bool cancelScrollOnInput = false;
    19.     [SerializeField]
    20.     private List<KeyCode> cancelScrollKeycodes = new List<KeyCode>();
    21.  
    22. //*** PROPERTIES ***//
    23.     // REFERENCES
    24.     protected RectTransform LayoutListGroup {
    25.         get {return TargetScrollRect != null ? TargetScrollRect.content : null;}
    26.     }
    27.  
    28.     // SETTINGS
    29.     protected ScrollType ScrollDirection {
    30.         get {return scrollDirection;}
    31.     }
    32.     protected float ScrollSpeed {
    33.         get {return scrollSpeed;}
    34.     }
    35.  
    36.     // INPUT
    37.     protected bool CancelScrollOnInput {
    38.         get {return cancelScrollOnInput;}
    39.     }
    40.     protected List<KeyCode> CancelScrollKeycodes {
    41.         get {return cancelScrollKeycodes;}
    42.     }
    43.  
    44.     // CACHED REFERENCES
    45.     protected RectTransform ScrollWindow {get; set;}
    46.     protected ScrollRect TargetScrollRect {get; set;}
    47.  
    48.     // SCROLLING
    49.     protected EventSystem CurrentEventSystem {
    50.         get {return EventSystem.current;}
    51.     }
    52.     protected GameObject LastCheckedGameObject {get; set;}
    53.     protected GameObject CurrentSelectedGameObject {
    54.         get {return EventSystem.current.currentSelectedGameObject;}
    55.     }
    56.     protected RectTransform CurrentTargetRectTransform {get; set;}
    57.     protected bool IsManualScrollingAvailable {get; set;}
    58.  
    59. //*** METHODS - PUBLIC ***//
    60.  
    61.  
    62. //*** METHODS - PROTECTED ***//
    63.     protected virtual void Awake (){
    64.         TargetScrollRect = GetComponent<ScrollRect>();
    65.         ScrollWindow = TargetScrollRect.GetComponent<RectTransform>();
    66.     }
    67.  
    68.     protected virtual void Start (){
    69.  
    70.     }
    71.  
    72.     protected virtual void Update (){
    73.         UpdateReferences();
    74.         CheckIfScrollingShouldBeLocked();
    75.         ScrollRectToLevelSelection();
    76.     }
    77.  
    78. //*** METHODS - PRIVATE ***//
    79.     private void UpdateReferences (){
    80.         // update current selected rect transform
    81.         if (CurrentSelectedGameObject != LastCheckedGameObject){
    82.             CurrentTargetRectTransform = (CurrentSelectedGameObject != null) ?
    83.                 CurrentSelectedGameObject.GetComponent<RectTransform>() :
    84.                 null;
    85.  
    86.             // unlock automatic scrolling
    87.             if (CurrentSelectedGameObject != null &&
    88.                 CurrentSelectedGameObject.transform.parent == LayoutListGroup.transform)
    89.             {
    90.                 IsManualScrollingAvailable = false;
    91.             }
    92.         }
    93.  
    94.         LastCheckedGameObject = CurrentSelectedGameObject;
    95.     }
    96.  
    97.     private void CheckIfScrollingShouldBeLocked (){
    98.         if (CancelScrollOnInput == false || IsManualScrollingAvailable == true){
    99.             return;
    100.         }
    101.  
    102.         for (int i = 0; i < CancelScrollKeycodes.Count; i++){
    103.             if (Input.GetKeyDown(CancelScrollKeycodes[i]) == true){
    104.                 IsManualScrollingAvailable = true;
    105.  
    106.                 break;
    107.             }
    108.         }
    109.     }
    110.  
    111.     private void ScrollRectToLevelSelection (){
    112.         // check main references
    113.         bool referencesAreIncorrect = (TargetScrollRect == null || LayoutListGroup == null || ScrollWindow == null);
    114.  
    115.         if (referencesAreIncorrect == true || IsManualScrollingAvailable == true){
    116.             return;
    117.         }
    118.  
    119.         RectTransform selection = CurrentTargetRectTransform;
    120.  
    121.         // check if scrolling is possible
    122.         if (selection == null || selection.transform.parent != LayoutListGroup.transform){
    123.             return;
    124.         }
    125.  
    126.         // depending on selected scroll direction move the scroll rect to selection
    127.         switch (ScrollDirection){
    128.             case ScrollType.VERTICAL:
    129.                 UpdateVerticalScrollPosition(selection);
    130.                 break;
    131.             case ScrollType.HORIZONTAL:
    132.                 UpdateHorizontalScrollPosition(selection);
    133.                 break;
    134.             case ScrollType.BOTH:
    135.                 UpdateVerticalScrollPosition(selection);
    136.                 UpdateHorizontalScrollPosition(selection);
    137.                 break;
    138.         }
    139.     }
    140.  
    141.     private void UpdateVerticalScrollPosition (RectTransform selection){
    142.         // move the current scroll rect to correct position
    143.         float selectionPosition = -selection.anchoredPosition.y;
    144.  
    145.         float elementHeight = selection.rect.height;
    146.         float maskHeight = ScrollWindow.rect.height;
    147.         float listAnchorPosition = LayoutListGroup.anchoredPosition.y;
    148.  
    149.         // get the element offset value depending on the cursor move direction
    150.         float offlimitsValue = GetScrollOffset(selectionPosition, listAnchorPosition, elementHeight, maskHeight);
    151.  
    152.         // move the target scroll rect
    153.         TargetScrollRect.verticalNormalizedPosition +=
    154.             (offlimitsValue / LayoutListGroup.rect.height) * Time.deltaTime * scrollSpeed;
    155.     }
    156.  
    157.     private void UpdateHorizontalScrollPosition (RectTransform selection){
    158.         // move the current scroll rect to correct position
    159.         float selectionPosition = selection.anchoredPosition.x;
    160.  
    161.         float elementWidth = selection.rect.width;
    162.         float maskWidth = ScrollWindow.rect.width;
    163.         float listAnchorPosition = -LayoutListGroup.anchoredPosition.x;
    164.  
    165.         // get the element offset value depending on the cursor move direction
    166.         float offlimitsValue = -GetScrollOffset(selectionPosition, listAnchorPosition, elementWidth, maskWidth);
    167.  
    168.         // move the target scroll rect
    169.         TargetScrollRect.horizontalNormalizedPosition +=
    170.             (offlimitsValue / LayoutListGroup.rect.width) * Time.deltaTime * scrollSpeed;
    171.     }
    172.  
    173.     private float GetScrollOffset (float position, float listAnchorPosition, float targetLength, float maskLength){
    174.         if (position < listAnchorPosition){
    175.             return listAnchorPosition - position;
    176.         } else if (position + targetLength > listAnchorPosition + maskLength){
    177.             return (listAnchorPosition + maskLength) - (position + targetLength);
    178.         }
    179.  
    180.         return 0;
    181.     }
    182.  
    183. //*** ENUMS ***//
    184.     public enum ScrollType {
    185.         VERTICAL,
    186.         HORIZONTAL,
    187.         BOTH
    188.     }
    189. }
    Usage:
    Put the script onto an ScrollRect object. With the script on, any selection made inside of the ScrollRect will cause the ScrollRect to move in that direction so the highlighted element is visible (but it does not center it).

    Available settings:
    - Scroll direction [VERTICAL, HORIZONTAL, BOTH]
    - Scroll speed [float]

    - Cancel scroll on input [bool]
    - (active if above is turned on) Cancel scroll KeyCodes [List, KeyCode] (if any of the keys in the list i. e. Mouse Button is pressed down the script will unlock manual scrolling so player can also scroll the grid/list using finger/mouse)

    If more options to set up the references are necessary then give me a call and I'll see what can be done.
     
    SimonDarksideJ and dis-s like this.
  11. stimul

    stimul

    Joined:
    Nov 28, 2013
    Posts:
    11
    Can someone update "InteractableText" script for unity 5.3 and above?
     
  12. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Thanks, I'd best get the version in the UI Extensions project updated to then :D
     
  13. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Better to get a Text Asset like TextMeshPro which handles this a lot better IMHO
     
  14. The_Devil

    The_Devil

    Joined:
    Jun 6, 2015
    Posts:
    36
    I am having an issue with Horizontal Scroll Snap - I had created a basic layout at first and everything was working fine. Once I changed the size of the Horizontal Scroll Snap to accommodate larger sprites, the pages started overlapping. Any idea how to fix this?
     
  15. fermmmm

    fermmmm

    Joined:
    Oct 18, 2013
    Posts:
    129
  16. Freezy

    Freezy

    Joined:
    Jul 15, 2012
    Posts:
    234
    judah4 likes this.
  17. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Great work @Freezy PR accepted and will be included in the next #UIExtensions release.
     
  18. smallbit

    smallbit

    Joined:
    Oct 3, 2013
    Posts:
    60
    @SimonDarksideJ
    I have some extensions of mine namely:
    1) Infinite scroll
    - automatic configuration (i.e. disabling of layouts and size fitter)
    - both directions (not at the same time)

    2) Scrollrect occlusion cull
    - disables objects off the scrollrect viewport
    - automatic configuration
    - usefull for large scroll content
    - reduces geometry and drawcalls (if not batched)
    - works in both directions (even at the same time)

    3) tween scale
    - can scale text or image component
    - based on curves
    - uniform scale or individual for x and y axis
    - loop
    - play on awake

    Here is a video that demoes above mentioned.



    Let me know If you are interested, I can post the script here or send them to you.
     
  19. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    All contributions welcome @smallbit
    Either fork the repo and add the PR yourself, or just create issue proposals and either paste ot link the code for each there and I'll pick them up.

    All look awesome!
     
  20. smallbit

    smallbit

    Joined:
    Oct 3, 2013
    Posts:
    60
    Added as proposals :) I will look in whats there, maybe I can be helpful in other features.
     
  21. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    All help and contributions welcome
     
  22. infinite360VR

    infinite360VR

    Joined:
    Apr 19, 2016
    Posts:
    23
    @Breyer @SimonDarksideJ

    I just downloaded TextWithEvent package and got an error: It says OnFillVBO is obselete, use OnPopulateMesh instead. Please help
     
    Last edited: Sep 9, 2016
  23. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Has anyone been able to get the SoftMask to work correctly? I feel like it hasn't been working for me correctly. Is there a tutorial for how to use it?
     
  24. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    How to fix conflict with Newtonsoft.Json.dll `System.Action' is defined multiple times?
     
  25. Word

    Word

    Joined:
    Jan 23, 2010
    Posts:
    225
    Just wanted to say thanks for this treasure of a thread and shamelessly request something myself :p - the things I'm still missing are a script for "guidelines" and a quick way to add a popup with images and text, both of which being unique for every object they're assigned to (and appearing when that object is clicked on, but i can do that part myself).
     
  26. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    Thanks for very useful asset. I also use Google Sheet in my project and get this error.
    Assets/unity-ui-extensions/Scripts/Controls/ComboBox/DropDownListItem.cs(79,16): error CS0433: The imported type `System.Action' is defined multiple times.
    That would be from conflict with Newtonsoft.Json.dll. How can I fix that?
     
  27. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
  28. zero3growlithe

    zero3growlithe

    Joined:
    Jul 7, 2012
    Posts:
    15
    Hi,
    I've created a new script for optimizing large Unity UI lists. It basically only enables elements that fit on the screen and disables everything else to save on rendering times.
    Maybe someone will find it useful.

    BaseMenuGrid class with core methods to override (usage example included): https://pastebin.com/CQ0Zw1Ed
    OptimizedMenuGrid class extending BaseMenuGrid class with optimization stuff: https://pastebin.com/CQ0Zw1Ed

    Enjoy.
     
  29. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Thanks for the contribution!

    Just in case you didn't realise, you can add a RectMask2D to mask off and not render off screen object - I had a list that had 280 drawcalls, whacked a RectMask2D over it and voila 18 drawcalls.
     
    JohnTube and zero3growlithe like this.
  30. Brogan89

    Brogan89

    Joined:
    Jul 10, 2014
    Posts:
    244
    Hey im not too sure if its a bug or if i missed somehting. In the UIWindowBase.cs to work for ScreenSpaceOverlay properly I had to add a condition. Works perfectly for the other render modes

    on line 48:
    Code (CSharp):
    1. if (m_canvas.renderMode == RenderMode.ScreenSpaceOverlay)
    2.         m_transform.position += delta;
    3.     else // WorldSpace or ScreenSpaceCamera
    4.         m_transform.localPosition += delta;
     
    larku likes this.
  31. Brogan89

    Brogan89

    Joined:
    Jul 10, 2014
    Posts:
    244
    Also for line 90: i changed
    Code (CSharp):
    1. max = new Vector2(Screen.width, Screen.height); //canvasSize;
    fixed an issue with 4k monitor using a 1080 canvas.

    Not sure where to report these kinds of things, I'm guessing they made private fork so can't do a pull request.
     
  32. vanshika1012

    vanshika1012

    Joined:
    Sep 18, 2014
    Posts:
    48
    ColorText is not working. It should be use BaseMeshEffect.
     
  33. Matanpjelly

    Matanpjelly

    Joined:
    Feb 6, 2018
    Posts:
    2
    Hi Breyer - are these scripts free for use for commerical products ( i have a game using your script )
     
  34. EdwinMurari

    EdwinMurari

    Joined:
    Jan 15, 2019
    Posts:
    6
    I noticed that the currentscreen() method was not returning the correcting value, to fix it, return Math.Round(calc), and you will always get the correct screen index.
     
  35. mrmeizongo

    mrmeizongo

    Joined:
    Mar 2, 2018
    Posts:
    2
    You've been very very helpful. Thank you so much.
     
    Senshi likes this.
  36. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    "Simply place the script on the ScrollRect that contains the selectable children we'll be scroling to
    and drag'n'drop the RectTransform of the options "container" that we'll be scrolling.*/"

    I tried dragging my RectTransform into any available slot in the inspector but the "UI buttons" in my container do not get centered. Bottom buttons still selected off camera. Any suggestions would be appreciated

    Thanks
     
    Last edited: Mar 6, 2020
  37. zero3growlithe

    zero3growlithe

    Joined:
    Jul 7, 2012
    Posts:
    15
    Hey there!
    Since I wrote this poor piece of code, let me support you with this handy minimal setup example project which should clear things up a bit.

    Included inside are 2 examples, one with the script you already have (but updated a little) which works fine with elements whose size is equal, and another example which works with elements of any size.
    The first one is a bit faster performance wise... at least it should :p

    Hope this helps!
     

    Attached Files:

  38. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Hi @zero3growlithe
    Thank you so much for your help!! I tried out your new package and it works perfectly!

    I ad a bit of confusion with the button alignments. But after comparing your scene's buttons, I was able to fix it.

    This new version works wonderfully! Thanks so much for everything! :D:D:D
     
    Last edited: Nov 1, 2019
    zero3growlithe likes this.
  39. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    If anyone runs into the same problem as I did, where the top button looks to be cut in half. The fix is to update the anchor points on all the buttons!

    Thanks again @zero3growlithe
     

    Attached Files:

    zero3growlithe likes this.
  40. catch_up

    catch_up

    Joined:
    Dec 30, 2013
    Posts:
    1
    Solution provided by Simon is great. However, some gotchas are there:
    1. The options in content of ScrollView must be pre-added. Since, calculations are happening inside Start of HorizontalScrollSnap, try to make sure your options are added before Start() is invoked, eg: inside Awake.

    2. It doesn't work well if you add GridLayoutGroup component to Content of ScrollView.
    To fix the paddings, consider grid padding and spacing between the cells. Rest of the things will automatically adjust. Check code:

    // Add adjustedPadding inside Start() of HorizontalScrollSnap.cs

    Code (CSharp):
    1.        
    2. GridLayoutGroup gridLayoutGroupInContent = _screensContainer.gameObject.GetComponent<GridLayoutGroup>();
    3.  
    4. float adjustedPadding =
    5. gridLayoutGroupInContent.padding.left + gridLayoutGroupInContent.padding.right + (_screens - 1) * gridLayoutGroupInContent.spacing.x;
    6.  
    7. _containerSize = (int)(_screensContainer.gameObject.GetComponent<RectTransform>().offsetMax.x - adjustedPadding);
    8.  


    pro
     

    Attached Files:

  41. eomerb

    eomerb

    Joined:
    Mar 6, 2020
    Posts:
    31
    hello there
    I just started to use rangeSlider
    dont know why but cant add other events like onPointerUp
    I get error sayin "Cannot assign to 'OnPointerUp' because it is a 'method group'"
    I wanted to use onPointerUp instead of onValueChanged because dont want to set any action while changing
     
  42. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    I recently tried the Scroll Snap extension and it was a wonderful tool to use. But then I saw that it required time.timescale at 1, so I went looking for an update if there was any and there was, which had me realize that for some reason I had forgotten to check the version I used which was a very old one.
    Nevertheless, I tried to use the UPM and change the manifest.json file as I picked only the part in the curled brackets:

    Code (CSharp):
    1. {
    2.       "name": "npmjs",
    3.       "url": "https://registry.npmjs.org/",
    4.       "scopes": [
    5.         "com.unity.uiextensions"
    6.       ]
    7.     }
    But it wouldn't load properly; I checked for the usual little nagging typo, missing coma, etc.
    So I just decided to use a git url instead (I had already done it for another package some time ago and it never needed any editing of the manifest file), but I can't find it anywhere in the documentation.
    As a last resort option, I just downloaded the package file and installed it the old way, after having deleted the former folder.
    It's unfortunate because I wish I could have used the UPM instead.
     
    Last edited: Feb 13, 2022
  43. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    I use horizontal scroll snap to swipe between pages; jumping form page to page with the slightest swipe possible.
    The setup was working flawlessly until I encountered a case where it's possible to stop the scroll snap component from letting a page slide all the way, so it remains stuck at a given percentage of the distance it should complete.
    Reducing the Transition Speed to 3 helps highlighting this.

    Even when using a value of 0 (or less but it shouldn't be of importance) for the Fast Swipe Threshold field, and using or not using Hard Swipe., or just relying Hard Swipe alone, I sometimes still get a page stuck.
    One can begin swiping for the next page before the current one has reached its destination (usually the center of the screen in most setups) and with the equivalent of a little twitch, one will prevent the current page from sliding. But it can even happen when moving a page that was already in place, at rest. It doesn't even try to finish it's interpolated slide, it just stops there, thinking all is done.

    When a page is blocked, one can drag it left and right by little increments and it will just slide the page of a few pixels on X but it will remain static, with no lerp being activated. Only doing a full swipe will restore the component's normal function and brings about the former or next page.
    With this bug you can even slowly drag a page so it partially moves out of the view, and when it disappears and triggers the next page, the next page will be static too.

    Putting higher threshold values in Swipe Delta Threshold like 50 helps minimizing these cases, but they still happen from time to time.
    Right now I'm trying to find a way to force the component to restart or perhaps resume that last unfinished lerp. Verifying the page's position against the content's window should cover this I think.

    EDIT: doing further tests after adding buttons with a scrolling "booklet" of 12 pages occupying most of the device's screen (simulating a smartphone), I precisely got the bug on the last page. The next button is disabled. At least this behaves logically because the script thinks the page is in place, as it looks at the currently activate page. With page 12 being active but stuck, there's no option to force a "next" slide with the next page button. Which unfortunately means I cannot cheat the script by forcing a previous or next page slide when one of them gets stuck.
    I got the same bug on the same page, luckily if I may say, and I tried to deactivate the Scroll Rect component to see what would happen.
    The page didn't move but a short drag on it had it drift into its slot with a lerp covering the remaining distance between its stuck position and expected central position on the screen.

    TL;DR
    Doing a little swipe during a lerp interrupts the lerp and the page's position is stuck, not reaching its expected targeted position.

    CASE SOLVED (it seems): the Scroll Rect's Inertia field was deactivated. A misclick or something. The effect wasn't obvious because even when OFF the inertia is emulated by the UI-extension component, but it knows its limits and definitely counts on the native inertia to work to its full capacity.
     
    Last edited: Feb 15, 2022
  44. chaosmonger

    chaosmonger

    Joined:
    Jan 23, 2019
    Posts:
    71
    Hello, not sure if other people had the same problem, I had a quick read-through this thread, but couldn't find.
    Basically I have an horizontal scroll, with the UIScrollToSelection. My canvas is set to readapt to a 1920x1080 screen using CanvasScaler (scale mode: Scale With Screen Size, Match Width or Height, with 0.5 value for the Match). Everything works great with this script if I'm on a 16:9 ratio resolution, but if I change my screen to a 4:3 one, the horizontal scroll doesn't work properly (it stops before reaching the edges, being them on the left or right side).
    I guess it has something to do with the fact that my canvas has a "native" 16:9 design, and gets messed up when I switch to a 4:3 one, but I've no clues why it's happening and how to solve it.
    My UI is an inventory bar on top of the screen, I'm selecting inventory items aligned in a row 1 by 1, using Rewired input system (gamepad or keyboard, no mouse scroll), and - again - all is perfect on 16:9 resolution, but not 4:3 one. The inventory and the UI are properly displayed also on 4:3, so the scale is working, all is great on the visual side (all perfectly aligned, centered, etc.) just the UIScrollToSelection.cs seems to be messed up.
    Any hint is very welcome!
    Thanks
     
  45. zero3growlithe

    zero3growlithe

    Joined:
    Jul 7, 2012
    Posts:
    15
  46. chaosmonger

    chaosmonger

    Joined:
    Jan 23, 2019
    Posts:
    71
    Thanks for your reply. I've tried using the updated script (the one included in the package you linked) into my project, but it doesn't work at all (doesn't scroll to my selected button, the scrollbar is totally still). I've tried opening your project alone, and it works there. So I'm wondering what's wrong with mine...
    The only thing I've noticed is that my selectable is not a direct child of the scroll window, but it's nested on another object, so I've tried to change something to the selection elements:

    Code (CSharp):
    1. if (CurrentSelectedGameObject != LastCheckedGameObject){
    2.             CurrentTargetRectTransform = (CurrentSelectedGameObject != null) ?
    3.                 CurrentSelectedGameObject.GetComponent<RectTransform>() :
    4.                 null;
    becoming:

    Code (CSharp):
    1. if (CurrentSelectedGameObject != LastCheckedGameObject)
    2.         {
    3.             CurrentTargetRectTransform = (CurrentSelectedGameObject != null) ?
    4.                 CurrentSelectedGameObject.transform.parent.GetComponent<RectTransform>() :
    5.                 null;
    But still, no luck... Before the problem was when checking the bool:
    Code (CSharp):
    1. if (selection == null || selection.transform.parent != LayoutListGroup.transform)
    Now that is solved, and if I put a debug.log("It's scrolling") under the UpdateHorizontalScrollPosition, I see it's called, but nothing changes, the scroll doesn't happen and I get infinite "It's scrolling" logs.

    Any guidance?

    UPDATE: after fixing the parent problem, the issue was in Time.deltaTime, since I'm calling this inventory during Pause... I solved using Time.unscaledDeltaTime.
    Thanks for the help
     
    Last edited: Jul 22, 2023
    zero3growlithe likes this.