YotogiStageUnit.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class YotogiStageUnit : MonoBehaviour
  6. {
  7. public void Awake()
  8. {
  9. GameObject childObject = UTY.GetChildObject(base.gameObject, "Parent", false);
  10. this.thumbnail_sprite_ = UTY.GetChildObject(childObject, "Icon", false).GetComponent<UI2DSprite>();
  11. EventDelegate.Add(childObject.GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.UpdateBG));
  12. this.button_ = childObject.GetComponent<UIWFTabButton>();
  13. this.name_label_ = UTY.GetChildObject(childObject, "Name", false).GetComponent<UILabel>();
  14. this.star_parent_ = new GameObject[2];
  15. this.star_parent_[0] = UTY.GetChildObject(childObject, "StarGroup", false);
  16. this.star_parent_[1] = UTY.GetChildObject(childObject, "StarMarkGroup", false);
  17. if (Product.supportMultiLanguage)
  18. {
  19. foreach (GameObject gameObject in this.star_parent_)
  20. {
  21. Vector3 localPosition = gameObject.transform.localPosition;
  22. gameObject.transform.localPosition = new Vector3(40f, localPosition.y, localPosition.z);
  23. UIGrid component = gameObject.GetComponent<UIGrid>();
  24. component.cellWidth = 22f;
  25. component.Reposition();
  26. }
  27. }
  28. Transform transform = UTY.GetChildObject(childObject, "StarGroup", false).transform;
  29. for (int j = 0; j < transform.childCount; j++)
  30. {
  31. this.star_sprite_list_.Add(transform.GetChild(j).GetComponent<UISprite>());
  32. }
  33. this.is_change_bg_ = true;
  34. }
  35. public void OnDestroy()
  36. {
  37. if (this.thumbnail_sprite_.sprite2D != null && this.thumbnail_sprite_.sprite2D.texture != null)
  38. {
  39. UnityEngine.Object.DestroyImmediate(this.thumbnail_sprite_.sprite2D.texture);
  40. }
  41. }
  42. public void SetOnSelectEvent(YotogiStageUnit.OnSelectEvent call_back)
  43. {
  44. this.on_select_event_ = call_back;
  45. }
  46. public void SetStageData(YotogiStage.Data stage_data, bool enabled, bool isDaytime)
  47. {
  48. this.stage_data_ = stage_data;
  49. this.is_daytime_ = isDaytime;
  50. if (enabled)
  51. {
  52. this.name_label_.text = this.stage_data_.drawName;
  53. Utility.SetLocalizeTerm(this.name_label_, stage_data.termName, false);
  54. }
  55. else
  56. {
  57. this.name_label_.text = "??????";
  58. }
  59. foreach (GameObject gameObject in this.star_parent_)
  60. {
  61. gameObject.SetActive(true);
  62. }
  63. for (int j = 0; j < this.star_sprite_list_.Count; j++)
  64. {
  65. if (j < this.stage_data_.drawClubGrade)
  66. {
  67. this.star_sprite_list_[j].enabled = true;
  68. }
  69. else
  70. {
  71. this.star_sprite_list_[j].enabled = false;
  72. }
  73. }
  74. int num = (!isDaytime) ? 1 : 0;
  75. string text = this.stage_data_.thumbnailName[num];
  76. text = ScriptManager.ReplacePersonal(GameMain.Instance.CharacterMgr.GetMaid(0), text);
  77. if (!enabled)
  78. {
  79. text = "cm3d2_stageselectpreview_nowprinting.tex";
  80. }
  81. AFileSystemBase afileSystemBase = (!GameUty.FileSystemOld.IsExistentFile(text)) ? GameUty.FileSystem : GameUty.FileSystemOld;
  82. if (!afileSystemBase.IsExistentFile(text))
  83. {
  84. text = "cm3d2_stageselectpreview_dammy.tex";
  85. }
  86. if (afileSystemBase.IsExistentFile(text))
  87. {
  88. Texture2D texture2D = ImportCM.CreateTexture(afileSystemBase, text);
  89. Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  90. sprite.name = stage_data.drawName;
  91. if (this.thumbnail_sprite_.sprite2D != null && this.thumbnail_sprite_.sprite2D.texture != null)
  92. {
  93. UnityEngine.Object.DestroyImmediate(this.thumbnail_sprite_.sprite2D.texture);
  94. }
  95. this.thumbnail_sprite_.sprite2D = sprite;
  96. this.thumbnail_sprite_.SetDimensions(texture2D.width, texture2D.height);
  97. }
  98. this.button_.isEnabled = enabled;
  99. }
  100. public void UpdateBG()
  101. {
  102. if (this.stage_data_ == null)
  103. {
  104. return;
  105. }
  106. if (this.is_change_bg)
  107. {
  108. int num = (!GameMain.Instance.CharacterMgr.status.isDaytime) ? 1 : 0;
  109. GameMain.Instance.BgMgr.ChangeBg(this.stage_data_.prefabName[num]);
  110. }
  111. if (this.on_select_event_ != null)
  112. {
  113. this.on_select_event_(this);
  114. }
  115. }
  116. public YotogiStage.Data stage_data
  117. {
  118. get
  119. {
  120. return this.stage_data_;
  121. }
  122. }
  123. public bool is_daytime
  124. {
  125. get
  126. {
  127. return this.is_daytime_;
  128. }
  129. }
  130. public UIWFTabButton button
  131. {
  132. get
  133. {
  134. return this.button_;
  135. }
  136. }
  137. public bool is_change_bg
  138. {
  139. get
  140. {
  141. return this.is_change_bg_;
  142. }
  143. set
  144. {
  145. this.is_change_bg_ = value;
  146. }
  147. }
  148. public UI2DSprite thumbnail_sprite
  149. {
  150. get
  151. {
  152. return this.thumbnail_sprite_;
  153. }
  154. }
  155. private YotogiStage.Data stage_data_;
  156. private bool is_daytime_;
  157. private YotogiStageUnit.OnSelectEvent on_select_event_;
  158. private UILabel name_label_;
  159. private UI2DSprite thumbnail_sprite_;
  160. private List<UISprite> star_sprite_list_ = new List<UISprite>();
  161. private GameObject[] star_parent_;
  162. private UIWFTabButton button_;
  163. private bool is_change_bg_;
  164. public delegate void OnSelectEvent(YotogiStageUnit click_unit);
  165. }