OvrHandCamera.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 text = Path.Combine(GameMain.Instance.SerializeStorageManager.StoreDirectoryPath, "ScreenShot");
  96. if (!Directory.Exists(text))
  97. {
  98. Directory.CreateDirectory(text);
  99. }
  100. if (!f_bThum)
  101. {
  102. return string.Concat(new string[]
  103. {
  104. text,
  105. "\\img",
  106. DateTime.Now.ToString("yyyyMMddHHmmss"),
  107. this.m_strAddSideChar[(int)this.m_eSide],
  108. ".png"
  109. });
  110. }
  111. text += "\\VRPhotoThumb";
  112. if (!Directory.Exists(text))
  113. {
  114. Directory.CreateDirectory(text);
  115. }
  116. return string.Concat(new string[]
  117. {
  118. text,
  119. "\\img",
  120. DateTime.Now.ToString("yyyyMMddHHmmss"),
  121. this.m_strAddSideChar[(int)this.m_eSide],
  122. ".jpg"
  123. });
  124. }
  125. private void Update()
  126. {
  127. Vector3 vector = base.transform.TransformPoint(-0.06f, 0f, 0.08f);
  128. Vector3 vector2 = base.transform.TransformPoint(0.06f, 0f, 0.08f);
  129. Vector3 vector3 = base.transform.TransformPoint(0f, 0f, 0.15f);
  130. float y = base.transform.position.y;
  131. OvrHandCamera.SIDE eSide = OvrHandCamera.SIDE.PORTRAIT_DOWN;
  132. if (vector.y < y)
  133. {
  134. y = vector.y;
  135. eSide = OvrHandCamera.SIDE.LANDSCAPE_L;
  136. }
  137. if (vector2.y < y)
  138. {
  139. y = vector2.y;
  140. eSide = OvrHandCamera.SIDE.LANDSCAPE_R;
  141. }
  142. if (vector3.y < y)
  143. {
  144. y = vector3.y;
  145. eSide = OvrHandCamera.SIDE.PORTRAIT_TOP;
  146. }
  147. this.m_eSide = eSide;
  148. }
  149. private Camera m_Camera;
  150. private Material m_matMonitor;
  151. private RenderTexture m_rtPreview;
  152. public AVRControllerBehavior m_ctrl;
  153. private int[] ss_super_size_ = new int[]
  154. {
  155. 1,
  156. 2,
  157. 4
  158. };
  159. public OvrHandCamera.SIDE m_eSide = OvrHandCamera.SIDE.PORTRAIT_DOWN;
  160. private string[] m_strAddSideChar = new string[]
  161. {
  162. "l",
  163. "r",
  164. "d",
  165. "t"
  166. };
  167. private Vector3 m_vBackPos;
  168. private Vector3 m_vBackCamPos;
  169. public enum SIDE
  170. {
  171. LANDSCAPE_L,
  172. LANDSCAPE_R,
  173. PORTRAIT_DOWN,
  174. PORTRAIT_TOP,
  175. MAX
  176. }
  177. }