OvrSelfShotCamera.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 text = Path.Combine(GameMain.Instance.SerializeStorageManager.StoreDirectoryPath, "ScreenShot");
  116. if (!Directory.Exists(text))
  117. {
  118. Directory.CreateDirectory(text);
  119. }
  120. if (!f_bThum)
  121. {
  122. return text + "\\img" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
  123. }
  124. text += "\\VRPhotoThumb";
  125. if (!Directory.Exists(text))
  126. {
  127. Directory.CreateDirectory(text);
  128. }
  129. return text + "\\img" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
  130. }
  131. private void Update()
  132. {
  133. if (this.m_trCamMoniPlane != null)
  134. {
  135. this.m_trCamMoniPlane.localScale = new Vector3((float)this.m_rtMoniPlaneTex.width / (float)this.m_rtMoniPlaneTex.height * 0.1f, 1f, -0.1f);
  136. }
  137. this.m_camera.backgroundColor = this.m_OvrCamera.backgroundColor;
  138. float selfCameraFOV = ControllerShortcutSettingData.config.selfCameraFOV;
  139. if (this.m_fBackFOV != selfCameraFOV)
  140. {
  141. CMSystem.SerializeConfig sconfig = GameMain.Instance.CMSystem.SConfig;
  142. this.m_camera.fieldOfView = sconfig.OvrIkSelfCamFovMin + (sconfig.OvrIkSelfCamFovMax - sconfig.OvrIkSelfCamFovMin) * selfCameraFOV;
  143. this.m_fBackFOV = selfCameraFOV;
  144. }
  145. }
  146. private RenderTexture m_rtMoniPlaneTex;
  147. private Transform m_trCamMoniPlane;
  148. private Transform m_trEyeTarget;
  149. private Camera m_camera;
  150. private Camera m_OvrCamera;
  151. private RenderTexture m_rtPreview;
  152. private Coroutine m_coCountdown;
  153. private Coroutine m_coSnap;
  154. private int[] ss_super_size_ = new int[]
  155. {
  156. 1,
  157. 2,
  158. 4
  159. };
  160. private GameObject m_goCountCanvas;
  161. private Text m_txCountText;
  162. private float m_fBackFOV;
  163. }