YotogiOldStageUnit.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class YotogiOldStageUnit : 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(YotogiOldStageUnit.OnSelectEvent call_back)
  31. {
  32. this.on_select_event_ = call_back;
  33. }
  34. public void SetStageData(YotogiOld.Stage stage, bool enabled)
  35. {
  36. this.SetStageData(YotogiOld.stage_data_list[stage], enabled);
  37. }
  38. public void SetStageData(YotogiOld.StageData stage_data, bool enabled)
  39. {
  40. this.stage_data_ = stage_data;
  41. if (enabled)
  42. {
  43. this.name_label_.text = this.stage_data_.draw_name.ToString();
  44. }
  45. else
  46. {
  47. this.name_label_.text = "??????";
  48. }
  49. foreach (GameObject gameObject in this.star_parent_)
  50. {
  51. gameObject.SetActive(string.IsNullOrEmpty(stage_data.need_flag));
  52. }
  53. for (int j = 0; j < this.star_sprite_list_.Count; j++)
  54. {
  55. if (j < this.stage_data_.need_grade)
  56. {
  57. this.star_sprite_list_[j].enabled = true;
  58. }
  59. else
  60. {
  61. this.star_sprite_list_[j].enabled = false;
  62. }
  63. }
  64. string f_strFileName = this.stage_data_.thumbnail_name + ".tex";
  65. if (!enabled)
  66. {
  67. f_strFileName = "cm3d2_stageselectpreview_nowprinting.tex";
  68. }
  69. if (!GameUty.FileSystemOld.IsExistentFile(f_strFileName))
  70. {
  71. f_strFileName = "cm3d2_stageselectpreview_dammy.tex";
  72. }
  73. if (GameUty.FileSystemOld.IsExistentFile(f_strFileName))
  74. {
  75. Texture2D texture2D = ImportCM.CreateTexture(f_strFileName);
  76. Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  77. sprite.name = this.stage_data_.thumbnail_name;
  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. GameMain.Instance.BgMgr.ChangeBg(this.stage_data_.prefab_name);
  96. }
  97. if (this.on_select_event_ != null)
  98. {
  99. this.on_select_event_(this);
  100. }
  101. }
  102. public YotogiOld.StageData stage_data
  103. {
  104. get
  105. {
  106. return this.stage_data_;
  107. }
  108. }
  109. public UIWFTabButton button
  110. {
  111. get
  112. {
  113. return this.button_;
  114. }
  115. }
  116. public bool is_change_bg
  117. {
  118. get
  119. {
  120. return this.is_change_bg_;
  121. }
  122. set
  123. {
  124. this.is_change_bg_ = value;
  125. }
  126. }
  127. public UI2DSprite thumbnail_sprite
  128. {
  129. get
  130. {
  131. return this.thumbnail_sprite_;
  132. }
  133. }
  134. private YotogiOld.StageData stage_data_;
  135. private YotogiOldStageUnit.OnSelectEvent on_select_event_;
  136. private UILabel name_label_;
  137. private UI2DSprite thumbnail_sprite_;
  138. private List<UISprite> star_sprite_list_ = new List<UISprite>();
  139. private GameObject[] star_parent_;
  140. private UIWFTabButton button_;
  141. private bool is_change_bg_;
  142. public delegate void OnSelectEvent(YotogiOldStageUnit click_unit);
  143. }