ThumShot.cs 5.5 KB

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