YotogiStageUnit.cs 4.2 KB

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