YotogiStageUnit.cs 4.6 KB

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