ThumShot.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true);
  60. base.transform.position = transform.TransformPoint(transform.localPosition + new Vector3(0.38f, 1.07f, 0f));
  61. base.transform.rotation = transform.rotation * Quaternion.Euler(90f, 0f, 90f);
  62. this.m_camMain.fieldOfView = 30f;
  63. return this.RenderThum(this.m_camMain, this.m_rtThumPreset, this.m_rtThumPreset2, this.m_siPreSize);
  64. }
  65. public void MoveTargetThum(Maid f_maid)
  66. {
  67. Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true);
  68. if (transform != null)
  69. {
  70. base.transform.position = transform.TransformPoint(transform.localPosition + new Vector3(0.38f, 1.07f, 0f));
  71. base.transform.rotation = transform.rotation * Quaternion.Euler(90f, 0f, 90f);
  72. }
  73. else
  74. {
  75. Debug.LogError("サムネイルを取ろうとしましたがメイドが居ません。");
  76. }
  77. }
  78. public Texture2D ShotThumIcon(Maid f_maid)
  79. {
  80. this.MoveTargetThum(f_maid);
  81. this.m_camMain.fieldOfView = 30f;
  82. return this.RenderThum(this.m_camMain, this.m_rtThumIcon, this.m_rtThumIcon2, this.m_siIconSize);
  83. }
  84. public void MoveTargetCard(Maid f_maid)
  85. {
  86. Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true);
  87. if (transform != null)
  88. {
  89. base.transform.position = transform.TransformPoint(transform.localPosition + new Vector3(0.64f, 2.25f, 0f));
  90. base.transform.rotation = transform.rotation * Quaternion.Euler(90f, 0f, 90f);
  91. }
  92. else
  93. {
  94. Debug.LogError("サムネイルを取ろうとしましたがメイドが居ません。");
  95. }
  96. }
  97. public Texture2D ShotThumCard(Maid f_maid)
  98. {
  99. this.MoveTargetCard(f_maid);
  100. this.m_camMain.fieldOfView = 30f;
  101. return this.ShotThumCardOriginal();
  102. }
  103. public Texture2D ShotThumCardOriginal()
  104. {
  105. return this.RenderThum(this.m_camMain, this.m_rtThumCard, this.m_rtThumCard2, this.m_siCardSize);
  106. }
  107. public void ShotSave(Maid f_maid)
  108. {
  109. UTY.SaveImage(this.ShotThumPreset(f_maid), null);
  110. }
  111. public void ShotStart()
  112. {
  113. base.StartCoroutine(this.CoShot());
  114. }
  115. private IEnumerator CoShot()
  116. {
  117. yield return new WaitForEndOfFrame();
  118. this.m_camMain.enabled = true;
  119. yield return new WaitForEndOfFrame();
  120. this.m_camMain.enabled = false;
  121. Camera cam = base.gameObject.GetComponent<Camera>();
  122. if (cam != null)
  123. {
  124. UTY.SaveImage(this.m_rtThumPreset, null, TextureFormat.ARGB32);
  125. }
  126. yield break;
  127. }
  128. private Camera m_camMain;
  129. private RenderTexture m_rtThumPreset;
  130. private RenderTexture m_rtThumPreset2;
  131. private RenderTexture m_rtThumIcon;
  132. private RenderTexture m_rtThumIcon2;
  133. private RenderTexture m_rtThumCard;
  134. private RenderTexture m_rtThumCard2;
  135. public Transform m_trParent;
  136. public Vector3 m_vecOffsetPos;
  137. public Vector3 m_vecOffsetRot;
  138. private readonly Size<int> m_siIconSize = new Size<int>(90, 90);
  139. private readonly Size<int> m_siPreSize = new Size<int>(138, 200);
  140. private readonly Size<int> m_siCardSize = new Size<int>(630, 890);
  141. }