using System; using System.Collections.Generic; using UnityEngine; public class YotogiOldStageUnit : MonoBehaviour { public void Awake() { GameObject childObject = UTY.GetChildObject(base.gameObject, "Parent", false); this.thumbnail_sprite_ = UTY.GetChildObject(childObject, "Icon", false).GetComponent(); EventDelegate.Add(childObject.GetComponent().onClick, new EventDelegate.Callback(this.UpdateBG)); this.button_ = childObject.GetComponent(); this.name_label_ = UTY.GetChildObject(childObject, "Name", false).GetComponent(); this.star_parent_ = new GameObject[2]; this.star_parent_[0] = UTY.GetChildObject(childObject, "StarGroup", false); this.star_parent_[1] = UTY.GetChildObject(childObject, "StarMarkGroup", false); Transform transform = UTY.GetChildObject(childObject, "StarGroup", false).transform; for (int i = 0; i < transform.childCount; i++) { this.star_sprite_list_.Add(transform.GetChild(i).GetComponent()); } this.is_change_bg_ = true; } public void OnDestroy() { if (this.thumbnail_sprite_.sprite2D != null && this.thumbnail_sprite_.sprite2D.texture != null) { UnityEngine.Object.DestroyImmediate(this.thumbnail_sprite_.sprite2D.texture); } } public void SetOnSelectEvent(YotogiOldStageUnit.OnSelectEvent call_back) { this.on_select_event_ = call_back; } public void SetStageData(YotogiOld.Stage stage, bool enabled) { this.SetStageData(YotogiOld.stage_data_list[stage], enabled); } public void SetStageData(YotogiOld.StageData stage_data, bool enabled) { this.stage_data_ = stage_data; if (enabled) { this.name_label_.text = this.stage_data_.draw_name.ToString(); } else { this.name_label_.text = "??????"; } foreach (GameObject gameObject in this.star_parent_) { gameObject.SetActive(string.IsNullOrEmpty(stage_data.need_flag)); } for (int j = 0; j < this.star_sprite_list_.Count; j++) { if (j < this.stage_data_.need_grade) { this.star_sprite_list_[j].enabled = true; } else { this.star_sprite_list_[j].enabled = false; } } string f_strFileName = this.stage_data_.thumbnail_name + ".tex"; if (!enabled) { f_strFileName = "cm3d2_stageselectpreview_nowprinting.tex"; } if (!GameUty.FileSystemOld.IsExistentFile(f_strFileName)) { f_strFileName = "cm3d2_stageselectpreview_dammy.tex"; } if (GameUty.FileSystemOld.IsExistentFile(f_strFileName)) { Texture2D texture2D = ImportCM.CreateTexture(f_strFileName); Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2)); sprite.name = this.stage_data_.thumbnail_name; if (this.thumbnail_sprite_.sprite2D != null && this.thumbnail_sprite_.sprite2D.texture != null) { UnityEngine.Object.DestroyImmediate(this.thumbnail_sprite_.sprite2D.texture); } this.thumbnail_sprite_.sprite2D = sprite; this.thumbnail_sprite_.SetDimensions(texture2D.width, texture2D.height); } this.button_.isEnabled = enabled; } public void UpdateBG() { if (this.stage_data_ == null) { return; } if (this.is_change_bg) { GameMain.Instance.BgMgr.ChangeBg(this.stage_data_.prefab_name); } if (this.on_select_event_ != null) { this.on_select_event_(this); } } public YotogiOld.StageData stage_data { get { return this.stage_data_; } } public UIWFTabButton button { get { return this.button_; } } public bool is_change_bg { get { return this.is_change_bg_; } set { this.is_change_bg_ = value; } } public UI2DSprite thumbnail_sprite { get { return this.thumbnail_sprite_; } } private YotogiOld.StageData stage_data_; private YotogiOldStageUnit.OnSelectEvent on_select_event_; private UILabel name_label_; private UI2DSprite thumbnail_sprite_; private List star_sprite_list_ = new List(); private GameObject[] star_parent_; private UIWFTabButton button_; private bool is_change_bg_; public delegate void OnSelectEvent(YotogiOldStageUnit click_unit); }