123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- using System;
- using UnityEngine;
- [ExecuteInEditMode]
- [AddComponentMenu("NGUI/Interaction/NGUI Slider")]
- public class UISlider : UIProgressBar
- {
- [Obsolete("Use 'value' instead")]
- public float sliderValue
- {
- get
- {
- return base.value;
- }
- set
- {
- base.value = value;
- }
- }
- [Obsolete("Use 'fillDirection' instead")]
- public bool inverted
- {
- get
- {
- return base.isInverted;
- }
- set
- {
- }
- }
- protected override void Upgrade()
- {
- if (this.direction != UISlider.Direction.Upgraded)
- {
- this.mValue = this.rawValue;
- if (this.foreground != null)
- {
- this.mFG = this.foreground.GetComponent<UIWidget>();
- }
- if (this.direction == UISlider.Direction.Horizontal)
- {
- this.mFill = ((!this.mInverted) ? UIProgressBar.FillDirection.LeftToRight : UIProgressBar.FillDirection.RightToLeft);
- }
- else
- {
- this.mFill = ((!this.mInverted) ? UIProgressBar.FillDirection.BottomToTop : UIProgressBar.FillDirection.TopToBottom);
- }
- this.direction = UISlider.Direction.Upgraded;
- }
- }
- protected override void OnStart()
- {
- GameObject go = (!(this.mBG != null) || (!(this.mBG.GetComponent<Collider>() != null) && !(this.mBG.GetComponent<Collider2D>() != null))) ? base.gameObject : this.mBG.gameObject;
- UIEventListener uieventListener = UIEventListener.Get(go);
- UIEventListener uieventListener2 = uieventListener;
- uieventListener2.onPress = (UIEventListener.BoolDelegate)Delegate.Combine(uieventListener2.onPress, new UIEventListener.BoolDelegate(this.OnPressBackground));
- UIEventListener uieventListener3 = uieventListener;
- uieventListener3.onDrag = (UIEventListener.VectorDelegate)Delegate.Combine(uieventListener3.onDrag, new UIEventListener.VectorDelegate(this.OnDragBackground));
- if (this.thumb != null && (this.thumb.GetComponent<Collider>() != null || this.thumb.GetComponent<Collider2D>() != null) && (this.mFG == null || this.thumb != this.mFG.cachedTransform))
- {
- UIEventListener uieventListener4 = UIEventListener.Get(this.thumb.gameObject);
- UIEventListener uieventListener5 = uieventListener4;
- uieventListener5.onPress = (UIEventListener.BoolDelegate)Delegate.Combine(uieventListener5.onPress, new UIEventListener.BoolDelegate(this.OnPressForeground));
- UIEventListener uieventListener6 = uieventListener4;
- uieventListener6.onDrag = (UIEventListener.VectorDelegate)Delegate.Combine(uieventListener6.onDrag, new UIEventListener.VectorDelegate(this.OnDragForeground));
- }
- }
- protected void OnPressBackground(GameObject go, bool isPressed)
- {
- if (UICamera.currentScheme == UICamera.ControlScheme.Controller)
- {
- return;
- }
- this.mCam = UICamera.currentCamera;
- base.value = base.ScreenToValue(UICamera.lastTouchPosition);
- if (!isPressed && this.onDragFinished != null)
- {
- this.onDragFinished();
- }
- }
- protected void OnDragBackground(GameObject go, Vector2 delta)
- {
- if (UICamera.currentScheme == UICamera.ControlScheme.Controller)
- {
- return;
- }
- this.mCam = UICamera.currentCamera;
- base.value = base.ScreenToValue(UICamera.lastTouchPosition);
- }
- protected void OnPressForeground(GameObject go, bool isPressed)
- {
- if (UICamera.currentScheme == UICamera.ControlScheme.Controller)
- {
- return;
- }
- this.mCam = UICamera.currentCamera;
- if (isPressed)
- {
- this.mOffset = ((!(this.mFG == null)) ? (base.value - base.ScreenToValue(UICamera.lastTouchPosition)) : 0f);
- }
- else if (this.onDragFinished != null)
- {
- this.onDragFinished();
- }
- }
- protected void OnDragForeground(GameObject go, Vector2 delta)
- {
- if (UICamera.currentScheme == UICamera.ControlScheme.Controller)
- {
- return;
- }
- this.mCam = UICamera.currentCamera;
- base.value = this.mOffset + base.ScreenToValue(UICamera.lastTouchPosition);
- }
- protected void OnKey(KeyCode key)
- {
- if (base.enabled)
- {
- float num = ((float)this.numberOfSteps <= 1f) ? 0.125f : (1f / (float)(this.numberOfSteps - 1));
- switch (this.mFill)
- {
- case UIProgressBar.FillDirection.LeftToRight:
- if (key == KeyCode.LeftArrow)
- {
- base.value = this.mValue - num;
- }
- else if (key == KeyCode.RightArrow)
- {
- base.value = this.mValue + num;
- }
- break;
- case UIProgressBar.FillDirection.RightToLeft:
- if (key == KeyCode.LeftArrow)
- {
- base.value = this.mValue + num;
- }
- else if (key == KeyCode.RightArrow)
- {
- base.value = this.mValue - num;
- }
- break;
- case UIProgressBar.FillDirection.BottomToTop:
- if (key == KeyCode.DownArrow)
- {
- base.value = this.mValue - num;
- }
- else if (key == KeyCode.UpArrow)
- {
- base.value = this.mValue + num;
- }
- break;
- case UIProgressBar.FillDirection.TopToBottom:
- if (key == KeyCode.DownArrow)
- {
- base.value = this.mValue + num;
- }
- else if (key == KeyCode.UpArrow)
- {
- base.value = this.mValue - num;
- }
- break;
- }
- }
- }
- [HideInInspector]
- [SerializeField]
- private Transform foreground;
- [HideInInspector]
- [SerializeField]
- private float rawValue = 1f;
- [HideInInspector]
- [SerializeField]
- private UISlider.Direction direction = UISlider.Direction.Upgraded;
- [HideInInspector]
- [SerializeField]
- protected bool mInverted;
- private enum Direction
- {
- Horizontal,
- Vertical,
- Upgraded
- }
- }
|