TaskUnit.cs 6.9 KB

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