using System; using System.IO; using UnityEngine; public class BigThumbnail : MonoBehaviour { public void Awake() { this.isEnabled = true; this.Init(); } private void Init() { if (this.sprite_ == null) { this.CheckCreateFrame(); this.sprite_ = UTY.GetChildObject(base.gameObject, "Image", false).GetComponent(); this.bg_sprite_ = base.gameObject.GetComponent(); this.frame_sprite_ = UTY.GetChildObject(base.gameObject, "Frame", false).GetComponent(); this.alpha = 0f; } } public void OnDestroy() { if (this.sprite_.sprite2D != null && this.sprite_.sprite2D.texture != null) { UnityEngine.Object.DestroyImmediate(this.sprite_.sprite2D.texture); } if (this.bg_sprite_.sprite2D != null && this.bg_sprite_.sprite2D.texture != null) { UnityEngine.Object.DestroyImmediate(this.bg_sprite_.sprite2D.texture); } if (this.frame_sprite_.sprite2D != null && this.frame_sprite_.sprite2D.texture != null) { UnityEngine.Object.DestroyImmediate(this.frame_sprite_.sprite2D.texture); } this.sprite_.sprite2D = null; this.bg_sprite_.sprite2D = null; this.frame_sprite_.sprite2D = null; this.draw_tex_ = null; } public void SetMaid(Maid maid) { if (!this.isEnabled) { return; } this.Init(); this.alpha = 0f; if (this.sprite_.sprite2D != null && this.sprite_.sprite2D.texture != null) { UnityEngine.Object.DestroyImmediate(this.sprite_.sprite2D.texture); } this.sprite_.sprite2D = null; this.draw_tex_ = null; if (maid == null) { return; } this.draw_tex_ = maid.GetThumCard(); if (this.draw_tex_ == null) { return; } this.LoadFrameAndBG(); Sprite sprite = Sprite.Create(this.draw_tex_, new Rect(0f, 0f, (float)this.draw_tex_.width, (float)this.draw_tex_.height), default(Vector2)); sprite.name = maid.status.lastName + maid.status.firstName; this.sprite_.sprite2D = sprite; this.sprite_.SetDimensions(this.draw_tex_.width, this.draw_tex_.height); this.alpha = 1f; } public float alpha { get { this.Init(); return this.bg_sprite_.alpha; } set { this.Init(); this.bg_sprite_.alpha = value; } } public bool Visible { get { return base.gameObject.activeSelf; } set { base.gameObject.SetActive(value); } } public bool isEnabled { get; set; } private Texture2D draw_tex { get { return this.draw_tex_; } } private void CheckCreateFrame() { string str = UTY.gameProjectPath + "\\"; string text = str + "Thumb"; if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } string path = text + "/frame_single.png"; if (!File.Exists(path)) { Texture2D texture2D = Resources.Load("CharacterSelect/Atlas/DefaultFrame"); File.WriteAllBytes(path, texture2D.EncodeToPNG()); Resources.UnloadAsset(texture2D); } path = text + "/frame_back.png"; if (!File.Exists(path)) { Texture2D texture2D2 = Resources.Load("CharacterSelect/Atlas/DefaultFrameBack"); File.WriteAllBytes(path, texture2D2.EncodeToPNG()); Resources.UnloadAsset(texture2D2); } } private void LoadFrameAndBG() { this.CheckCreateFrame(); string str = UTY.gameProjectPath + "\\Thumb"; string f_strFileName = str + "/frame_back.png"; if (this.bg_sprite_.sprite2D == null) { Texture2D texture2D = UTY.LoadTexture(f_strFileName); if (texture2D != null) { int width = this.bg_sprite_.width; int height = this.bg_sprite_.height; Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)width, (float)height), default(Vector2)); sprite.name = "frame_back"; this.bg_sprite_.sprite2D = sprite; this.bg_sprite_.SetDimensions(width, height); } } if (this.frame_sprite_.sprite2D == null) { f_strFileName = str + "/frame_single.png"; Texture2D texture2D2 = UTY.LoadTexture(f_strFileName); if (texture2D2 != null) { int width2 = this.frame_sprite_.width; int height2 = this.frame_sprite_.height; Sprite sprite2 = Sprite.Create(texture2D2, new Rect(0f, 0f, (float)width2, (float)height2), default(Vector2)); sprite2.name = "frame_back"; this.frame_sprite_.sprite2D = sprite2; this.frame_sprite_.SetDimensions(width2, height2); } } } private Texture2D draw_tex_; private UI2DSprite sprite_; private UI2DSprite bg_sprite_; private UI2DSprite frame_sprite_; }