ActionDirect.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class ActionDirect : MonoBehaviour
  5. {
  6. public static ActionDirect Instance { get; private set; }
  7. private void Start()
  8. {
  9. ActionDirect.Instance = this;
  10. base.gameObject.SetActive(false);
  11. }
  12. private void UIMove(float time)
  13. {
  14. float current_time;
  15. if (time <= this.m_MoveTime / 2f + this.m_StopTime)
  16. {
  17. current_time = Mathf.Min(time, this.m_MoveTime / 2f);
  18. }
  19. else
  20. {
  21. current_time = time - (this.m_StopTime + this.m_MoveTime / 2f);
  22. }
  23. float x = this.m_ParentCanvas.sizeDelta.x;
  24. if (time <= this.m_MoveTime / 2f)
  25. {
  26. base.transform.localPosition = Vector3.Lerp(Vector3.right * x, Vector3.zero, KasaiUtility.SinRate01(current_time, this.m_MoveTime / 2f, false, false));
  27. }
  28. else if (time > this.m_MoveTime / 2f + this.m_StopTime)
  29. {
  30. base.transform.localPosition = Vector3.Lerp(Vector3.zero, Vector3.left * x, KasaiUtility.SinRate01(current_time, this.m_MoveTime / 2f, false, false));
  31. }
  32. }
  33. private void MoveEnd()
  34. {
  35. if (this.MoveendCall != null)
  36. {
  37. this.MoveendCall();
  38. }
  39. this.MoveendCall = null;
  40. base.gameObject.SetActive(false);
  41. }
  42. public void ActionStart(string action)
  43. {
  44. base.gameObject.SetActive(true);
  45. IEnumerator enumerator = this.m_ActionImage.GetEnumerator();
  46. try
  47. {
  48. while (enumerator.MoveNext())
  49. {
  50. object obj = enumerator.Current;
  51. Transform transform = (Transform)obj;
  52. transform.gameObject.SetActive(transform.name == action);
  53. }
  54. }
  55. finally
  56. {
  57. IDisposable disposable;
  58. if ((disposable = (enumerator as IDisposable)) != null)
  59. {
  60. disposable.Dispose();
  61. }
  62. }
  63. base.StartCoroutine(KasaiUtility.TimeCroutine(this.m_MoveTime + this.m_StopTime, new Action<float>(this.UIMove), new Action(this.MoveEnd)));
  64. }
  65. [SerializeField]
  66. private Transform m_ActionImage;
  67. [SerializeField]
  68. private RectTransform m_ParentCanvas;
  69. [SerializeField]
  70. private float m_MoveTime = 0.75f;
  71. [SerializeField]
  72. private float m_StopTime = 0.25f;
  73. public Action MoveendCall;
  74. }