BigThumbnailKasizuki.cs 4.6 KB

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