OvrHandCamera.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using UnityEngine;
  5. public class OvrHandCamera : MonoBehaviour
  6. {
  7. private void Awake()
  8. {
  9. Transform transform = base.transform.Find("Camera");
  10. NDebug.Assert(transform != null, "HandCameraの下にCameraがありませんでした。");
  11. this.m_Camera = transform.GetComponent<Camera>();
  12. Transform transform2 = base.transform.Find("mopnitor");
  13. NDebug.Assert(transform2 != null, "HandCameraの下にmopnitorがありませんでした。");
  14. MeshRenderer component = transform2.GetComponent<MeshRenderer>();
  15. this.m_matMonitor = component.material;
  16. this.m_rtPreview = new RenderTexture(180, 320, 24, RenderTextureFormat.ARGB32);
  17. this.m_Camera.targetTexture = this.m_rtPreview;
  18. this.m_matMonitor.mainTexture = this.m_rtPreview;
  19. this.m_vBackPos = base.transform.localPosition;
  20. this.m_vBackCamPos = transform.localPosition;
  21. }
  22. private void OnEnable()
  23. {
  24. if (OvrIK.IsModeVRIK)
  25. {
  26. if (this.m_ctrl != null)
  27. {
  28. if (this.m_ctrl.m_bHandL)
  29. {
  30. base.transform.localPosition = new Vector3(0.085f, -0.021f, -0.082f);
  31. }
  32. else
  33. {
  34. base.transform.localPosition = new Vector3(-0.085f, -0.021f, -0.082f);
  35. }
  36. this.m_Camera.transform.localPosition = new Vector3(this.m_Camera.transform.localPosition.x, 0.0189f, this.m_Camera.transform.localPosition.z);
  37. }
  38. }
  39. else
  40. {
  41. base.transform.localPosition = this.m_vBackPos;
  42. this.m_Camera.transform.localPosition = this.m_vBackCamPos;
  43. }
  44. }
  45. public void Snap()
  46. {
  47. if (GameMain.Instance.OvrMgr.OvrCamera.IsFadeStateNon())
  48. {
  49. GameMain.Instance.SoundMgr.PlaySe("SE022.ogg", false);
  50. base.StartCoroutine(this.SaveScreenShotNormal());
  51. }
  52. }
  53. private IEnumerator SaveScreenShotNormal()
  54. {
  55. int nSuperSize = this.ss_super_size_[(int)GameMain.Instance.CMSystem.ScreenShotSuperSize];
  56. RenderTexture rtSnap = new RenderTexture(GameMain.Instance.CMSystem.OvrHandCameraWidth * nSuperSize, GameMain.Instance.CMSystem.OvrHandCameraHeight * nSuperSize, 24, RenderTextureFormat.ARGB32);
  57. RenderTexture rtSnapThum = null;
  58. if (SceneVRCommunication.Instance != null)
  59. {
  60. rtSnapThum = new RenderTexture(576, 1024, 24, RenderTextureFormat.ARGB32);
  61. }
  62. this.m_Camera.targetTexture = rtSnap;
  63. yield return new WaitForEndOfFrame();
  64. if (SceneVRCommunication.Instance != null)
  65. {
  66. this.m_Camera.targetTexture = rtSnapThum;
  67. yield return new WaitForEndOfFrame();
  68. }
  69. UTY.SaveImage(rtSnap, this.GetTimeFileName(false), TextureFormat.RGB24);
  70. if (SceneVRCommunication.Instance != null)
  71. {
  72. this.SaveImageThum(rtSnapThum, this.GetTimeFileName(true), TextureFormat.RGB24);
  73. }
  74. yield return new WaitForEndOfFrame();
  75. this.m_Camera.targetTexture = this.m_rtPreview;
  76. UnityEngine.Object.Destroy(rtSnap);
  77. if (rtSnapThum != null)
  78. {
  79. UnityEngine.Object.Destroy(rtSnapThum);
  80. }
  81. yield break;
  82. }
  83. public void SaveImageThum(RenderTexture f_rtSrc, string f_strFileName, TextureFormat f_TexFormat = TextureFormat.ARGB32)
  84. {
  85. Texture2D texture2D = new Texture2D(f_rtSrc.width, f_rtSrc.height, f_TexFormat, false);
  86. RenderTexture active = RenderTexture.active;
  87. RenderTexture.active = f_rtSrc;
  88. texture2D.ReadPixels(new Rect(0f, 0f, (float)f_rtSrc.width, (float)f_rtSrc.height), 0, 0);
  89. RenderTexture.active = active;
  90. byte[] bytes = texture2D.EncodeToJPG();
  91. File.WriteAllBytes(f_strFileName, bytes);
  92. }
  93. private string GetTimeFileName(bool f_bThum = false)
  94. {
  95. string fullPath = Path.GetFullPath(".\\");
  96. string text = fullPath + "ScreenShot";
  97. if (!Directory.Exists(text))
  98. {
  99. Directory.CreateDirectory(text);
  100. }
  101. if (!f_bThum)
  102. {
  103. return string.Concat(new string[]
  104. {
  105. text,
  106. "\\img",
  107. DateTime.Now.ToString("yyyyMMddHHmmss"),
  108. this.m_strAddSideChar[(int)this.m_eSide],
  109. ".png"
  110. });
  111. }
  112. text += "\\VRPhotoThumb";
  113. if (!Directory.Exists(text))
  114. {
  115. Directory.CreateDirectory(text);
  116. }
  117. return string.Concat(new string[]
  118. {
  119. text,
  120. "\\img",
  121. DateTime.Now.ToString("yyyyMMddHHmmss"),
  122. this.m_strAddSideChar[(int)this.m_eSide],
  123. ".jpg"
  124. });
  125. }
  126. private void Update()
  127. {
  128. Vector3 vector = base.transform.TransformPoint(-0.06f, 0f, 0.08f);
  129. Vector3 vector2 = base.transform.TransformPoint(0.06f, 0f, 0.08f);
  130. Vector3 vector3 = base.transform.TransformPoint(0f, 0f, 0.15f);
  131. float y = base.transform.position.y;
  132. OvrHandCamera.SIDE eSide = OvrHandCamera.SIDE.PORTRAIT_DOWN;
  133. if (vector.y < y)
  134. {
  135. y = vector.y;
  136. eSide = OvrHandCamera.SIDE.LANDSCAPE_L;
  137. }
  138. if (vector2.y < y)
  139. {
  140. y = vector2.y;
  141. eSide = OvrHandCamera.SIDE.LANDSCAPE_R;
  142. }
  143. if (vector3.y < y)
  144. {
  145. y = vector3.y;
  146. eSide = OvrHandCamera.SIDE.PORTRAIT_TOP;
  147. }
  148. this.m_eSide = eSide;
  149. }
  150. private Camera m_Camera;
  151. private Material m_matMonitor;
  152. private RenderTexture m_rtPreview;
  153. public AVRControllerBehavior m_ctrl;
  154. private int[] ss_super_size_ = new int[]
  155. {
  156. 1,
  157. 2,
  158. 4
  159. };
  160. public OvrHandCamera.SIDE m_eSide = OvrHandCamera.SIDE.PORTRAIT_DOWN;
  161. private string[] m_strAddSideChar = new string[]
  162. {
  163. "l",
  164. "r",
  165. "d",
  166. "t"
  167. };
  168. private Vector3 m_vBackPos;
  169. private Vector3 m_vBackCamPos;
  170. public enum SIDE
  171. {
  172. LANDSCAPE_L,
  173. LANDSCAPE_R,
  174. PORTRAIT_DOWN,
  175. PORTRAIT_TOP,
  176. MAX
  177. }
  178. }