TaskUnit.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Schedule;
  5. using UnityEngine;
  6. public class TaskUnit : MonoBehaviour
  7. {
  8. public ScheduleCSVData.ScheduleBase schedule { get; protected set; }
  9. public bool isSelected
  10. {
  11. get
  12. {
  13. return this.SelectCursor.alpha != 0f;
  14. }
  15. }
  16. public void Init(ScheduleTaskViewer taskViewer)
  17. {
  18. this.viewer = taskViewer;
  19. this.Icon = UTY.GetChildObject(base.gameObject, "Main", false).GetComponent<UITexture>();
  20. this.Button = this.Icon.GetComponent<UIButton>();
  21. this.SelectCursor = UTY.GetChildObject(base.gameObject, "Main/SelectCursor", false).GetComponent<UISprite>();
  22. this.TitleLabel = UTY.GetChildObject(base.gameObject, "Title", false).GetComponent<UILabel>();
  23. this.AddOnClickEvent();
  24. this.onHoverOverEvent = new Action<ScheduleCSVData.ScheduleBase>(this.viewer.onHoverOverEvent);
  25. this.onHoverOutEvent = new Action<ScheduleCSVData.ScheduleBase>(this.viewer.onHoverOutEvent);
  26. UIEventTrigger[] componentsInChildren = base.GetComponentsInChildren<UIEventTrigger>();
  27. foreach (UIEventTrigger uieventTrigger in componentsInChildren)
  28. {
  29. uieventTrigger.onHoverOut.Clear();
  30. EventDelegate.Add(uieventTrigger.onHoverOut, new EventDelegate.Callback(this.OnHoverOut));
  31. uieventTrigger.onHoverOver.Clear();
  32. EventDelegate.Add(uieventTrigger.onHoverOver, new EventDelegate.Callback(this.OnHoverOver));
  33. }
  34. }
  35. private void Update()
  36. {
  37. this.Monitor();
  38. }
  39. protected virtual void Monitor()
  40. {
  41. }
  42. protected virtual void AddOnClickEvent()
  43. {
  44. EventDelegate eventDelegate = new EventDelegate(this.viewer, "OnClickTaskUnit");
  45. eventDelegate.parameters[0].value = this;
  46. EventDelegate.Add(this.Button.onClick, eventDelegate);
  47. }
  48. public void SetData(ScheduleTaskCtrl.TaskType taskType, ScheduleTaskViewer viewer, ScheduleTaskViewer.ViewData viewData)
  49. {
  50. this.taskType = taskType;
  51. this.viewer = viewer;
  52. this.viewData = viewData;
  53. this.schedule = viewData.schedule;
  54. this.taskName = this.schedule.name;
  55. this.SelectCursor.alpha = 0f;
  56. this.TitleLabel.text = this.schedule.name;
  57. this.Icon.mainTexture = viewer.TmpData(taskType).icons[this.schedule.icon];
  58. }
  59. public bool isEnabled
  60. {
  61. get
  62. {
  63. return this.Button.isEnabled;
  64. }
  65. set
  66. {
  67. this.Button.isEnabled = value;
  68. this.TitleLabel.color = ((!this.Button.isEnabled) ? Color.gray : Color.white);
  69. }
  70. }
  71. public void SetSelect(bool is_select)
  72. {
  73. if (is_select && this.isEnabled)
  74. {
  75. this.SelectCursor.alpha = 1f;
  76. this.Button.defaultColor = Color.white;
  77. this.Button.SetState(UIButtonColor.State.Normal, false);
  78. BoxCollider component = this.Button.GetComponent<BoxCollider>();
  79. if (component != null)
  80. {
  81. component.size = Vector3.zero;
  82. }
  83. }
  84. else
  85. {
  86. this.SelectCursor.alpha = 0f;
  87. this.Button.defaultColor = this.backup_default_color_;
  88. BoxCollider component2 = this.Button.GetComponent<BoxCollider>();
  89. if (component2 != null)
  90. {
  91. UIWidget component3 = this.Button.GetComponent<UIWidget>();
  92. if (component3 != null)
  93. {
  94. Vector2 localSize = component3.localSize;
  95. component2.size = new Vector3(localSize.x, localSize.y, 0f);
  96. }
  97. }
  98. }
  99. }
  100. protected virtual void OnHoverOver()
  101. {
  102. if (this.onHoverOverEvent == null)
  103. {
  104. return;
  105. }
  106. this.onHoverOverEvent(this.schedule);
  107. this.isHover = true;
  108. }
  109. protected virtual void OnHoverOut()
  110. {
  111. if (this.onHoverOutEvent == null)
  112. {
  113. return;
  114. }
  115. this.onHoverOutEvent(this.schedule);
  116. this.isHover = false;
  117. }
  118. protected void SetTaskRank(GameObject go, int rank)
  119. {
  120. List<GameObject> list = new List<GameObject>();
  121. GameObject childObject = UTY.GetChildObject(go, "Stars/Icon", false);
  122. IEnumerator enumerator = childObject.transform.GetEnumerator();
  123. try
  124. {
  125. while (enumerator.MoveNext())
  126. {
  127. object obj = enumerator.Current;
  128. Transform transform = (Transform)obj;
  129. list.Add(transform.gameObject);
  130. }
  131. }
  132. finally
  133. {
  134. IDisposable disposable;
  135. if ((disposable = (enumerator as IDisposable)) != null)
  136. {
  137. disposable.Dispose();
  138. }
  139. }
  140. int count = list.Count;
  141. for (int i = 0; i < count; i++)
  142. {
  143. if (rank > i)
  144. {
  145. list[i].SetActive(true);
  146. }
  147. else
  148. {
  149. list[i].SetActive(false);
  150. }
  151. }
  152. }
  153. protected void SetExpRatio(GameObject go, int expRatio)
  154. {
  155. List<GameObject> list = new List<GameObject>();
  156. GameObject childObject = UTY.GetChildObject(go, "ExpRatio/ValueGroup", false);
  157. IEnumerator enumerator = childObject.transform.GetEnumerator();
  158. try
  159. {
  160. while (enumerator.MoveNext())
  161. {
  162. object obj = enumerator.Current;
  163. Transform transform = (Transform)obj;
  164. list.Add(transform.gameObject);
  165. }
  166. }
  167. finally
  168. {
  169. IDisposable disposable;
  170. if ((disposable = (enumerator as IDisposable)) != null)
  171. {
  172. disposable.Dispose();
  173. }
  174. }
  175. int count = list.Count;
  176. for (int i = 0; i < count; i++)
  177. {
  178. if (expRatio > i)
  179. {
  180. list[i].SetActive(true);
  181. }
  182. else
  183. {
  184. list[i].SetActive(false);
  185. }
  186. }
  187. }
  188. public void AdjustmentTitlePos(GameObject obj, ScheduleTaskCtrl.TaskButton taskButton, bool active = true)
  189. {
  190. UTY.GetChildObject(obj, "Stars", false).SetActive(active);
  191. UTY.GetChildObject(obj, "ExpRatio", false).SetActive(active);
  192. Transform transform = UTY.GetChildObject(obj, "Title", false).transform;
  193. Vector3 localPosition = transform.localPosition;
  194. localPosition.y = -27f;
  195. if (this.taskType == ScheduleTaskCtrl.TaskType.Training)
  196. {
  197. ScheduleTaskCtrl.TrainingTaskButton trainingTaskButton = (ScheduleTaskCtrl.TrainingTaskButton)taskButton;
  198. if (trainingTaskButton.type == ScheduleCSVData.TrainingType.Travel)
  199. {
  200. localPosition.y = -55f;
  201. }
  202. }
  203. if (this.taskType == ScheduleTaskCtrl.TaskType.Work && ScheduleCSVData.faclilityPowerUpWorkId == this.schedule.id)
  204. {
  205. localPosition.y = -51f;
  206. }
  207. transform.localPosition = localPosition;
  208. }
  209. protected ScheduleTaskViewer viewer;
  210. protected ScheduleTaskViewer.ViewData viewData;
  211. public GameObject removePrarent;
  212. [SerializeField]
  213. private bool isHover;
  214. public Action<ScheduleCSVData.ScheduleBase> onHoverOverEvent;
  215. public Action<ScheduleCSVData.ScheduleBase> onHoverOutEvent;
  216. [SerializeField]
  217. protected string taskName;
  218. public UITexture Icon;
  219. public UIButton Button;
  220. public UISprite SelectCursor;
  221. public UILabel TitleLabel;
  222. public ScheduleTaskCtrl.TaskType taskType;
  223. protected Color backup_default_color_ = new Color(1f, 1f, 1f, 0.6f);
  224. }