OvrTablet.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class OvrTablet : MonoBehaviour
  5. {
  6. public float Size
  7. {
  8. get
  9. {
  10. return base.transform.localScale.x;
  11. }
  12. set
  13. {
  14. if (GameMain.Instance.VRDeviceTypeID != GameMain.VRDeviceType.NON)
  15. {
  16. float num = Mathf.Clamp(value, 0.5f, 3f);
  17. base.transform.localScale = new Vector3(num, num, num);
  18. }
  19. }
  20. }
  21. public bool IsRotDown
  22. {
  23. get
  24. {
  25. return this.m_bRotDown;
  26. }
  27. }
  28. public bool IsSideBack
  29. {
  30. get
  31. {
  32. return this.m_bSideBack;
  33. }
  34. }
  35. public bool UIStickyHead
  36. {
  37. get
  38. {
  39. return this.m_bUIStickyHead;
  40. }
  41. set
  42. {
  43. this.m_bUIStickyHead = value;
  44. }
  45. }
  46. private void Awake()
  47. {
  48. this.m_trScreen = base.transform.Find("Screen");
  49. NDebug.Assert(this.m_trScreen != null, "OvrTablet Screenが見つかりません。");
  50. this.m_vScaleBackup = base.transform.localScale;
  51. this.m_vScaleNow = this.m_vScaleBackup;
  52. this.m_trButton = base.transform.Find("Button");
  53. NDebug.Assert(this.m_trButton != null, "OvrTablet Buttonが見つかりません。");
  54. this.m_trTabletFrame = base.transform.Find("Tablet");
  55. NDebug.Assert(this.m_trTabletFrame != null, "OvrTablet Tabletが見つかりません。");
  56. }
  57. public void Init(GameObject f_goCenterEye)
  58. {
  59. this.m_trOvrUiTabletResetParent = UTY.GetChildObject(f_goCenterEye, "TabletUIResetParent", false).transform;
  60. this.m_trOvrUiTabletResetPos = UTY.GetChildObject(this.m_trOvrUiTabletResetParent.gameObject, "TabletUIResetPos", false).transform;
  61. }
  62. private void OnEnable()
  63. {
  64. this.SetVisible(true);
  65. }
  66. private void OnDisable()
  67. {
  68. this.SetVisible(false);
  69. }
  70. public void SetVisible(bool f_bVisible)
  71. {
  72. Renderer[] componentsInChildren = base.GetComponentsInChildren<Renderer>(true);
  73. for (int i = 0; i < componentsInChildren.Length; i++)
  74. {
  75. componentsInChildren[i].enabled = f_bVisible;
  76. }
  77. Collider[] componentsInChildren2 = base.GetComponentsInChildren<Collider>(true);
  78. for (int j = 0; j < componentsInChildren2.Length; j++)
  79. {
  80. componentsInChildren2[j].enabled = f_bVisible;
  81. }
  82. this.m_bVisible = f_bVisible;
  83. this.AvoidFloorAndChara();
  84. }
  85. public bool IsVisible
  86. {
  87. get
  88. {
  89. return this.m_bVisible;
  90. }
  91. }
  92. public bool IsHitPointerArea(Vector3 f_vWorldPoint)
  93. {
  94. if (!this.IsVisible)
  95. {
  96. return false;
  97. }
  98. Vector3 vector = base.transform.InverseTransformPoint(f_vWorldPoint);
  99. float num = this.m_vHitArea.x * 0.5f;
  100. float num2 = this.m_vHitArea.z * 0.5f;
  101. float num3 = this.m_vHitArea.y * 0.5f;
  102. if (-num <= vector.x && vector.x <= num && -num2 <= vector.z && vector.z <= num2 && -num3 <= vector.y && vector.y <= num3)
  103. {
  104. Debug.DrawLine(f_vWorldPoint, base.transform.TransformPoint(vector.x, 0f, vector.z), Color.green);
  105. return true;
  106. }
  107. Debug.DrawLine(f_vWorldPoint, base.transform.TransformPoint(vector.x, 0f, vector.z), Color.gray);
  108. return false;
  109. }
  110. public void UIPosReset(float f_fOffsetRotY = 0f)
  111. {
  112. if (!base.enabled || !base.gameObject.activeInHierarchy)
  113. {
  114. return;
  115. }
  116. if (GameMain.Instance.VRDeviceTypeID != GameMain.VRDeviceType.NON)
  117. {
  118. base.StartCoroutine(this.CoUIPosReset(f_fOffsetRotY));
  119. }
  120. }
  121. private IEnumerator CoUIPosReset(float f_fOffsetRotY = 0f)
  122. {
  123. bool bSticky = true;
  124. float timeBack = Time.realtimeSinceStartup;
  125. if (bSticky)
  126. {
  127. Transform trHead = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  128. if (!(trHead == null))
  129. {
  130. Vector3 vHeadEuler = trHead.rotation.eulerAngles;
  131. this.m_trOvrUiTabletResetParent.rotation = Quaternion.Euler(vHeadEuler.x, vHeadEuler.y + f_fOffsetRotY, 0f);
  132. base.transform.position = this.m_trOvrUiTabletResetPos.position;
  133. base.transform.rotation = this.m_trOvrUiTabletResetPos.rotation;
  134. this.AvoidFloorAndChara();
  135. yield return null;
  136. }
  137. }
  138. this.m_vWorldPos = base.transform.position;
  139. yield break;
  140. }
  141. public void AvoidFloorAndChara()
  142. {
  143. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  144. {
  145. return;
  146. }
  147. bool flag = false;
  148. float num = 0.15f;
  149. float num2 = 0.25f * base.transform.localScale.x;
  150. Ray ray = new Ray(base.transform.position, Vector3.down);
  151. float num3 = 0f;
  152. RaycastHit raycastHit;
  153. if (Physics.Raycast(ray, out raycastHit, float.PositiveInfinity, 512))
  154. {
  155. num3 = Vector3.Distance(raycastHit.point, base.transform.position);
  156. }
  157. else
  158. {
  159. ray.origin = new Vector3(base.transform.position.x, 100f, base.transform.position.z);
  160. ray.direction = Vector3.down;
  161. if (Physics.Raycast(ray, out raycastHit, float.PositiveInfinity, 512))
  162. {
  163. num3 = Vector3.Distance(raycastHit.point, base.transform.position);
  164. }
  165. }
  166. if (raycastHit.collider != null && num3 < num2 + 0.1f)
  167. {
  168. base.transform.position = new Vector3(base.transform.position.x, raycastHit.point.y + num2 + 0.1f, base.transform.position.z);
  169. flag = true;
  170. }
  171. if (GameMain.Instance.OvrMgr != null && GameMain.Instance.OvrMgr.OvrCamera != null)
  172. {
  173. Transform realHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  174. int maidCount = GameMain.Instance.CharacterMgr.GetMaidCount();
  175. for (int i = 0; i < maidCount; i++)
  176. {
  177. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(i);
  178. if (maid != null && maid.Visible && maid.body0 != null && maid.body0.isLoadedBody)
  179. {
  180. foreach (Transform transform in new Transform[]
  181. {
  182. maid.body0.trsHead,
  183. maid.body0.Spine,
  184. maid.body0.Spine0a,
  185. maid.body0.Spine1a,
  186. maid.body0.UpperArmL,
  187. maid.body0.UpperArmR
  188. })
  189. {
  190. if (!(transform == null))
  191. {
  192. if (Vector3.Distance(base.transform.position, transform.position) < num + num2)
  193. {
  194. Vector3 normalized = (realHeadTransform.position - transform.position).normalized;
  195. Vector3 normalized2 = Vector3.Reflect(-normalized, Vector3.up).normalized;
  196. Vector3 normalized3 = Vector3.Cross(normalized, normalized2).normalized;
  197. Vector3 a = base.transform.position - normalized3 * (num + num2 + 0.1f);
  198. float angle = Vector3.Angle((transform.position - realHeadTransform.position).normalized, (a - realHeadTransform.position).normalized);
  199. base.transform.RotateAround(realHeadTransform.position, Vector3.up, angle);
  200. flag = true;
  201. }
  202. }
  203. }
  204. }
  205. }
  206. if (flag)
  207. {
  208. base.transform.LookAt(realHeadTransform.position);
  209. base.transform.Rotate(-90f, 180f, 0f, Space.Self);
  210. }
  211. }
  212. this.m_vWorldPos = base.transform.position;
  213. }
  214. private void Update()
  215. {
  216. if (!this.IsVisible)
  217. {
  218. return;
  219. }
  220. if (this.m_bUIStickyHead)
  221. {
  222. Transform realHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  223. float num = (this.m_vWorldPos - realHeadTransform.position).magnitude;
  224. Vector3 normalized = (this.m_vWorldPos - realHeadTransform.position).normalized;
  225. bool flag = false;
  226. if (num < 0.1f || 0.5f < num)
  227. {
  228. if (0.5f < num)
  229. {
  230. flag = true;
  231. }
  232. num = Mathf.Clamp(num, 0.1f, 0.5f);
  233. this.m_vWorldPos = realHeadTransform.position + normalized * num;
  234. }
  235. Vector3 normalized2 = GameMain.Instance.OvrMgr.OvrCamera.EyeRay.GetRay().direction.normalized;
  236. float num2 = Vector3.Angle(normalized2, normalized);
  237. if (num2 > 60f)
  238. {
  239. Vector3 normalized3 = Vector3.RotateTowards(normalized, normalized2, 1f - 60f / num2, 0f).normalized;
  240. this.m_vWorldPos = realHeadTransform.position + normalized3 * num;
  241. flag = true;
  242. }
  243. base.transform.position = this.m_vWorldPos;
  244. if (flag)
  245. {
  246. base.transform.LookAt(GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform().position);
  247. base.transform.Rotate(new Vector3(-90f, 0f, 0f), Space.Self);
  248. }
  249. }
  250. Vector3 forward = base.transform.forward;
  251. if (GameMain.Instance.OvrMgr != null && GameMain.Instance.OvrMgr.OvrCamera != null)
  252. {
  253. Transform realHeadTransform2 = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  254. if (Vector3.Dot((realHeadTransform2.position - base.transform.position).normalized, base.transform.up) < 0f)
  255. {
  256. this.m_bSideBack = true;
  257. }
  258. else
  259. {
  260. this.m_bSideBack = false;
  261. }
  262. }
  263. if (GameMain.Instance.VRDeviceTypeID != GameMain.VRDeviceType.NON)
  264. {
  265. if (Vector3.Dot(forward, Vector3.down) < 0f)
  266. {
  267. this.m_trScreen.localRotation = Quaternion.Euler(90f, 0f, 0f);
  268. this.m_bRotDown = false;
  269. }
  270. else
  271. {
  272. this.m_trScreen.localRotation = Quaternion.Euler(-90f, 0f, 0f);
  273. this.m_bRotDown = true;
  274. }
  275. }
  276. else
  277. {
  278. this.m_trScreen.localRotation = Quaternion.Euler(90f, 0f, 0f);
  279. this.m_bRotDown = false;
  280. }
  281. float vrcameraFov = GameMain.Instance.CMSystem.VRCameraFov;
  282. if (this.m_fBackFOV != vrcameraFov)
  283. {
  284. float num3 = (vrcameraFov - 30f) / 30f;
  285. float num4 = this.m_fTabletScaleMin + (this.m_fTabletScaleMax - this.m_fTabletScaleMin) * num3;
  286. this.m_vScaleNow = new Vector3(num4, num4, num4);
  287. this.m_fBackFOV = vrcameraFov;
  288. }
  289. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  290. {
  291. float num5 = (float)Screen.width / (float)Screen.height;
  292. if (num5 < 1.7777f)
  293. {
  294. float num6 = this.m_vScaleNow.x * (num5 / 1.7777f);
  295. base.transform.localScale = new Vector3(num6, num6, num6);
  296. }
  297. else
  298. {
  299. base.transform.localScale = this.m_vScaleNow;
  300. }
  301. }
  302. bool isVisibleMessageViewer = GameMain.Instance.MsgWnd.IsVisibleMessageViewer;
  303. if (this.m_bBackVisibleMessageViewer != isVisibleMessageViewer)
  304. {
  305. if (GameMain.Instance.CMSystem.SConfig.OvrTabletFrameHideWhenMsgWndVisible)
  306. {
  307. this.m_trTabletFrame.gameObject.SetActive(!isVisibleMessageViewer);
  308. this.m_trButton.gameObject.SetActive(!isVisibleMessageViewer);
  309. }
  310. else
  311. {
  312. this.m_trTabletFrame.gameObject.SetActive(true);
  313. this.m_trButton.gameObject.SetActive(true);
  314. }
  315. this.m_bBackVisibleMessageViewer = isVisibleMessageViewer;
  316. }
  317. }
  318. public Vector3 m_vHitArea = new Vector3(1.3f, 1f, 1f);
  319. public Transform m_trOvrUiTabletResetParent;
  320. public Transform m_trOvrUiTabletResetPos;
  321. private Transform m_trScreen;
  322. private bool m_bRotDown;
  323. private bool m_bSideBack;
  324. private bool m_bVisible = true;
  325. private bool m_bUIStickyHead;
  326. private Vector3 m_vWorldPos;
  327. private Vector3 m_vScaleBackup;
  328. private Vector3 m_vScaleNow;
  329. private float m_fDistance = 1f;
  330. private float m_fBackFOV;
  331. private float m_fTabletScaleMin = 0.1543127f;
  332. private float m_fTabletScaleMax = 0.3287759f;
  333. private bool m_bBackVisibleMessageViewer;
  334. private Transform m_trButton;
  335. private Transform m_trTabletFrame;
  336. }