MemoryObject.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using DG.Tweening;
  7. public class MemoryObject : MonoBehaviour
  8. {
  9. [SerializeField] GameObject CurrentMemoryObject;
  10. public List<MemoryTab> memoryTabs = new List<MemoryTab>();
  11. [SerializeField] MemoryPredictionLine memoryPredictionLine;
  12. int oldMemory = 0;
  13. public void Init()
  14. {
  15. AssignMemoryTab();
  16. memoryPredictionLine.Init();
  17. foreach (MemoryTab memoryTab in memoryTabs)
  18. {
  19. memoryTab.Init();
  20. }
  21. }
  22. public void AssignMemoryTab()
  23. {
  24. bool isMasterClient = GManager.instance.You.PlayerID == 0;
  25. for (int i = 0; i < memoryTabs.Count; i++)
  26. {
  27. if (isMasterClient)
  28. {
  29. memoryTabs[i].Memory = i - 10;
  30. }
  31. else
  32. {
  33. memoryTabs[i].Memory = 10 - i;
  34. }
  35. }
  36. }
  37. public IEnumerator SetMemory()
  38. {
  39. if (oldMemory != GManager.instance.turnStateMachine.gameContext.Memory)
  40. {
  41. bool isMasterClient = GManager.instance.You.PlayerID == 0;
  42. MemoryTab targetMemoryTab = null;
  43. MemoryTab currentMemoryTab = null;
  44. foreach (MemoryTab memoryTab in memoryTabs)
  45. {
  46. if (memoryTab.Memory == GManager.instance.turnStateMachine.gameContext.Memory)
  47. {
  48. targetMemoryTab = memoryTab;
  49. }
  50. if (memoryTab.Memory == oldMemory)
  51. {
  52. currentMemoryTab = memoryTab;
  53. }
  54. }
  55. if (targetMemoryTab != null)
  56. {
  57. List<MemoryTab> lightMemoryTabs = new List<MemoryTab>();
  58. int startIndex = memoryTabs.IndexOf(currentMemoryTab);
  59. int endIndex = memoryTabs.IndexOf(targetMemoryTab);
  60. if (startIndex < endIndex)
  61. {
  62. for (int i = 0; i < memoryTabs.Count; i++)
  63. {
  64. if (startIndex <= i && i <= endIndex)
  65. {
  66. lightMemoryTabs.Add(memoryTabs[i]);
  67. }
  68. }
  69. }
  70. else
  71. {
  72. for (int i = 0; i < memoryTabs.Count; i++)
  73. {
  74. if (endIndex <= i && i <= startIndex)
  75. {
  76. lightMemoryTabs.Add(memoryTabs[i]);
  77. }
  78. }
  79. }
  80. foreach (MemoryTab memoryTab in lightMemoryTabs)
  81. {
  82. if (memoryTab.Light != null)
  83. {
  84. memoryTab.Light.SetActive(true);
  85. }
  86. }
  87. #region ƒAƒjƒ��[ƒVƒ‡ƒ“
  88. bool end = false;
  89. var sequence = DOTween.Sequence();
  90. Vector3 TargetPosition = targetMemoryTab.tabObject.transform.localPosition;
  91. float GoTime = 0.2f;
  92. sequence
  93. .Append(CurrentMemoryObject.transform.DOLocalMove(TargetPosition, GoTime).SetEase(Ease.OutCubic))
  94. .AppendCallback(() =>
  95. {
  96. end = true;
  97. });
  98. sequence.Play();
  99. yield return new WaitWhile(() => !end);
  100. end = false;
  101. #endregion
  102. #region setting used blitz
  103. if (GManager.instance.attackProcess.UsedBlitz)
  104. {
  105. if (GManager.instance.turnStateMachine.gameContext.Memory <= 0)
  106. GManager.instance.attackProcess.UsedBlitz = false;
  107. }
  108. #endregion
  109. }
  110. }
  111. foreach (MemoryTab memoryTab in memoryTabs)
  112. {
  113. if (memoryTab.Light != null)
  114. {
  115. memoryTab.Light.SetActive(false);
  116. }
  117. }
  118. oldMemory = GManager.instance.turnStateMachine.gameContext.Memory;
  119. }
  120. public void ShowMemoryPredictionLine(int nextMemory)
  121. {
  122. if (nextMemory >= 10)
  123. {
  124. nextMemory = 10;
  125. }
  126. else if (nextMemory <= -10)
  127. {
  128. nextMemory = -10;
  129. }
  130. MemoryTab currentMemoryTab = null;
  131. MemoryTab nextMemoryTab = null;
  132. foreach (MemoryTab memoryTab in memoryTabs)
  133. {
  134. if (memoryTab.Memory == GManager.instance.turnStateMachine.gameContext.Memory)
  135. {
  136. currentMemoryTab = memoryTab;
  137. }
  138. if (memoryTab.Memory == nextMemory)
  139. {
  140. nextMemoryTab = memoryTab;
  141. }
  142. }
  143. if (currentMemoryTab != null && nextMemoryTab != null)
  144. {
  145. memoryPredictionLine.SetMemoryPredictionLine(currentMemoryTab, nextMemoryTab);
  146. }
  147. else
  148. {
  149. OffMemoryPredictionLine();
  150. }
  151. }
  152. public void OffMemoryPredictionLine()
  153. {
  154. memoryPredictionLine.gameObject.SetActive(false);
  155. }
  156. }
  157. [Serializable]
  158. public class MemoryTab
  159. {
  160. public int Memory { get; set; }
  161. public GameObject tabObject;
  162. public GameObject Light
  163. {
  164. get
  165. {
  166. if (tabObject != null)
  167. {
  168. if (tabObject.transform.childCount >= 2)
  169. {
  170. return tabObject.transform.GetChild(tabObject.transform.childCount - 2).gameObject;
  171. }
  172. }
  173. return null;
  174. }
  175. }
  176. public void Init()
  177. {
  178. if (Light != null)
  179. {
  180. Light.SetActive(false);
  181. }
  182. }
  183. }