UIDragScrollView.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Interaction/Drag Scroll View")]
  4. public class UIDragScrollView : MonoBehaviour
  5. {
  6. protected virtual void OnEnable()
  7. {
  8. this.mTrans = base.transform;
  9. if (this.scrollView == null && this.draggablePanel != null)
  10. {
  11. this.scrollView = this.draggablePanel;
  12. this.draggablePanel = null;
  13. }
  14. if (this.mStarted && (this.mAutoFind || this.mScroll == null))
  15. {
  16. this.FindScrollView();
  17. }
  18. }
  19. protected virtual void Start()
  20. {
  21. this.mStarted = true;
  22. this.FindScrollView();
  23. }
  24. protected virtual void FindScrollView()
  25. {
  26. UIScrollView uiscrollView = NGUITools.FindInParents<UIScrollView>(this.mTrans);
  27. if (this.scrollView == null || (this.mAutoFind && uiscrollView != this.scrollView))
  28. {
  29. this.scrollView = uiscrollView;
  30. this.mAutoFind = true;
  31. }
  32. else if (this.scrollView == uiscrollView)
  33. {
  34. this.mAutoFind = true;
  35. }
  36. this.mScroll = this.scrollView;
  37. }
  38. protected virtual void OnPress(bool pressed)
  39. {
  40. if (this.mAutoFind && this.mScroll != this.scrollView)
  41. {
  42. this.mScroll = this.scrollView;
  43. this.mAutoFind = false;
  44. }
  45. if (this.scrollView && base.enabled && NGUITools.GetActive(base.gameObject))
  46. {
  47. this.scrollView.Press(pressed);
  48. if (!pressed && this.mAutoFind)
  49. {
  50. this.scrollView = NGUITools.FindInParents<UIScrollView>(this.mTrans);
  51. this.mScroll = this.scrollView;
  52. }
  53. }
  54. }
  55. protected virtual void OnDrag(Vector2 delta)
  56. {
  57. if (this.scrollView && NGUITools.GetActive(this))
  58. {
  59. this.scrollView.Drag();
  60. }
  61. }
  62. protected virtual void OnScroll(float delta)
  63. {
  64. if (this.scrollView && NGUITools.GetActive(this))
  65. {
  66. this.scrollView.Scroll(delta);
  67. }
  68. }
  69. public UIScrollView scrollView;
  70. [HideInInspector]
  71. [SerializeField]
  72. private UIScrollView draggablePanel;
  73. protected Transform mTrans;
  74. protected UIScrollView mScroll;
  75. protected bool mAutoFind;
  76. protected bool mStarted;
  77. }