VRWfChangeCanvas.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(RectTransform))]
  4. [RequireComponent(typeof(Canvas))]
  5. [RequireComponent(typeof(CanvasGroup))]
  6. public abstract class VRWfChangeCanvas : MonoBehaviour
  7. {
  8. public virtual bool isVisible
  9. {
  10. get
  11. {
  12. return this.canvasGroup.alpha != 0f;
  13. }
  14. set
  15. {
  16. this.canvasGroup.alpha = (float)((!value) ? 0 : 1);
  17. }
  18. }
  19. protected RenderMode renderMode
  20. {
  21. get
  22. {
  23. return this.parentCanvas.renderMode;
  24. }
  25. set
  26. {
  27. this.parentCanvas.renderMode = value;
  28. if (this.parentCanvas.renderMode == RenderMode.ScreenSpaceOverlay)
  29. {
  30. this.parentCanvas.pixelPerfect = true;
  31. }
  32. }
  33. }
  34. protected virtual void Awake()
  35. {
  36. this.rectTransform = base.GetComponent<RectTransform>();
  37. this.parentCanvas = base.GetComponent<Canvas>();
  38. this.canvasGroup = base.GetComponent<CanvasGroup>();
  39. }
  40. public virtual void ChangeDeviceMode(GameMain.VRDeviceType devideType)
  41. {
  42. if (devideType == GameMain.VRDeviceType.NON || devideType == GameMain.VRDeviceType.RIFT || devideType == GameMain.VRDeviceType.FOVE)
  43. {
  44. this.isVisible = true;
  45. this.ChangeDrawMode(devideType != GameMain.VRDeviceType.NON);
  46. }
  47. else
  48. {
  49. this.isVisible = false;
  50. }
  51. }
  52. public abstract void ChangeDrawMode(bool worldMode);
  53. protected virtual void FixedUpdate()
  54. {
  55. if (!this.updateWorldPosition || this.parentCanvas.renderMode != RenderMode.WorldSpace || GameMain.Instance.OvrMgr == null)
  56. {
  57. return;
  58. }
  59. OvrCamera ovrCamera = GameMain.Instance.OvrMgr.OvrCamera;
  60. this.rectTransform.position = ovrCamera.m_goCenterEye.transform.position + ovrCamera.m_goCenterEye.transform.forward * this.distanceFromCamera;
  61. this.rectTransform.rotation = Quaternion.LookRotation(this.rectTransform.position - ovrCamera.m_goCenterEye.transform.position);
  62. }
  63. [SerializeField]
  64. [Tooltip("ワールド座標での位置を更新し続けるかどうか")]
  65. public bool updateWorldPosition = true;
  66. [SerializeField]
  67. [Tooltip("ワールド座標モードでのカメラからの距離")]
  68. public float distanceFromCamera = 0.2f;
  69. protected RectTransform rectTransform;
  70. protected CanvasGroup canvasGroup;
  71. protected Canvas parentCanvas;
  72. }