|  |  |  | 
|---|
|  |  |  | using System.Collections; | 
|---|
|  |  |  | using UnityEngine.UI; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace vnxbqy.UI | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class ScreenDiffuseMove : MonoBehaviour | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class ScreenDiffuseMove : MonoBehaviour | 
|---|
|  |  |  | [SerializeField] DiffuseType m_MoveType = DiffuseType.MoveUp; | 
|---|
|  |  |  | public DiffuseType moveType { get { return m_MoveType; } } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] float m_Speed = 10f; | 
|---|
|  |  |  | public float speed { | 
|---|
|  |  |  | get { return m_Speed; } | 
|---|
|  |  |  | set { m_Speed = value; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] TweenCurve m_SpeedRatioCurve; | 
|---|
|  |  |  | [SerializeField] float m_Duration = 1f; | 
|---|
|  |  |  | public float duration { | 
|---|
|  |  |  | get { return m_Duration; } | 
|---|
|  |  |  | set { m_Duration = value; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] float m_Delay = 0f; | 
|---|
|  |  |  | public float delay { | 
|---|
|  |  |  | get { return m_Delay; } | 
|---|
|  |  |  | set { m_Delay = value; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] bool m_IsLocal = true; | 
|---|
|  |  |  | public bool isLocal { | 
|---|
|  |  |  | get { return m_IsLocal; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float beginTime = 0f; | 
|---|
|  |  |  | float endTime = 0f; | 
|---|
|  |  |  | Vector2 direction = Vector2.up; | 
|---|
|  |  |  | bool disableOnEnd = true; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void Begin(bool _disableOnEnd = true) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | beginTime = Time.time + delay; | 
|---|
|  |  |  | endTime = Time.time + delay + duration; | 
|---|
|  |  |  | disableOnEnd = _disableOnEnd; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] DiffuseType m_MoveType = DiffuseType.MoveUp; | 
|---|
|  |  |  | public DiffuseType moveType { get { return m_MoveType; } } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] float m_Speed = 10f; | 
|---|
|  |  |  | public float speed { | 
|---|
|  |  |  | get { return m_Speed; } | 
|---|
|  |  |  | set { m_Speed = value; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] TweenCurve m_SpeedRatioCurve; | 
|---|
|  |  |  | [SerializeField] float m_Duration = 1f; | 
|---|
|  |  |  | public float duration { | 
|---|
|  |  |  | get { return m_Duration; } | 
|---|
|  |  |  | set { m_Duration = value; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] float m_Delay = 0f; | 
|---|
|  |  |  | public float delay { | 
|---|
|  |  |  | get { return m_Delay; } | 
|---|
|  |  |  | set { m_Delay = value; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] bool m_IsLocal = true; | 
|---|
|  |  |  | public bool isLocal { | 
|---|
|  |  |  | get { return m_IsLocal; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float beginTime = 0f; | 
|---|
|  |  |  | float endTime = 0f; | 
|---|
|  |  |  | Vector2 direction = Vector2.up; | 
|---|
|  |  |  | bool disableOnEnd = true; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void Begin(bool _disableOnEnd = true) | 
|---|
|  |  |  | switch (m_MoveType) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | beginTime = Time.time + delay; | 
|---|
|  |  |  | endTime = Time.time + delay + duration; | 
|---|
|  |  |  | disableOnEnd = _disableOnEnd; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | switch (m_MoveType) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | case DiffuseType.MoveUp: | 
|---|
|  |  |  | direction = Vector2.up * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveDown: | 
|---|
|  |  |  | direction = Vector2.down * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveLeft: | 
|---|
|  |  |  | direction = Vector2.left * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveRight: | 
|---|
|  |  |  | direction = Vector2.right * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.RelativePosition: | 
|---|
|  |  |  | direction = new Vector2(this.transform.position.x, this.transform.position.y).normalized * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.ReversalRelativePosition: | 
|---|
|  |  |  | direction = new Vector2(-this.transform.position.x, this.transform.position.y).normalized * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.enabled = true; | 
|---|
|  |  |  | if (!this.gameObject.activeInHierarchy) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | this.SetActive(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | case DiffuseType.MoveUp: | 
|---|
|  |  |  | direction = Vector2.up * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveDown: | 
|---|
|  |  |  | direction = Vector2.down * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveLeft: | 
|---|
|  |  |  | direction = Vector2.left * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveRight: | 
|---|
|  |  |  | direction = Vector2.right * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.RelativePosition: | 
|---|
|  |  |  | direction = new Vector2(this.transform.position.x, this.transform.position.y).normalized * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.ReversalRelativePosition: | 
|---|
|  |  |  | direction = new Vector2(-this.transform.position.x, this.transform.position.y).normalized * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void Begin(Vector3 _direction, bool _disableOnEnd = true) | 
|---|
|  |  |  | this.enabled = true; | 
|---|
|  |  |  | if (!this.gameObject.activeInHierarchy) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | beginTime = Time.time + delay; | 
|---|
|  |  |  | endTime = Time.time + delay + duration; | 
|---|
|  |  |  | disableOnEnd = _disableOnEnd; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | switch (m_MoveType) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | case DiffuseType.MoveUp: | 
|---|
|  |  |  | direction = Vector2.up * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveDown: | 
|---|
|  |  |  | direction = Vector2.down * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveLeft: | 
|---|
|  |  |  | direction = Vector2.left * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveRight: | 
|---|
|  |  |  | direction = Vector2.right * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.RelativePosition: | 
|---|
|  |  |  | direction = new Vector2(_direction.x, _direction.y).normalized * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.ReversalRelativePosition: | 
|---|
|  |  |  | direction = new Vector2(_direction.x, -_direction.y).normalized * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.enabled = true; | 
|---|
|  |  |  | if (!this.gameObject.activeInHierarchy) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | this.SetActive(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.SetActive(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void LateUpdate() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (Time.time < beginTime) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Time.time < endTime) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var delta = direction * Time.deltaTime * m_SpeedRatioCurve.Evaluate((Time.time - beginTime) / duration); | 
|---|
|  |  |  | if (isLocal) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | this.transform.localPosition += new Vector3(delta.x, delta.y, 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | this.transform.position += new Vector3(delta.x, delta.y, 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (disableOnEnd) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | this.enabled = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public void Begin(Vector3 _direction, bool _disableOnEnd = true) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | beginTime = Time.time + delay; | 
|---|
|  |  |  | endTime = Time.time + delay + duration; | 
|---|
|  |  |  | disableOnEnd = _disableOnEnd; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | switch (m_MoveType) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | case DiffuseType.MoveUp: | 
|---|
|  |  |  | direction = Vector2.up * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveDown: | 
|---|
|  |  |  | direction = Vector2.down * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveLeft: | 
|---|
|  |  |  | direction = Vector2.left * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.MoveRight: | 
|---|
|  |  |  | direction = Vector2.right * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.RelativePosition: | 
|---|
|  |  |  | direction = new Vector2(_direction.x, _direction.y).normalized * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case DiffuseType.ReversalRelativePosition: | 
|---|
|  |  |  | direction = new Vector2(_direction.x, -_direction.y).normalized * m_Speed; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public enum DiffuseType | 
|---|
|  |  |  | this.enabled = true; | 
|---|
|  |  |  | if (!this.gameObject.activeInHierarchy) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | MoveUp, | 
|---|
|  |  |  | MoveDown, | 
|---|
|  |  |  | MoveLeft, | 
|---|
|  |  |  | MoveRight, | 
|---|
|  |  |  | RelativePosition, | 
|---|
|  |  |  | ReversalRelativePosition, | 
|---|
|  |  |  | this.SetActive(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void LateUpdate() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (Time.time < beginTime) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Time.time < endTime) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var delta = direction * Time.deltaTime * m_SpeedRatioCurve.Evaluate((Time.time - beginTime) / duration); | 
|---|
|  |  |  | if (isLocal) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | this.transform.localPosition += new Vector3(delta.x, delta.y, 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | this.transform.position += new Vector3(delta.x, delta.y, 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (disableOnEnd) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | this.enabled = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public enum DiffuseType | 
|---|
|  |  |  | { | 
|---|
|  |  |  | MoveUp, | 
|---|
|  |  |  | MoveDown, | 
|---|
|  |  |  | MoveLeft, | 
|---|
|  |  |  | MoveRight, | 
|---|
|  |  |  | RelativePosition, | 
|---|
|  |  |  | ReversalRelativePosition, | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|