RotationScaleScrollView.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using UnityEngine;
  2. public class RotationScaleScrollView : ScalePageScrollView
  3. {
  4. public float rotation;
  5. protected override void Update()
  6. {
  7. base.Update();
  8. ListenerItemRotation();
  9. }
  10. public void ListenerItemRotation() {
  11. if (nextPage == lastPage)
  12. {
  13. return;
  14. }
  15. float percent = (rect.horizontalNormalizedPosition - pages[lastPage]) / (pages[nextPage] - pages[lastPage]);
  16. if (nextPage > currentPage)
  17. {
  18. items[lastPage].transform.localRotation = Quaternion.Euler(-Vector3.Lerp(Vector3.zero, new Vector3(0, rotation, 0), percent));
  19. items[nextPage].transform.localRotation = Quaternion.Euler(Vector3.Lerp(Vector3.zero, new Vector3(0, rotation, 0), 1 - percent));
  20. }
  21. else {
  22. items[lastPage].transform.localRotation = Quaternion.Euler(-Vector3.Lerp(Vector3.zero, new Vector3(0, rotation, 0), percent));
  23. items[nextPage].transform.localRotation = Quaternion.Euler(Vector3.Lerp(Vector3.zero, new Vector3(0, rotation, 0), 1 - percent));
  24. }
  25. for (int i = 0; i < items.Length; i++)
  26. {
  27. if ( i != lastPage && i != nextPage )
  28. {
  29. if (i < currentPage)
  30. {
  31. items[i].transform.localRotation = Quaternion.Euler(new Vector3(0, -rotation, 0));
  32. }
  33. else if (i == currentPage)
  34. {
  35. //items[i].transform.localRotation = Quaternion.Euler(new Vector3(0, 0, 0));
  36. }
  37. else if (i > currentPage)
  38. {
  39. items[i].transform.localRotation = Quaternion.Euler(new Vector3(0, rotation, 0));
  40. }
  41. }
  42. }
  43. }
  44. }