ViveCamera.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. using System;
  2. using UnityEngine;
  3. public class ViveCamera : OvrCamera
  4. {
  5. protected override void Awake()
  6. {
  7. this.m_trRealHead = UTY.GetChildObject(base.gameObject, "Main Camera (head)", false).transform;
  8. this.m_goCenterEye = UTY.GetChildObject(base.gameObject, "Main Camera (head)/Main Camera (eye)", false);
  9. this.m_trCenterEye = this.m_goCenterEye.transform;
  10. this.m_nBackCullingMask = this.m_goCenterEye.GetComponent<Camera>().cullingMask;
  11. this.m_FadeTargetCameraOVR = this.m_goCenterEye.GetComponent<ScreenOverlay>();
  12. this.m_BloomOVR = this.m_goCenterEye.GetComponent<Bloom>();
  13. this.m_fBloomDefIntensity = this.m_BloomOVR.bloomIntensity;
  14. this.m_trTarget = new GameObject("OVRCamTarget").transform;
  15. this.m_trTarget.SetParent(GameMain.Instance.transform, false);
  16. this.m_trVirtualMy = new GameObject("OVRCamMy").transform;
  17. this.m_trVirtualMy.SetParent(GameMain.Instance.transform, false);
  18. GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load("OVR/OvrHeadScale")) as GameObject;
  19. gameObject.SetActive(true);
  20. GameObject gameObject2 = GameObject.Find("SystemUI Root");
  21. gameObject.transform.SetParent(gameObject2.transform, false);
  22. this.m_labelHeadScale = gameObject.GetComponentInChildren<UILabel>();
  23. this.m_labelHeadScale.enabled = false;
  24. this.m_goOvrUiScreen = UTY.GetChildObject(this.m_trRealHead.gameObject, "UI", false);
  25. this.m_goOvrUiTablet = UTY.GetChildObject(base.gameObject, "Odogu_TabletPC", false);
  26. this.m_OvrTablet = this.m_goOvrUiTablet.GetComponent<OvrTablet>();
  27. this.m_OvrTablet.Init(this.m_trRealHead.gameObject);
  28. Vignetting vignetting = base.gameObject.AddComponent<Vignetting>();
  29. vignetting.enabled = false;
  30. Camera component = base.gameObject.GetComponent<Camera>();
  31. component.enabled = false;
  32. this.m_trBaseHead = new GameObject("ViveCamBaseHead").transform;
  33. this.m_trBaseHead.SetParent(GameMain.Instance.transform, false);
  34. this.m_trBaseRoomBase = new GameObject("BaseRoomBase").transform;
  35. this.m_trBaseRoomBase.SetParent(this.m_trBaseHead, false);
  36. this.m_trCursorLaserHit = this.m_goOvrUiScreen.transform.Find("ovr_screen/hit");
  37. NDebug.Assert(this.m_trCursorLaserHit != null, "UI Cursor Hit オブジェクトが見つかりません。");
  38. float ovrViveCursorLaserHitScale = GameMain.Instance.CMSystem.OvrViveCursorLaserHitScale;
  39. this.m_trCursorLaserHit.localScale = new Vector3(ovrViveCursorLaserHitScale, ovrViveCursorLaserHitScale, ovrViveCursorLaserHitScale);
  40. this.m_VREvnetText = this.m_trRealHead.Find("VREventText").GetComponent<VREventText>();
  41. Texture2D texture2D = Resources.Load<Texture2D>("System/Texture/black");
  42. SteamVR_Skybox.SetOverride(texture2D, texture2D, texture2D, texture2D, texture2D, texture2D);
  43. Transform transform = base.transform.Find("Controller (left)");
  44. Transform transform2 = base.transform.Find("Controller (right)");
  45. this.m_VRCtrlLeft = transform.GetComponent<ViveController>();
  46. this.m_VRCtrlLeft.Init();
  47. this.m_VRCtrlRight = transform2.GetComponent<ViveController>();
  48. this.m_VRCtrlRight.Init();
  49. Transform transform3 = this.m_trRealHead.Find("EyeRayCaster");
  50. this.m_EyeRay = transform3.GetComponent<OvrEyeRay>();
  51. NDebug.Assert(this.m_EyeRay != null, "視線検出機構がみつかりません。");
  52. this.m_camClearCam = this.m_trRealHead.Find("ClearCamera").GetComponent<Camera>();
  53. NDebug.Assert(this.m_camClearCam != null, "ClearCameraが見つかりません。");
  54. this.m_camClearCam.gameObject.SetActive(false);
  55. this.m_camClearCam.enabled = false;
  56. this.m_view = this.m_trRealHead.GetComponent<SteamVR_GameView>();
  57. this.m_view.enabled = true;
  58. this.UpdateHeadScale();
  59. }
  60. public override void ReCallcOffset()
  61. {
  62. Vector3 position = this.m_trBaseHead.position;
  63. Quaternion rotation = this.m_trBaseHead.rotation;
  64. this.m_trBaseHead.position = this.m_trRealHead.position;
  65. Vector3 eulerAngles = this.m_trRealHead.rotation.eulerAngles;
  66. this.m_trBaseHead.rotation = Quaternion.Euler(0f, eulerAngles.y, 0f);
  67. this.m_trBaseRoomBase.position = base.transform.position;
  68. this.m_trBaseRoomBase.rotation = base.transform.rotation;
  69. this.m_trBaseHead.position = position;
  70. Vector3 eulerAngles2 = rotation.eulerAngles;
  71. this.m_trBaseHead.rotation = Quaternion.Euler(0f, eulerAngles2.y, 0f);
  72. this.UpdateRealPosRot();
  73. }
  74. public override void SetCameraMask(CameraMain.CameraMask f_eMask, bool f_bVisible)
  75. {
  76. Camera component = this.m_goCenterEye.GetComponent<Camera>();
  77. if (f_bVisible)
  78. {
  79. component.cullingMask |= 1 << (int)f_eMask;
  80. }
  81. else
  82. {
  83. component.cullingMask &= ~(1 << (int)f_eMask);
  84. }
  85. }
  86. public override void CameraMaskReset()
  87. {
  88. Camera component = this.m_goCenterEye.GetComponent<Camera>();
  89. component.cullingMask = this.m_nBackCullingMask;
  90. }
  91. public override void SetCameraType(CameraMain.CameraType f_eType)
  92. {
  93. }
  94. public override CameraMain.CameraType GetCameraType()
  95. {
  96. return CameraMain.CameraType.Free;
  97. }
  98. public override void SetControl(bool f_bEnable)
  99. {
  100. }
  101. public override bool GetControl()
  102. {
  103. return true;
  104. }
  105. public override void SetTargetPos(Vector3 f_vecWorldPos, bool f_bSelf = true)
  106. {
  107. if (f_bSelf)
  108. {
  109. iTween.StopAndSkipToEnd(base.gameObject);
  110. }
  111. this.m_trTarget.position = f_vecWorldPos;
  112. this.SetTransform(this.m_trTarget.position, this.m_vRot, this.m_fDistance);
  113. }
  114. public override Vector3 GetTargetPos()
  115. {
  116. return this.m_trTarget.position;
  117. }
  118. public override void SetDistance(float f_fDistance, bool f_bSelf = true)
  119. {
  120. if (f_bSelf)
  121. {
  122. iTween.StopAndSkipToEnd(base.gameObject);
  123. }
  124. this.m_fDistance = f_fDistance;
  125. this.SetTransform(this.m_trTarget.position, this.m_vRot, this.m_fDistance);
  126. }
  127. public override float GetDistance()
  128. {
  129. return this.m_fDistance;
  130. }
  131. public override void SetAroundAngle(Vector2 f_vecAngle, bool f_bSelf = true)
  132. {
  133. if (f_bSelf)
  134. {
  135. iTween.StopAndSkipToEnd(base.gameObject);
  136. }
  137. this.SetTransform(this.m_trTarget.position, f_vecAngle, this.m_fDistance);
  138. }
  139. public override Vector2 GetAroundAngle()
  140. {
  141. return this.m_vRot;
  142. }
  143. public override void SetTargetOffset(Vector3 f_vOffs, bool f_bSelf = true)
  144. {
  145. }
  146. public override Vector3 GetPos()
  147. {
  148. return this.m_trBaseHead.position;
  149. }
  150. public override void SetRealHeadPos(Vector3 f_vecWorldPos, bool f_bYFromFloor = false)
  151. {
  152. if (GameMain.Instance.CMSystem.OvrCameraHeightType == CMSystem.OVR_CAM_HEIGHT_TYPE.VR)
  153. {
  154. if (f_bYFromFloor)
  155. {
  156. f_vecWorldPos.y = this.GetYfromFloor(f_vecWorldPos);
  157. }
  158. Vector3 position = this.m_trBaseRoomBase.position;
  159. this.m_trBaseHead.position = f_vecWorldPos;
  160. Vector3 b = f_vecWorldPos - this.GetRealHeadTransform().position;
  161. this.m_trBaseRoomBase.position = position + b;
  162. }
  163. else
  164. {
  165. if (f_bYFromFloor)
  166. {
  167. f_vecWorldPos = this.GetFloorPos(f_vecWorldPos);
  168. }
  169. Vector3 position2 = this.m_trBaseRoomBase.position;
  170. Vector3 position3 = this.GetRealHeadTransform().position;
  171. position3.y = position2.y;
  172. Vector3 b2 = position2 - position3;
  173. this.m_trBaseRoomBase.position = f_vecWorldPos + b2;
  174. }
  175. this.UpdateRealPosRot();
  176. }
  177. public override void SetFootPos(Vector3 f_vecFootPos, CameraMain.STAND_SIT f_eState)
  178. {
  179. if (GameMain.Instance.CMSystem.OvrCameraHeightType == CMSystem.OVR_CAM_HEIGHT_TYPE.VR)
  180. {
  181. if (f_eState == CameraMain.STAND_SIT.STAND)
  182. {
  183. f_vecFootPos.y += GameMain.Instance.CMSystem.VRCameraHeightStandOffs;
  184. }
  185. else if (f_eState == CameraMain.STAND_SIT.SIT)
  186. {
  187. f_vecFootPos.y += GameMain.Instance.CMSystem.VRCameraHeightSitOffs;
  188. }
  189. else
  190. {
  191. f_vecFootPos.y += this.GetYfromFloor(this.GetRealHeadTransform().position);
  192. }
  193. this.SetRealHeadPos(f_vecFootPos, false);
  194. }
  195. else
  196. {
  197. this.SetRealHeadPos(f_vecFootPos, false);
  198. }
  199. }
  200. public override Transform GetBaseHeadTransform()
  201. {
  202. return this.m_trBaseHead;
  203. }
  204. public override Transform GetRealHeadTransform()
  205. {
  206. return this.m_trRealHead;
  207. }
  208. private void SetTransform(Vector3 f_vecTargetPosWorld, Vector2 f_vecRot, float f_fDistance)
  209. {
  210. this.m_trTarget.position = f_vecTargetPosWorld;
  211. this.m_vRot = f_vecRot;
  212. this.m_trVirtualMy.rotation = Quaternion.identity;
  213. this.m_trVirtualMy.Rotate(new Vector3(0f, f_vecRot.x, 0f), Space.World);
  214. this.m_trVirtualMy.Rotate(new Vector3(f_vecRot.y, 0f, 0f), Space.Self);
  215. this.m_trVirtualMy.position = this.m_trVirtualMy.rotation * new Vector3(0f, 0f, -f_fDistance) + this.m_trTarget.position;
  216. this.m_trBaseHead.position = this.m_trVirtualMy.position + (this.m_trTarget.position - this.m_trVirtualMy.position) * 0.5f;
  217. Quaternion rotation = Quaternion.LookRotation(new Vector3(this.m_trTarget.position.x, 0f, this.m_trTarget.position.z) - new Vector3(this.m_trVirtualMy.position.x, 0f, this.m_trVirtualMy.position.z));
  218. this.m_trBaseHead.rotation = rotation;
  219. this.UpdateRealPosRot();
  220. }
  221. public override void Reset(CameraMain.CameraType f_eType, bool f_bControl)
  222. {
  223. iTween.StopAndSkipToEnd(base.gameObject);
  224. base.RemoveChaseCameraAll();
  225. this.SetTargetPos(new Vector3(0f, 1.5f, 0f), true);
  226. }
  227. public override void FadeOutNoUI(float f_fTime = 0.5f, bool f_bSkipable = true)
  228. {
  229. }
  230. public override void FadeInNoUI(float f_fTime = 0.5f, bool f_bSkipable = true)
  231. {
  232. }
  233. protected override float GetFadeIntensity()
  234. {
  235. return this.m_FadeTargetCameraOVR.intensity;
  236. }
  237. protected override void OnProcessFade(float f_fIntensity)
  238. {
  239. this.m_FadeTargetCameraOVR.intensity = f_fIntensity;
  240. }
  241. protected override void OnOverlayState(bool f_bEnable)
  242. {
  243. this.m_FadeTargetCameraOVR.enabled = f_bEnable;
  244. }
  245. public override Ray GetForwardRay()
  246. {
  247. return new Ray(this.m_trCenterEye.position, this.m_trCenterEye.rotation * Vector3.forward);
  248. }
  249. public override void UpdateHeadScale()
  250. {
  251. float ovrHeadScale = GameMain.Instance.CMSystem.OvrHeadScale;
  252. base.gameObject.transform.localScale = new Vector3(ovrHeadScale, ovrHeadScale, ovrHeadScale);
  253. this.m_trBaseHead.localScale = base.gameObject.transform.localScale;
  254. }
  255. protected override void UpdateRealPosRot()
  256. {
  257. base.transform.position = this.m_trBaseRoomBase.position;
  258. base.transform.rotation = this.m_trBaseRoomBase.rotation;
  259. }
  260. public override void MirrorSwitch()
  261. {
  262. if (this.m_camClearCam != null)
  263. {
  264. if (!this.m_camClearCam.enabled || !this.m_camClearCam.gameObject.activeSelf)
  265. {
  266. this.m_camClearCam.enabled = true;
  267. this.m_camClearCam.gameObject.SetActive(true);
  268. this.m_view.enabled = false;
  269. }
  270. else
  271. {
  272. this.m_camClearCam.enabled = false;
  273. this.m_camClearCam.gameObject.SetActive(false);
  274. this.m_view.enabled = true;
  275. }
  276. }
  277. }
  278. private void OnDrawGizmos()
  279. {
  280. if (this.m_trTarget != null)
  281. {
  282. Gizmos.DrawIcon(this.m_trTarget.position, "gizmo_eye.png", true);
  283. if (base.enabled)
  284. {
  285. Gizmos.color = Color.cyan;
  286. Gizmos.DrawRay(this.m_trVirtualMy.position, this.m_trTarget.position - this.m_trVirtualMy.position);
  287. Gizmos.DrawRay(this.m_trCenterEye.position, this.m_trCenterEye.rotation * Vector3.forward * 10f);
  288. }
  289. }
  290. }
  291. private Camera m_camClearCam;
  292. private SteamVR_GameView m_view;
  293. private enum MouseButtonDown
  294. {
  295. MBD_LEFT,
  296. MBD_RIGHT,
  297. MBD_MIDDLE
  298. }
  299. }