123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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<UI2DSprite>();
- this.bg_sprite_ = base.gameObject.GetComponent<UI2DSprite>();
- this.frame_sprite_ = UTY.GetChildObject(base.gameObject, "Frame", false).GetComponent<UI2DSprite>();
- 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 fullPath = Path.GetFullPath(".\\");
- string text = fullPath + "Thumb";
- if (!Directory.Exists(text))
- {
- Directory.CreateDirectory(text);
- }
- string path = text + "/frame_single.png";
- if (!File.Exists(path))
- {
- Texture2D texture2D = Resources.Load<Texture2D>("CharacterSelect/Atlas/DefaultFrame");
- File.WriteAllBytes(path, texture2D.EncodeToPNG());
- Resources.UnloadAsset(texture2D);
- }
- path = text + "/frame_back.png";
- if (!File.Exists(path))
- {
- Texture2D texture2D2 = Resources.Load<Texture2D>("CharacterSelect/Atlas/DefaultFrameBack");
- File.WriteAllBytes(path, texture2D2.EncodeToPNG());
- Resources.UnloadAsset(texture2D2);
- }
- }
- private void LoadFrameAndBG()
- {
- this.CheckCreateFrame();
- string str = Path.GetFullPath(".\\") + "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_;
- }
|