Tutor.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. public class Tutor : MonoBehaviour
  5. {
  6. private bool InfinitelyTraining
  7. {
  8. get
  9. {
  10. return GameObject.Find("InfinitelyTraining");
  11. }
  12. }
  13. private static Tutor _instance;
  14. public GameObject ArrowDown;
  15. public GameObject ArrowLeft;
  16. public GameObject ArrowRight;
  17. public GameObject ArrowUp;
  18. public GameObject ImageInfo;
  19. public GameObject ObjKillAnOrc;
  20. public GameObject ObjBreakTheChest;
  21. public GameObject ObjEnrage;
  22. public GameObject Colliders;
  23. private bool _tutorPassed = false;
  24. public static bool TutorPassed
  25. {
  26. get { return _instance._tutorPassed && !_instance.InfinitelyTraining; }
  27. }
  28. void Start ()
  29. {
  30. _tutorPassed = PlayerPrefs.GetInt("TutorPassed", 0) == 1;
  31. _instance = this;
  32. ArrowDown.SetActive(false);
  33. ArrowLeft.SetActive(false);
  34. ArrowRight.SetActive(false);
  35. ArrowUp.SetActive(false);
  36. // ObjKillAnOrc.SetActive(false);
  37. // ObjBreakTheChest.SetActive(false);
  38. //ObjEnrage.SetActive(false);
  39. }
  40. public static void ActivateColliders()
  41. {
  42. if (_instance && _instance.Colliders)
  43. {
  44. _instance.Colliders.SetActive(true);
  45. }
  46. }
  47. public static void Down()
  48. {
  49. if (_instance._tutorPassed && !_instance.InfinitelyTraining)
  50. {
  51. return;
  52. }
  53. _instance.StartCoroutine(_instance.Show(_instance.ArrowDown, new Vector3(0, -1, 0), 10));
  54. }
  55. public static void Left()
  56. {
  57. if (_instance._tutorPassed && !_instance.InfinitelyTraining)
  58. {
  59. return;
  60. }
  61. _instance.StartCoroutine(_instance.Show(_instance.ArrowLeft, new Vector3(-1, 0, 0), 10));
  62. }
  63. public static void Info()
  64. {
  65. if (_instance._tutorPassed && !_instance.InfinitelyTraining)
  66. {
  67. return;
  68. }
  69. _instance.StartCoroutine(_instance.Show(_instance.ImageInfo, new Vector3(0, 1, 0), 1));
  70. }
  71. public static void Right()
  72. {
  73. if (_instance._tutorPassed && !_instance.InfinitelyTraining)
  74. {
  75. return;
  76. }
  77. _instance.StartCoroutine(_instance.Show(_instance.ArrowRight, new Vector3(1, 0, 0), 10));
  78. }
  79. public static void Up()
  80. {
  81. if (_instance._tutorPassed && !_instance.InfinitelyTraining)
  82. {
  83. return;
  84. }
  85. _instance.StartCoroutine(_instance.Show(_instance.ArrowUp, new Vector3(0, 1, 0), 10));
  86. }
  87. public static void BreakChest()
  88. {
  89. if (_instance._tutorPassed && !_instance.InfinitelyTraining)
  90. {
  91. return;
  92. }
  93. _instance.StartCoroutine(_instance.Scale(_instance.ObjBreakTheChest, new Vector3(0.0001f, 0.0001f, 0), 50));
  94. }
  95. public static void KillAnOrc()
  96. {
  97. if (_instance._tutorPassed && !_instance.InfinitelyTraining)
  98. {
  99. return;
  100. }
  101. _instance.StartCoroutine(_instance.Scale(_instance.ObjKillAnOrc, new Vector3(0.0001f, 0.0001f, 0), 50));
  102. }
  103. public static void Enrage()
  104. {
  105. if (_instance._tutorPassed && !_instance.InfinitelyTraining)
  106. {
  107. return;
  108. }
  109. _instance.StartCoroutine(_instance.Scale(_instance.ObjEnrage, new Vector3(0.0001f, 0.0001f, 0), 50));
  110. }
  111. private IEnumerator Show(GameObject obj, Vector3 way, float dist)
  112. {
  113. if (obj.name == "TutorDone")
  114. {
  115. Debug.Log("TutorDone");
  116. LoginManager.Instance.TutorDone.gameObject.SetActive(true);
  117. yield return new WaitForSeconds(3.14f);
  118. LoginManager.Instance.TutorDone.gameObject.SetActive(false);
  119. yield break;
  120. }
  121. obj.transform.localPosition = way * 3 * -dist;
  122. obj.SetActive(true);
  123. var move = 0;
  124. while (move++ < dist)
  125. {
  126. yield return new WaitForSeconds(0.02f);
  127. obj.transform.localPosition += way * 3 * move;
  128. }
  129. if (obj.name == "TutorDone")
  130. {
  131. LoginManager.Instance.TutorDone.gameObject.SetActive(false);
  132. //LoginManager.Instance.TutorDone.Hide();
  133. }
  134. obj.SetActive(false);
  135. }
  136. private IEnumerator Scale(GameObject obj, Vector3 way, float dist)
  137. {
  138. Vector3 baseScale = obj.transform.localScale;
  139. obj.SetActive(true);
  140. var move = 0;
  141. while (move++ < dist)
  142. {
  143. yield return new WaitForSeconds(0.03f);
  144. obj.transform.localScale += way;
  145. }
  146. obj.SetActive(false);
  147. obj.transform.localScale = baseScale;
  148. }
  149. public static void Passed()
  150. {
  151. _instance._tutorPassed = true;
  152. PlayerPrefs.SetInt("TutorPassed", 1);
  153. PlayerPrefs.Save();
  154. }
  155. }