ContentScrollSnapHorizontal.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /// Credit Beka Westberg
  2. /// Sourced from - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/28
  3. /// Updated by SimonDarksideJ - Added some exception management and a SetNewItems to replace the content programmatically
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine.EventSystems;
  7. using UnityEngine.Events;
  8. using System;
  9. namespace UnityEngine.UI.Extensions
  10. {
  11. [ExecuteInEditMode]
  12. [RequireComponent(typeof(ScrollRect))]
  13. [AddComponentMenu("UI/Extensions/ContentSnapScrollHorizontal")]
  14. public class ContentScrollSnapHorizontal : MonoBehaviour, IBeginDragHandler, IEndDragHandler
  15. {
  16. [Serializable]
  17. public class StartMovementEvent : UnityEvent { }
  18. [Serializable]
  19. public class CurrentItemChangeEvent : UnityEvent<int> { }
  20. [Serializable]
  21. public class FoundItemToSnapToEvent : UnityEvent<int> { }
  22. [Serializable]
  23. public class SnappedToItemEvent : UnityEvent<int> { }
  24. public bool ignoreInactiveItems = true;
  25. public MoveInfo startInfo = new MoveInfo(MoveInfo.IndexType.positionIndex, 0);
  26. public GameObject prevButton;
  27. public GameObject nextButton;
  28. public GameObject pagination;
  29. [Tooltip("The velocity below which the scroll rect will start to snap")]
  30. public int snappingVelocityThreshold = 50;
  31. [Header("Paging Info")]
  32. [Tooltip("Should the pagination & buttons jump or lerp to the items")]
  33. public bool jumpToItem = false;
  34. [Tooltip("The time it will take for the pagination or buttons to move between items")]
  35. public float lerpTime = .3f;
  36. [Header("Events")]
  37. [SerializeField]
  38. [Tooltip("Event is triggered whenever the scroll rect starts to move, even when triggered programmatically")]
  39. private StartMovementEvent m_StartMovementEvent = new StartMovementEvent();
  40. public StartMovementEvent MovementStarted
  41. {
  42. get
  43. {
  44. return m_StartMovementEvent;
  45. }
  46. set
  47. {
  48. m_StartMovementEvent = value;
  49. }
  50. }
  51. [SerializeField]
  52. [Tooltip("Event is triggered whenever the closest item to the center of the scrollrect changes")]
  53. private CurrentItemChangeEvent m_CurrentItemChangeEvent = new CurrentItemChangeEvent();
  54. public CurrentItemChangeEvent CurrentItemChanged
  55. {
  56. get
  57. {
  58. return m_CurrentItemChangeEvent;
  59. }
  60. set
  61. {
  62. m_CurrentItemChangeEvent = value;
  63. }
  64. }
  65. [SerializeField]
  66. [Tooltip("Event is triggered when the ContentSnapScroll decides which item it is going to snap to. Returns the index of the closest position.")]
  67. private FoundItemToSnapToEvent m_FoundItemToSnapToEvent = new FoundItemToSnapToEvent();
  68. public FoundItemToSnapToEvent ItemFoundToSnap
  69. {
  70. get
  71. {
  72. return m_FoundItemToSnapToEvent;
  73. }
  74. set
  75. {
  76. m_FoundItemToSnapToEvent = value;
  77. }
  78. }
  79. [SerializeField]
  80. [Tooltip("Event is triggered when we finally settle on an element. Returns the index of the item's position.")]
  81. private SnappedToItemEvent m_SnappedToItemEvent = new SnappedToItemEvent();
  82. public SnappedToItemEvent ItemSnappedTo
  83. {
  84. get
  85. {
  86. return m_SnappedToItemEvent;
  87. }
  88. set
  89. {
  90. m_SnappedToItemEvent = value;
  91. }
  92. }
  93. private ScrollRect scrollRect = null;
  94. private RectTransform scrollRectTransform = null;
  95. private RectTransform contentTransform = null;
  96. private List<Vector3> contentPositions = new List<Vector3>();
  97. private Vector3 lerpTarget = Vector3.zero;
  98. private float totalScrollableWidth = 0;
  99. private DrivenRectTransformTracker tracker ;
  100. private float mLerpTime = 0;
  101. private int _closestItem = 0;
  102. private bool mSliding = false;
  103. private bool mLerping = false;
  104. private bool ContentIsHorizonalLayoutGroup
  105. {
  106. get
  107. {
  108. return contentTransform.GetComponent<HorizontalLayoutGroup>() != null;
  109. }
  110. }
  111. #region Public Info
  112. /// <summary>
  113. /// Returns if the SnapScroll is moving
  114. /// </summary>
  115. public bool Moving
  116. {
  117. get
  118. {
  119. return Sliding || Lerping;
  120. }
  121. }
  122. /// <summary>
  123. /// Returns if the SnapScroll is moving because of a touch
  124. /// </summary>
  125. public bool Sliding
  126. {
  127. get
  128. {
  129. return mSliding;
  130. }
  131. }
  132. /// <summary>
  133. /// Returns if the SnapScroll is moving programmatically
  134. /// </summary>
  135. public bool Lerping
  136. {
  137. get
  138. {
  139. return mLerping;
  140. }
  141. }
  142. /// <summary>
  143. /// Returns the closest item's index
  144. /// *Note this is zero based, and based on position not child order
  145. /// </summary>
  146. public int ClosestItemIndex
  147. {
  148. get
  149. {
  150. return contentPositions.IndexOf(FindClosestFrom(contentTransform.localPosition));
  151. }
  152. }
  153. /// <summary>
  154. /// Returns the lerpTarget's index
  155. /// *Note this is zero-based, and based on position not child order
  156. /// </summary>
  157. public int LerpTargetIndex
  158. {
  159. get
  160. {
  161. return contentPositions.IndexOf(lerpTarget);
  162. }
  163. }
  164. #endregion
  165. #region Setup
  166. private void Awake()
  167. {
  168. scrollRect = GetComponent<ScrollRect>();
  169. scrollRectTransform = (RectTransform) scrollRect.transform;
  170. contentTransform = scrollRect.content;
  171. if (nextButton)
  172. nextButton.GetComponent<Button>().onClick.AddListener(() => { NextItem(); });
  173. if (prevButton)
  174. prevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousItem(); });
  175. if (IsScrollRectAvailable)
  176. {
  177. SetupDrivenTransforms();
  178. SetupSnapScroll();
  179. scrollRect.horizontalNormalizedPosition = 0;
  180. _closestItem = 0;
  181. GoTo(startInfo);
  182. }
  183. }
  184. public void SetNewItems(ref List<Transform> newItems)
  185. {
  186. if (scrollRect && contentTransform)
  187. {
  188. for (int i = scrollRect.content.childCount - 1; i >= 0; i--)
  189. {
  190. Transform child = contentTransform.GetChild(i);
  191. child.SetParent(null);
  192. GameObject.DestroyImmediate(child.gameObject);
  193. }
  194. foreach (Transform item in newItems)
  195. {
  196. GameObject newItem = item.gameObject;
  197. if (newItem.IsPrefab())
  198. {
  199. newItem = Instantiate(item.gameObject, contentTransform);
  200. }
  201. else
  202. {
  203. newItem.transform.SetParent(contentTransform);
  204. }
  205. }
  206. SetupDrivenTransforms();
  207. SetupSnapScroll();
  208. scrollRect.horizontalNormalizedPosition = 0;
  209. _closestItem = 0;
  210. GoTo(startInfo);
  211. }
  212. }
  213. private bool IsScrollRectAvailable
  214. {
  215. get
  216. {
  217. if (scrollRect &&
  218. contentTransform &&
  219. contentTransform.childCount > 0)
  220. {
  221. return true;
  222. }
  223. return false;
  224. }
  225. }
  226. private void OnDisable()
  227. {
  228. tracker.Clear();
  229. }
  230. private void SetupDrivenTransforms()
  231. {
  232. tracker = new DrivenRectTransformTracker();
  233. tracker.Clear();
  234. //So that we can calculate everything correctly
  235. foreach (RectTransform child in contentTransform)
  236. {
  237. tracker.Add(this, child, DrivenTransformProperties.Anchors);
  238. child.anchorMax = new Vector2(0, 1);
  239. child.anchorMin = new Vector2(0, 1);
  240. }
  241. }
  242. private void SetupSnapScroll()
  243. {
  244. if (ContentIsHorizonalLayoutGroup)
  245. {
  246. //because you can't get the anchored positions of UI elements
  247. //when they are in a layout group (as far as I could tell)
  248. SetupWithHorizontalLayoutGroup();
  249. }
  250. else
  251. {
  252. SetupWithCalculatedSpacing();
  253. }
  254. }
  255. private void SetupWithHorizontalLayoutGroup()
  256. {
  257. HorizontalLayoutGroup horizLayoutGroup = contentTransform.GetComponent<HorizontalLayoutGroup>();
  258. float childTotalWidths = 0;
  259. int activeChildren = 0;
  260. for (int i = 0; i < contentTransform.childCount; i++)
  261. {
  262. if (!ignoreInactiveItems || contentTransform.GetChild(i).gameObject.activeInHierarchy)
  263. {
  264. childTotalWidths += ((RectTransform)contentTransform.GetChild(i)).sizeDelta.x;
  265. activeChildren++;
  266. }
  267. }
  268. float spacingTotal = (activeChildren - 1) * horizLayoutGroup.spacing;
  269. float totalWidth = childTotalWidths + spacingTotal + horizLayoutGroup.padding.left + horizLayoutGroup.padding.right;
  270. contentTransform.sizeDelta = new Vector2(totalWidth, contentTransform.sizeDelta.y);
  271. float scrollRectWidth = Mathf.Min(((RectTransform)contentTransform.GetChild(0)).sizeDelta.x, ((RectTransform)contentTransform.GetChild(contentTransform.childCount - 1)).sizeDelta.x);
  272. /*---If the scroll view is set to stretch width this breaks stuff---*/
  273. scrollRectTransform.sizeDelta = new Vector2(scrollRectWidth, scrollRectTransform.sizeDelta.y);
  274. contentPositions = new List<Vector3>();
  275. float widthOfScrollRect = scrollRectTransform.sizeDelta.x;
  276. totalScrollableWidth = totalWidth - widthOfScrollRect;
  277. float checkedChildrenTotalWidths = horizLayoutGroup.padding.left;
  278. int activeChildrenBeforeSelf = 0;
  279. for (int i = 0; i < contentTransform.childCount; i++)
  280. {
  281. if (!ignoreInactiveItems || contentTransform.GetChild(i).gameObject.activeInHierarchy)
  282. {
  283. float widthOfSelf = ((RectTransform)contentTransform.GetChild(i)).sizeDelta.x;
  284. float offset = checkedChildrenTotalWidths + (horizLayoutGroup.spacing * activeChildrenBeforeSelf) + ((widthOfSelf - widthOfScrollRect) / 2);
  285. scrollRect.horizontalNormalizedPosition = offset / totalScrollableWidth;
  286. contentPositions.Add(contentTransform.localPosition);
  287. checkedChildrenTotalWidths += widthOfSelf;
  288. activeChildrenBeforeSelf++;
  289. }
  290. }
  291. }
  292. private void SetupWithCalculatedSpacing()
  293. {
  294. //we need them in order from left to right for pagination & buttons & our scrollRectWidth
  295. List<RectTransform> childrenFromLeftToRight = new List<RectTransform>();
  296. for (int i = 0; i < contentTransform.childCount; i++)
  297. {
  298. if (!ignoreInactiveItems || contentTransform.GetChild(i).gameObject.activeInHierarchy)
  299. {
  300. RectTransform childBeingSorted = ((RectTransform)contentTransform.GetChild(i));
  301. int insertIndex = childrenFromLeftToRight.Count;
  302. for (int j = 0; j < childrenFromLeftToRight.Count; j++)
  303. {
  304. if (DstFromTopLeftOfTransformToTopLeftOfParent(childBeingSorted).x < DstFromTopLeftOfTransformToTopLeftOfParent(childrenFromLeftToRight[j]).x)
  305. {
  306. insertIndex = j;
  307. break;
  308. }
  309. }
  310. childrenFromLeftToRight.Insert(insertIndex, childBeingSorted);
  311. }
  312. }
  313. RectTransform childFurthestToTheRight = childrenFromLeftToRight[childrenFromLeftToRight.Count - 1];
  314. float totalWidth = DstFromTopLeftOfTransformToTopLeftOfParent(childFurthestToTheRight).x + childFurthestToTheRight.sizeDelta.x;
  315. contentTransform.sizeDelta = new Vector2(totalWidth, contentTransform.sizeDelta.y);
  316. float scrollRectWidth = Mathf.Min(childrenFromLeftToRight[0].sizeDelta.x, childrenFromLeftToRight[childrenFromLeftToRight.Count - 1].sizeDelta.x);
  317. // Note: sizeDelta will not be calculated properly if the scroll view is set to stretch width.
  318. scrollRectTransform.sizeDelta = new Vector2(scrollRectWidth, scrollRectTransform.sizeDelta.y);
  319. contentPositions = new List<Vector3>();
  320. float widthOfScrollRect = scrollRectTransform.sizeDelta.x;
  321. totalScrollableWidth = totalWidth - widthOfScrollRect;
  322. for (int i = 0; i < childrenFromLeftToRight.Count; i++)
  323. {
  324. float offset = DstFromTopLeftOfTransformToTopLeftOfParent(childrenFromLeftToRight[i]).x + ((childrenFromLeftToRight[i].sizeDelta.x - widthOfScrollRect) / 2);
  325. scrollRect.horizontalNormalizedPosition = offset / totalScrollableWidth;
  326. contentPositions.Add(contentTransform.localPosition);
  327. }
  328. }
  329. #endregion
  330. #region Public Movement Functions
  331. /// <summary>
  332. /// Function for going to a specific screen.
  333. /// *Note the index is based on a zero-starting index.
  334. /// </summary>
  335. /// <param name="info">All of the info about how you want it to move</param>
  336. public void GoTo(MoveInfo info)
  337. {
  338. if (!Moving && info.index != ClosestItemIndex)
  339. {
  340. MovementStarted.Invoke();
  341. }
  342. if (info.indexType == MoveInfo.IndexType.childIndex)
  343. {
  344. mLerpTime = info.duration;
  345. GoToChild(info.index, info.jump);
  346. }
  347. else if (info.indexType == MoveInfo.IndexType.positionIndex)
  348. {
  349. mLerpTime = info.duration;
  350. GoToContentPos(info.index, info.jump);
  351. }
  352. }
  353. private void GoToChild(int index, bool jump)
  354. {
  355. int clampedIndex = Mathf.Clamp(index, 0, contentPositions.Count - 1); //contentPositions amount == the amount of available children
  356. if (ContentIsHorizonalLayoutGroup) //the contentPositions are in child order
  357. {
  358. lerpTarget = contentPositions[clampedIndex];
  359. if (jump)
  360. {
  361. contentTransform.localPosition = lerpTarget;
  362. }
  363. else
  364. {
  365. StopMovement();
  366. StartCoroutine("LerpToContent");
  367. }
  368. }
  369. else //the contentPositions are in order from left -> right;
  370. {
  371. int availableChildIndex = 0; //an available child is one we can snap to
  372. Vector3 previousContentTransformPos = contentTransform.localPosition;
  373. for (int i = 0; i < contentTransform.childCount; i++)
  374. {
  375. if (!ignoreInactiveItems || contentTransform.GetChild(i).gameObject.activeInHierarchy)
  376. {
  377. if (availableChildIndex == clampedIndex)
  378. {
  379. RectTransform startChild = (RectTransform) contentTransform.GetChild(i);
  380. float offset = DstFromTopLeftOfTransformToTopLeftOfParent(startChild).x + ((startChild.sizeDelta.x - scrollRectTransform.sizeDelta.x) / 2);
  381. scrollRect.horizontalNormalizedPosition = offset / totalScrollableWidth;
  382. lerpTarget = contentTransform.localPosition;
  383. if (!jump)
  384. {
  385. contentTransform.localPosition = previousContentTransformPos;
  386. StopMovement();
  387. StartCoroutine("LerpToContent");
  388. }
  389. return;
  390. }
  391. availableChildIndex++;
  392. }
  393. }
  394. }
  395. }
  396. private void GoToContentPos(int index, bool jump)
  397. {
  398. int clampedIndex = Mathf.Clamp(index, 0, contentPositions.Count - 1); //contentPositions amount == the amount of available children
  399. //the content positions are all in order from left -> right
  400. //which is what we want so there's no need to check
  401. lerpTarget = contentPositions[clampedIndex];
  402. if (jump)
  403. {
  404. contentTransform.localPosition = lerpTarget;
  405. }
  406. else
  407. {
  408. StopMovement();
  409. StartCoroutine("LerpToContent");
  410. }
  411. }
  412. /// <summary>
  413. /// Function for going to the next item
  414. /// *Note the next item is the item to the right of the current item, this is not based on child order
  415. /// </summary>
  416. public void NextItem()
  417. {
  418. int index;
  419. if (Sliding)
  420. {
  421. index = ClosestItemIndex + 1;
  422. }
  423. else
  424. {
  425. index = LerpTargetIndex + 1;
  426. }
  427. MoveInfo info = new MoveInfo(MoveInfo.IndexType.positionIndex, index, jumpToItem, lerpTime);
  428. GoTo(info);
  429. }
  430. /// <summary>
  431. /// Function for going to the previous item
  432. /// *Note the next item is the item to the left of the current item, this is not based on child order
  433. /// </summary>
  434. public void PreviousItem()
  435. {
  436. int index;
  437. if (Sliding)
  438. {
  439. index = ClosestItemIndex - 1;
  440. }
  441. else
  442. {
  443. index = LerpTargetIndex - 1;
  444. }
  445. MoveInfo info = new MoveInfo(MoveInfo.IndexType.positionIndex, index, jumpToItem, lerpTime);
  446. GoTo(info);
  447. }
  448. /// <summary>
  449. /// Function for recalculating the size of the content & the snap positions, such as when you remove or add a child
  450. /// </summary>
  451. public void UpdateLayout()
  452. {
  453. SetupDrivenTransforms();
  454. SetupSnapScroll();
  455. }
  456. /// <summary>
  457. /// Recalculates the size of the content & snap positions, and moves to a new item afterwards.
  458. /// </summary>
  459. /// <param name="info">All of the info about how you want it to move</param>
  460. public void UpdateLayoutAndMoveTo(MoveInfo info)
  461. {
  462. SetupDrivenTransforms();
  463. SetupSnapScroll();
  464. GoTo(info);
  465. }
  466. #endregion
  467. #region Behind the Scenes Movement stuff
  468. public void OnBeginDrag(PointerEventData ped)
  469. {
  470. if (contentPositions.Count < 2)
  471. {
  472. return;
  473. }
  474. StopMovement();
  475. if (!Moving)
  476. {
  477. MovementStarted.Invoke();
  478. }
  479. }
  480. public void OnEndDrag(PointerEventData ped)
  481. {
  482. if (contentPositions.Count <= 1)
  483. {
  484. return;
  485. }
  486. if (IsScrollRectAvailable)
  487. {
  488. StartCoroutine("SlideAndLerp");
  489. }
  490. }
  491. private void Update()
  492. {
  493. if (IsScrollRectAvailable)
  494. {
  495. if (_closestItem != ClosestItemIndex)
  496. {
  497. CurrentItemChanged.Invoke(ClosestItemIndex);
  498. ChangePaginationInfo(ClosestItemIndex);
  499. _closestItem = ClosestItemIndex;
  500. }
  501. }
  502. }
  503. private IEnumerator SlideAndLerp()
  504. {
  505. mSliding = true;
  506. while (Mathf.Abs(scrollRect.velocity.x) > snappingVelocityThreshold)
  507. {
  508. yield return null;
  509. }
  510. lerpTarget = FindClosestFrom(contentTransform.localPosition);
  511. ItemFoundToSnap.Invoke(LerpTargetIndex);
  512. while (Vector3.Distance(contentTransform.localPosition, lerpTarget) > 1)
  513. {
  514. contentTransform.localPosition = Vector3.Lerp(scrollRect.content.localPosition, lerpTarget, 7.5f * Time.deltaTime);
  515. yield return null;
  516. }
  517. mSliding = false;
  518. scrollRect.velocity = Vector2.zero;
  519. contentTransform.localPosition = lerpTarget;
  520. ItemSnappedTo.Invoke(LerpTargetIndex);
  521. }
  522. private IEnumerator LerpToContent()
  523. {
  524. ItemFoundToSnap.Invoke(LerpTargetIndex);
  525. mLerping = true;
  526. Vector3 originalContentPos = contentTransform.localPosition;
  527. float elapsedTime = 0;
  528. while (elapsedTime < mLerpTime)
  529. {
  530. elapsedTime += Time.deltaTime;
  531. contentTransform.localPosition = Vector3.Lerp(originalContentPos, lerpTarget, (elapsedTime / mLerpTime));
  532. yield return null;
  533. }
  534. ItemSnappedTo.Invoke(LerpTargetIndex);
  535. mLerping = false;
  536. }
  537. #endregion
  538. private void StopMovement()
  539. {
  540. scrollRect.velocity = Vector2.zero;
  541. StopCoroutine("SlideAndLerp");
  542. StopCoroutine("LerpToContent");
  543. }
  544. private void ChangePaginationInfo(int targetScreen)
  545. {
  546. if (pagination)
  547. for (int i = 0; i < pagination.transform.childCount; i++)
  548. {
  549. pagination.transform.GetChild(i).GetComponent<Toggle>().isOn = (targetScreen == i);
  550. }
  551. }
  552. private Vector2 DstFromTopLeftOfTransformToTopLeftOfParent(RectTransform rt)
  553. {
  554. //gets rid of any pivot weirdness
  555. return new Vector2(rt.anchoredPosition.x - (rt.sizeDelta.x * rt.pivot.x), rt.anchoredPosition.y + (rt.sizeDelta.y * (1 - rt.pivot.y)));
  556. }
  557. private Vector3 FindClosestFrom(Vector3 start)
  558. {
  559. Vector3 closest = Vector3.zero;
  560. float distance = Mathf.Infinity;
  561. foreach (Vector3 position in contentPositions)
  562. {
  563. if (Vector3.Distance(start, position) < distance)
  564. {
  565. distance = Vector3.Distance(start, position);
  566. closest = position;
  567. }
  568. }
  569. return closest;
  570. }
  571. [System.Serializable]
  572. public struct MoveInfo
  573. {
  574. public enum IndexType { childIndex, positionIndex }
  575. [Tooltip("Child Index means the Index corresponds to the content item at that index in the hierarchy.\n" +
  576. "Position Index means the Index corresponds to the content item in that snap position.\n" +
  577. "A higher Position Index in a Horizontal Scroll Snap means it would be further to the right.")]
  578. public IndexType indexType;
  579. [Tooltip("Zero based")]
  580. public int index;
  581. [Tooltip("If this is true the snap scroll will jump to the index, otherwise it will lerp there.")]
  582. public bool jump;
  583. [Tooltip("If jump is false this is the time it will take to lerp to the index")]
  584. public float duration;
  585. /// <summary>
  586. /// Creates a MoveInfo that jumps to the index
  587. /// </summary>
  588. /// <param name="_indexType">Whether you want to get the child at the index or the snap position at the index</param>
  589. /// <param name="_index">Where you want it to jump</param>
  590. public MoveInfo(IndexType _indexType, int _index)
  591. {
  592. indexType = _indexType;
  593. index = _index;
  594. jump = true;
  595. duration = 0;
  596. }
  597. /// <summary>
  598. /// Creates a MoveInfo
  599. /// </summary>
  600. /// <param name="_indexType">Whether you want to get the child at the index or the snap position at the index</param>
  601. /// <param name="_index">Where you want it to jump</param>
  602. /// <param name="_jump">Whether you want it to jump or lerp to the index</param>
  603. /// <param name="_duration">How long it takes to lerp to the index</param>
  604. public MoveInfo(IndexType _indexType, int _index, bool _jump, float _duration)
  605. {
  606. indexType = _indexType;
  607. index = _index;
  608. jump = _jump;
  609. duration = _duration;
  610. }
  611. }
  612. }
  613. }