YotogiStageUnit.cs 4.1 KB

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