OvrSelfShotCamera.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using wf;
  7. public class OvrSelfShotCamera : MonoBehaviour
  8. {
  9. public static OvrSelfShotCamera Create()
  10. {
  11. GameObject gameObject = Utility.CreatePrefab(null, "OVR/OvrSelfShotCamera", false);
  12. gameObject.name = "OvrSelfShotCamera";
  13. OvrSelfShotCamera component = gameObject.GetComponent<OvrSelfShotCamera>();
  14. component.Init();
  15. return component;
  16. }
  17. public RenderTexture CamTex
  18. {
  19. get
  20. {
  21. return this.m_rtMoniPlaneTex;
  22. }
  23. }
  24. public Transform EyeTarget
  25. {
  26. get
  27. {
  28. return this.m_trEyeTarget;
  29. }
  30. }
  31. private void Init()
  32. {
  33. this.m_camera = base.gameObject.GetComponentInChildren<Camera>();
  34. this.m_rtMoniPlaneTex = this.m_camera.targetTexture;
  35. this.m_trEyeTarget = this.m_camera.transform;
  36. this.m_trCamMoniPlane = base.gameObject.transform.Find("SelfShotCam/Monitor/Plane");
  37. Transform realHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  38. Vector3 vector = new Vector3(realHeadTransform.forward.x, 0f, realHeadTransform.forward.z);
  39. Vector3 normalized = vector.normalized;
  40. base.gameObject.transform.position = realHeadTransform.position + normalized * 1.5f;
  41. base.gameObject.transform.LookAt(realHeadTransform.position, Vector3.up);
  42. base.gameObject.transform.Rotate(-20f, 180f, 0f);
  43. this.m_OvrCamera = GameMain.Instance.OvrMgr.OvrCamera.GetComponent<Camera>();
  44. this.m_goCountCanvas = base.gameObject.transform.Find("SelfShotCam/Canvas").gameObject;
  45. this.m_txCountText = this.m_goCountCanvas.transform.Find("Text").GetComponent<Text>();
  46. this.m_goCountCanvas.SetActive(false);
  47. }
  48. private void Start()
  49. {
  50. if (this.m_camera == null)
  51. {
  52. this.Init();
  53. }
  54. }
  55. private void OnDisable()
  56. {
  57. this.m_coSnap = null;
  58. if (this.m_camera != null && this.m_rtPreview != null)
  59. {
  60. this.m_camera.targetTexture = this.m_rtPreview;
  61. }
  62. this.m_coCountdown = null;
  63. if (this.m_goCountCanvas != null)
  64. {
  65. this.m_goCountCanvas.SetActive(false);
  66. }
  67. }
  68. public void StartCountSnap()
  69. {
  70. if (GameMain.Instance.OvrMgr.OvrCamera.IsFadeStateNon() && this.m_coSnap == null && this.m_goCountCanvas != null)
  71. {
  72. this.m_coCountdown = base.StartCoroutine(this.CoCountdown());
  73. }
  74. }
  75. private IEnumerator CoCountdown()
  76. {
  77. this.m_goCountCanvas.SetActive(true);
  78. int nC = 3;
  79. while (0 < nC)
  80. {
  81. this.m_txCountText.text = nC.ToString();
  82. yield return new WaitForSeconds(1f);
  83. nC--;
  84. }
  85. this.Snap();
  86. this.m_goCountCanvas.SetActive(false);
  87. this.m_coCountdown = null;
  88. yield break;
  89. }
  90. private void Snap()
  91. {
  92. if (GameMain.Instance.OvrMgr.OvrCamera.IsFadeStateNon() && this.m_coSnap == null)
  93. {
  94. GameMain.Instance.SoundMgr.PlaySe("SE022.ogg", false);
  95. this.m_coSnap = base.StartCoroutine(this.SaveScreenShotNormal());
  96. }
  97. }
  98. private IEnumerator SaveScreenShotNormal()
  99. {
  100. this.m_rtPreview = this.m_camera.targetTexture;
  101. int nSuperSize = this.ss_super_size_[(int)GameMain.Instance.CMSystem.ScreenShotSuperSize];
  102. RenderTexture rtSnap = new RenderTexture(this.m_rtPreview.width * nSuperSize, this.m_rtPreview.height * nSuperSize, 24, RenderTextureFormat.ARGB32);
  103. this.m_camera.targetTexture = rtSnap;
  104. yield return new WaitForEndOfFrame();
  105. UTY.SaveImage(rtSnap, this.GetTimeFileName(false), TextureFormat.RGB24);
  106. yield return new WaitForEndOfFrame();
  107. this.m_camera.targetTexture = this.m_rtPreview;
  108. this.m_rtPreview = null;
  109. UnityEngine.Object.Destroy(rtSnap);
  110. this.m_coSnap = null;
  111. yield break;
  112. }
  113. private string GetTimeFileName(bool f_bThum = false)
  114. {
  115. string fullPath = Path.GetFullPath(".\\");
  116. string text = fullPath + "ScreenShot";
  117. if (!Directory.Exists(text))
  118. {
  119. Directory.CreateDirectory(text);
  120. }
  121. if (!f_bThum)
  122. {
  123. return text + "\\img" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
  124. }
  125. text += "\\VRPhotoThumb";
  126. if (!Directory.Exists(text))
  127. {
  128. Directory.CreateDirectory(text);
  129. }
  130. return text + "\\img" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
  131. }
  132. private void Update()
  133. {
  134. if (this.m_trCamMoniPlane != null)
  135. {
  136. this.m_trCamMoniPlane.localScale = new Vector3((float)this.m_rtMoniPlaneTex.width / (float)this.m_rtMoniPlaneTex.height * 0.1f, 1f, -0.1f);
  137. }
  138. this.m_camera.backgroundColor = this.m_OvrCamera.backgroundColor;
  139. float selfCameraFOV = ControllerShortcutSettingData.config.selfCameraFOV;
  140. if (this.m_fBackFOV != selfCameraFOV)
  141. {
  142. CMSystem.SerializeConfig sconfig = GameMain.Instance.CMSystem.SConfig;
  143. this.m_camera.fieldOfView = sconfig.OvrIkSelfCamFovMin + (sconfig.OvrIkSelfCamFovMax - sconfig.OvrIkSelfCamFovMin) * selfCameraFOV;
  144. this.m_fBackFOV = selfCameraFOV;
  145. }
  146. }
  147. private RenderTexture m_rtMoniPlaneTex;
  148. private Transform m_trCamMoniPlane;
  149. private Transform m_trEyeTarget;
  150. private Camera m_camera;
  151. private Camera m_OvrCamera;
  152. private RenderTexture m_rtPreview;
  153. private Coroutine m_coCountdown;
  154. private Coroutine m_coSnap;
  155. private int[] ss_super_size_ = new int[]
  156. {
  157. 1,
  158. 2,
  159. 4
  160. };
  161. private GameObject m_goCountCanvas;
  162. private Text m_txCountText;
  163. private float m_fBackFOV;
  164. }