1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using UnityEngine;
- [AddComponentMenu("NGUI/Interaction/Drag Scroll View")]
- public class UIDragScrollView : MonoBehaviour
- {
- protected virtual void OnEnable()
- {
- this.mTrans = base.transform;
- if (this.scrollView == null && this.draggablePanel != null)
- {
- this.scrollView = this.draggablePanel;
- this.draggablePanel = null;
- }
- if (this.mStarted && (this.mAutoFind || this.mScroll == null))
- {
- this.FindScrollView();
- }
- }
- protected virtual void Start()
- {
- this.mStarted = true;
- this.FindScrollView();
- }
- protected virtual void FindScrollView()
- {
- UIScrollView uiscrollView = NGUITools.FindInParents<UIScrollView>(this.mTrans);
- if (this.scrollView == null || (this.mAutoFind && uiscrollView != this.scrollView))
- {
- this.scrollView = uiscrollView;
- this.mAutoFind = true;
- }
- else if (this.scrollView == uiscrollView)
- {
- this.mAutoFind = true;
- }
- this.mScroll = this.scrollView;
- }
- protected virtual void OnPress(bool pressed)
- {
- if (this.mAutoFind && this.mScroll != this.scrollView)
- {
- this.mScroll = this.scrollView;
- this.mAutoFind = false;
- }
- if (this.scrollView && base.enabled && NGUITools.GetActive(base.gameObject))
- {
- this.scrollView.Press(pressed);
- if (!pressed && this.mAutoFind)
- {
- this.scrollView = NGUITools.FindInParents<UIScrollView>(this.mTrans);
- this.mScroll = this.scrollView;
- }
- }
- }
- protected virtual void OnDrag(Vector2 delta)
- {
- if (this.scrollView && NGUITools.GetActive(this))
- {
- this.scrollView.Drag();
- }
- }
- protected virtual void OnScroll(float delta)
- {
- if (this.scrollView && NGUITools.GetActive(this))
- {
- this.scrollView.Scroll(delta);
- }
- }
- public UIScrollView scrollView;
- [HideInInspector]
- [SerializeField]
- private UIScrollView draggablePanel;
- protected Transform mTrans;
- protected UIScrollView mScroll;
- protected bool mAutoFind;
- protected bool mStarted;
- }
|