ThumShot.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class ThumShot : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. this.m_camMain = base.gameObject.GetComponent<Camera>();
  9. this.m_camMain.enabled = false;
  10. this.m_rtThumPreset = new RenderTexture(this.m_siPreSize.width, this.m_siPreSize.height, 24, RenderTextureFormat.ARGB32);
  11. this.m_rtThumPreset.filterMode = FilterMode.Bilinear;
  12. this.m_rtThumPreset.antiAliasing = 8;
  13. this.m_rtThumPreset2 = new RenderTexture(this.m_siPreSize.width, this.m_siPreSize.height, 0, RenderTextureFormat.ARGB32);
  14. this.m_rtThumIcon = new RenderTexture(this.m_siIconSize.width, this.m_siIconSize.height, 24, RenderTextureFormat.ARGB32);
  15. this.m_rtThumIcon.filterMode = FilterMode.Bilinear;
  16. this.m_rtThumIcon.antiAliasing = 8;
  17. this.m_rtThumIcon2 = new RenderTexture(this.m_siIconSize.width, this.m_siIconSize.height, 0, RenderTextureFormat.ARGB32);
  18. RenderTextureFormat format = RenderTextureFormat.ARGB32;
  19. if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGB111110Float))
  20. {
  21. format = RenderTextureFormat.RGB111110Float;
  22. }
  23. else if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGB565))
  24. {
  25. format = RenderTextureFormat.RGB565;
  26. }
  27. this.m_rtThumCard = new RenderTexture(this.m_siCardSize.width, this.m_siCardSize.height, 24, format);
  28. this.m_rtThumCard.filterMode = FilterMode.Bilinear;
  29. this.m_rtThumCard.antiAliasing = 8;
  30. this.m_rtThumCard2 = new RenderTexture(this.m_siCardSize.width, this.m_siCardSize.height, 0, RenderTextureFormat.ARGB32);
  31. }
  32. private void Update()
  33. {
  34. if (this.m_trParent != null)
  35. {
  36. base.transform.position = this.m_trParent.TransformPoint(this.m_trParent.localPosition + this.m_vecOffsetPos);
  37. base.transform.rotation = this.m_trParent.rotation * Quaternion.Euler(this.m_vecOffsetRot);
  38. }
  39. }
  40. public Texture2D RenderThum(Camera f_cam, RenderTexture f_rtMain, RenderTexture f_rtSub, Size<int> f_size)
  41. {
  42. return this.RenderThum(f_cam, f_rtMain, f_rtSub, f_size, false);
  43. }
  44. public Texture2D RenderThum(Camera f_cam, RenderTexture f_rtMain, RenderTexture f_rtSub, Size<int> f_size, bool f_white)
  45. {
  46. if (f_white)
  47. {
  48. f_cam.backgroundColor = Color.white;
  49. }
  50. else
  51. {
  52. f_cam.backgroundColor = new Color(0f, 0f, 0f, 0f);
  53. }
  54. f_cam.targetTexture = f_rtMain;
  55. f_cam.enabled = true;
  56. f_cam.Render();
  57. f_cam.enabled = false;
  58. Texture2D texture2D = new Texture2D(f_size.width, f_size.height, TextureFormat.ARGB32, false);
  59. RenderTexture active = RenderTexture.active;
  60. if (f_rtMain.antiAliasing != 0)
  61. {
  62. RenderTexture.active = f_rtSub;
  63. GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));
  64. GL.PushMatrix();
  65. GL.LoadPixelMatrix(0f, (float)f_size.width, (float)f_size.height, 0f);
  66. Graphics.DrawTexture(new Rect(0f, 0f, (float)f_size.width, (float)f_size.height), f_rtMain);
  67. GL.PopMatrix();
  68. }
  69. else
  70. {
  71. RenderTexture.active = f_rtMain;
  72. }
  73. texture2D.ReadPixels(new Rect(0f, 0f, (float)f_size.width, (float)f_size.height), 0, 0);
  74. texture2D.Apply();
  75. RenderTexture.active = active;
  76. return texture2D;
  77. }
  78. public Texture2D ShotThumPreset(Maid f_maid)
  79. {
  80. if (f_maid.body0 == null || f_maid.body0.m_Bones == null)
  81. {
  82. return null;
  83. }
  84. Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true);
  85. if (transform == null)
  86. {
  87. return null;
  88. }
  89. base.transform.position = transform.TransformPoint(transform.localPosition + new Vector3(0.38f, 1.07f, 0f));
  90. base.transform.rotation = transform.rotation * Quaternion.Euler(90f, 0f, 90f);
  91. this.m_camMain.fieldOfView = 30f;
  92. return this.RenderThum(this.m_camMain, this.m_rtThumPreset, this.m_rtThumPreset2, this.m_siPreSize);
  93. }
  94. public void MoveTargetThum(Maid f_maid)
  95. {
  96. Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true);
  97. if (transform != null)
  98. {
  99. base.transform.position = transform.TransformPoint(transform.localPosition + new Vector3(0.38f, 1.07f, 0f));
  100. base.transform.rotation = transform.rotation * Quaternion.Euler(90f, 0f, 90f);
  101. }
  102. else
  103. {
  104. Debug.LogError("サムネイルを取ろうとしましたがメイドが居ません。");
  105. }
  106. }
  107. public Texture2D ShotThumIcon(Maid f_maid)
  108. {
  109. this.MoveTargetThum(f_maid);
  110. this.m_camMain.fieldOfView = 30f;
  111. return this.RenderThum(this.m_camMain, this.m_rtThumIcon, this.m_rtThumIcon2, this.m_siIconSize);
  112. }
  113. public void MoveTargetCard(Maid f_maid)
  114. {
  115. Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true);
  116. if (transform != null)
  117. {
  118. base.transform.position = transform.TransformPoint(transform.localPosition + new Vector3(0.64f, 2.25f, 0f));
  119. base.transform.rotation = transform.rotation * Quaternion.Euler(90f, 0f, 90f);
  120. }
  121. else
  122. {
  123. Debug.LogError("サムネイルを取ろうとしましたがメイドが居ません。");
  124. }
  125. }
  126. public Texture2D ShotThumCard(Maid f_maid)
  127. {
  128. this.MoveTargetCard(f_maid);
  129. this.m_camMain.fieldOfView = 30f;
  130. return this.ShotThumCardOriginal();
  131. }
  132. public Texture2D ShotThumCardOriginal()
  133. {
  134. return this.RenderThum(this.m_camMain, this.m_rtThumCard, this.m_rtThumCard2, this.m_siCardSize, true);
  135. }
  136. public void ShotSave(Maid f_maid)
  137. {
  138. UTY.SaveImage(this.ShotThumPreset(f_maid), null);
  139. }
  140. public void ShotStart()
  141. {
  142. base.StartCoroutine(this.CoShot());
  143. }
  144. private IEnumerator CoShot()
  145. {
  146. yield return new WaitForEndOfFrame();
  147. this.m_camMain.enabled = true;
  148. yield return new WaitForEndOfFrame();
  149. this.m_camMain.enabled = false;
  150. Camera cam = base.gameObject.GetComponent<Camera>();
  151. if (cam != null)
  152. {
  153. UTY.SaveImage(this.m_rtThumPreset, null, TextureFormat.ARGB32);
  154. }
  155. yield break;
  156. }
  157. private Camera m_camMain;
  158. private RenderTexture m_rtThumPreset;
  159. private RenderTexture m_rtThumPreset2;
  160. private RenderTexture m_rtThumIcon;
  161. private RenderTexture m_rtThumIcon2;
  162. private RenderTexture m_rtThumCard;
  163. private RenderTexture m_rtThumCard2;
  164. public Transform m_trParent;
  165. public Vector3 m_vecOffsetPos;
  166. public Vector3 m_vecOffsetRot;
  167. private readonly Size<int> m_siIconSize = new Size<int>(90, 90);
  168. private readonly Size<int> m_siPreSize = new Size<int>(138, 200);
  169. private readonly Size<int> m_siCardSize = new Size<int>(630, 890);
  170. }