YotogiStageUnit.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. AFileSystemBase afileSystemBase = (!GameUty.FileSystemOld.IsExistentFile(text)) ? GameUty.FileSystem : GameUty.FileSystemOld;
  69. if (!afileSystemBase.IsExistentFile(text))
  70. {
  71. text = "cm3d2_stageselectpreview_dammy.tex";
  72. }
  73. if (afileSystemBase.IsExistentFile(text))
  74. {
  75. Texture2D texture2D = ImportCM.CreateTexture(afileSystemBase, text);
  76. Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  77. sprite.name = stage_data.drawName;
  78. if (this.thumbnail_sprite_.sprite2D != null && this.thumbnail_sprite_.sprite2D.texture != null)
  79. {
  80. UnityEngine.Object.DestroyImmediate(this.thumbnail_sprite_.sprite2D.texture);
  81. }
  82. this.thumbnail_sprite_.sprite2D = sprite;
  83. this.thumbnail_sprite_.SetDimensions(texture2D.width, texture2D.height);
  84. }
  85. this.button_.isEnabled = enabled;
  86. }
  87. public void UpdateBG()
  88. {
  89. if (this.stage_data_ == null)
  90. {
  91. return;
  92. }
  93. if (this.is_change_bg)
  94. {
  95. int num = (!GameMain.Instance.CharacterMgr.status.isDaytime) ? 1 : 0;
  96. GameMain.Instance.BgMgr.ChangeBg(this.stage_data_.prefabName[num]);
  97. }
  98. if (this.on_select_event_ != null)
  99. {
  100. this.on_select_event_(this);
  101. }
  102. }
  103. public YotogiStage.Data stage_data
  104. {
  105. get
  106. {
  107. return this.stage_data_;
  108. }
  109. }
  110. public bool is_daytime
  111. {
  112. get
  113. {
  114. return this.is_daytime_;
  115. }
  116. }
  117. public UIWFTabButton button
  118. {
  119. get
  120. {
  121. return this.button_;
  122. }
  123. }
  124. public bool is_change_bg
  125. {
  126. get
  127. {
  128. return this.is_change_bg_;
  129. }
  130. set
  131. {
  132. this.is_change_bg_ = value;
  133. }
  134. }
  135. public UI2DSprite thumbnail_sprite
  136. {
  137. get
  138. {
  139. return this.thumbnail_sprite_;
  140. }
  141. }
  142. private YotogiStage.Data stage_data_;
  143. private bool is_daytime_;
  144. private YotogiStageUnit.OnSelectEvent on_select_event_;
  145. private UILabel name_label_;
  146. private UI2DSprite thumbnail_sprite_;
  147. private List<UISprite> star_sprite_list_ = new List<UISprite>();
  148. private GameObject[] star_parent_;
  149. private UIWFTabButton button_;
  150. private bool is_change_bg_;
  151. public delegate void OnSelectEvent(YotogiStageUnit click_unit);
  152. }