BigThumbnail.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. public class BigThumbnail : MonoBehaviour
  5. {
  6. public string ThumbnailDictionary
  7. {
  8. get
  9. {
  10. return Path.Combine(GameMain.Instance.SerializeStorageManager.StoreDirectoryPath, "Thumb");
  11. }
  12. }
  13. public void Awake()
  14. {
  15. this.isEnabled = true;
  16. this.Init();
  17. }
  18. private void Init()
  19. {
  20. if (this.sprite_ == null)
  21. {
  22. this.CheckCreateFrame();
  23. this.sprite_ = UTY.GetChildObject(base.gameObject, "Image", false).GetComponent<UI2DSprite>();
  24. this.bg_sprite_ = base.gameObject.GetComponent<UI2DSprite>();
  25. this.frame_sprite_ = UTY.GetChildObject(base.gameObject, "Frame", false).GetComponent<UI2DSprite>();
  26. this.alpha = 0f;
  27. }
  28. }
  29. public void OnDestroy()
  30. {
  31. if (this.sprite_.sprite2D != null && this.sprite_.sprite2D.texture != null)
  32. {
  33. UnityEngine.Object.DestroyImmediate(this.sprite_.sprite2D.texture);
  34. }
  35. if (this.bg_sprite_.sprite2D != null && this.bg_sprite_.sprite2D.texture != null)
  36. {
  37. UnityEngine.Object.DestroyImmediate(this.bg_sprite_.sprite2D.texture);
  38. }
  39. if (this.frame_sprite_.sprite2D != null && this.frame_sprite_.sprite2D.texture != null)
  40. {
  41. UnityEngine.Object.DestroyImmediate(this.frame_sprite_.sprite2D.texture);
  42. }
  43. this.sprite_.sprite2D = null;
  44. this.bg_sprite_.sprite2D = null;
  45. this.frame_sprite_.sprite2D = null;
  46. this.draw_tex_ = null;
  47. }
  48. public void SetMaid(Maid maid)
  49. {
  50. if (!this.isEnabled)
  51. {
  52. return;
  53. }
  54. this.Init();
  55. this.alpha = 0f;
  56. if (this.sprite_.sprite2D != null && this.sprite_.sprite2D.texture != null)
  57. {
  58. UnityEngine.Object.DestroyImmediate(this.sprite_.sprite2D.texture);
  59. }
  60. this.sprite_.sprite2D = null;
  61. this.draw_tex_ = null;
  62. if (maid == null)
  63. {
  64. return;
  65. }
  66. this.draw_tex_ = maid.GetThumCard();
  67. if (this.draw_tex_ == null)
  68. {
  69. return;
  70. }
  71. this.LoadFrameAndBG();
  72. Sprite sprite = Sprite.Create(this.draw_tex_, new Rect(0f, 0f, (float)this.draw_tex_.width, (float)this.draw_tex_.height), default(Vector2));
  73. sprite.name = maid.status.lastName + maid.status.firstName;
  74. this.sprite_.sprite2D = sprite;
  75. this.sprite_.SetDimensions(this.draw_tex_.width, this.draw_tex_.height);
  76. this.alpha = 1f;
  77. }
  78. public float alpha
  79. {
  80. get
  81. {
  82. this.Init();
  83. return this.bg_sprite_.alpha;
  84. }
  85. set
  86. {
  87. this.Init();
  88. this.bg_sprite_.alpha = value;
  89. }
  90. }
  91. public bool Visible
  92. {
  93. get
  94. {
  95. return base.gameObject.activeSelf;
  96. }
  97. set
  98. {
  99. base.gameObject.SetActive(value);
  100. }
  101. }
  102. public bool isEnabled { get; set; }
  103. private Texture2D draw_tex
  104. {
  105. get
  106. {
  107. return this.draw_tex_;
  108. }
  109. }
  110. private void CheckCreateFrame()
  111. {
  112. string thumbnailDictionary = this.ThumbnailDictionary;
  113. if (!Directory.Exists(thumbnailDictionary))
  114. {
  115. Directory.CreateDirectory(thumbnailDictionary);
  116. }
  117. string path = thumbnailDictionary + "/frame_single.png";
  118. if (!File.Exists(path))
  119. {
  120. Texture2D texture2D = Resources.Load<Texture2D>("CharacterSelect/Atlas/DefaultFrame");
  121. File.WriteAllBytes(path, texture2D.EncodeToPNG());
  122. Resources.UnloadAsset(texture2D);
  123. }
  124. path = thumbnailDictionary + "/frame_back.png";
  125. if (!File.Exists(path))
  126. {
  127. Texture2D texture2D2 = Resources.Load<Texture2D>("CharacterSelect/Atlas/DefaultFrameBack");
  128. File.WriteAllBytes(path, texture2D2.EncodeToPNG());
  129. Resources.UnloadAsset(texture2D2);
  130. }
  131. }
  132. private void LoadFrameAndBG()
  133. {
  134. this.CheckCreateFrame();
  135. string thumbnailDictionary = this.ThumbnailDictionary;
  136. string f_strFileName = thumbnailDictionary + "/frame_back.png";
  137. if (this.bg_sprite_.sprite2D == null)
  138. {
  139. Texture2D texture2D = UTY.LoadTexture(f_strFileName);
  140. if (texture2D != null)
  141. {
  142. int width = this.bg_sprite_.width;
  143. int height = this.bg_sprite_.height;
  144. Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)width, (float)height), default(Vector2));
  145. sprite.name = "frame_back";
  146. this.bg_sprite_.sprite2D = sprite;
  147. this.bg_sprite_.SetDimensions(width, height);
  148. }
  149. }
  150. if (this.frame_sprite_.sprite2D == null)
  151. {
  152. f_strFileName = thumbnailDictionary + "/frame_single.png";
  153. Texture2D texture2D2 = UTY.LoadTexture(f_strFileName);
  154. if (texture2D2 != null)
  155. {
  156. int width2 = this.frame_sprite_.width;
  157. int height2 = this.frame_sprite_.height;
  158. Sprite sprite2 = Sprite.Create(texture2D2, new Rect(0f, 0f, (float)width2, (float)height2), default(Vector2));
  159. sprite2.name = "frame_back";
  160. this.frame_sprite_.sprite2D = sprite2;
  161. this.frame_sprite_.SetDimensions(width2, height2);
  162. }
  163. }
  164. }
  165. private Texture2D draw_tex_;
  166. private UI2DSprite sprite_;
  167. private UI2DSprite bg_sprite_;
  168. private UI2DSprite frame_sprite_;
  169. }