123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- using System;
- using System.Collections;
- using UnityEngine;
- using UnityEngine.UI;
- public class VRControllerLaserCast : MonoBehaviour
- {
- public float raycastMaxLength
- {
- get
- {
- return this.m_RaycastMaxLength;
- }
- set
- {
- this.m_RaycastMaxLength = value;
- }
- }
- public float PosScreenX
- {
- get
- {
- return this.m_PosScreenX;
- }
- }
- public float PosScreenY
- {
- get
- {
- return this.m_PosScreenY;
- }
- }
- private void Start()
- {
- GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
- if (vrdeviceTypeID == GameMain.VRDeviceType.NON || vrdeviceTypeID == GameMain.VRDeviceType.RIFT || vrdeviceTypeID == GameMain.VRDeviceType.FOVE)
- {
- base.gameObject.SetActive(false);
- return;
- }
- base.StartCoroutine(this.Coroutine_Debug_FindParent());
- }
- private IEnumerator Coroutine_Debug_FindParent()
- {
- for (int i = 0; i < 4; i++)
- {
- yield return null;
- }
- while (this.m_Controller == null)
- {
- this.m_Controller = ((!this.m_IsLeftHand) ? GameMain.Instance.OvrMgr.ovr_obj.right_controller.controller : GameMain.Instance.OvrMgr.ovr_obj.left_controller.controller);
- yield return null;
- }
- GameObject hand = this.m_Controller.gameObject;
- VRTestInputModule.Instance.AddController(this);
- yield break;
- }
- private void Update()
- {
- if (!this.m_Controller)
- {
- if (GameMain.Instance == null)
- {
- return;
- }
- this.m_Controller = ((!this.m_IsLeftHand) ? GameMain.Instance.OvrMgr.ovr_obj.right_controller.controller : GameMain.Instance.OvrMgr.ovr_obj.left_controller.controller);
- if (!this.m_Controller)
- {
- return;
- }
- VRTestInputModule.Instance.AddController(this);
- }
- AVRController controller = this.m_Controller;
- if (!controller.UIRayEnable)
- {
- if (this.m_RaycastLineRenderer)
- {
- this.m_RaycastLineRenderer.gameObject.SetActive(false);
- }
- if (this.m_RaycastPointEffect)
- {
- this.m_RaycastPointEffect.SetActive(false);
- }
- return;
- }
- this.UpdateOffSet(controller.UIRayTrans);
- }
- public void UpdateOffSet(Transform trans)
- {
- base.transform.position = trans.position;
- base.transform.rotation = trans.rotation;
- base.transform.localScale = trans.lossyScale;
- }
- private void OnDestroy()
- {
- if (VRTestInputModule.Instance == null)
- {
- return;
- }
- VRTestInputModule.Instance.RemoveController(this);
- }
- public virtual bool GetButtonDown()
- {
- return this.m_Controller.VRControllerButtons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
- }
- public virtual bool GetButtonUp()
- {
- return this.m_Controller.VRControllerButtons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
- }
- public virtual Vector2 GetScrollDelta()
- {
- return Vector2.zero;
- }
- public virtual bool EnableUIRay()
- {
- return this.m_Controller && this.m_Controller.UIRayEnable;
- }
- public virtual void SetRaycastHitPoint(Vector3 WorldPos, Vector3 WorldNormal, float rayLength, GameObject HitObject)
- {
- bool active = false;
- if (HitObject != null && HitObject.GetComponent<RectTransform>() != null)
- {
- active = true;
- }
- if (!this.m_Controller.UIRayEnable)
- {
- return;
- }
- rayLength += this.m_RayLength;
- if (HitObject == null)
- {
- rayLength = this.m_RaycastMaxLength;
- }
- if (this.m_RaycastLineRenderer)
- {
- if (HitObject)
- {
- this.m_RaycastLineRenderer.SetColors(this.m_LineColorHighlighted, Color.white);
- }
- else
- {
- this.m_RaycastLineRenderer.SetColors(this.m_LineColorNormal, Color.white);
- }
- this.m_RaycastLineRenderer.SetPosition(0, base.transform.position);
- this.m_RaycastLineRenderer.SetPosition(1, base.transform.position + base.transform.forward * rayLength);
- this.m_RaycastLineRenderer.gameObject.SetActive(true);
- }
- if (this.m_RaycastPointEffect)
- {
- this.m_RaycastPointEffect.transform.position = base.transform.position + base.transform.forward * rayLength;
- if (HitObject)
- {
- this.m_RaycastPointEffect.transform.rotation = HitObject.transform.rotation;
- }
- this.m_RaycastPointEffect.SetActive(active);
- }
- }
- public void OnEventRayHitEnter(GameObject Obj)
- {
- bool flag = Obj.GetComponent<RectTransform>() != null;
- bool flag2 = false;
- Selectable component = Obj.GetComponent<Selectable>();
- if (component)
- {
- flag2 = component.interactable;
- }
- if (flag && flag2)
- {
- GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
- }
- }
- public void OnEventRayHitExit(GameObject Obj)
- {
- }
- public void OnEventClick(GameObject Obj)
- {
- bool flag = Obj.GetComponent<RectTransform>();
- bool flag2 = false;
- Selectable component = Obj.GetComponent<Selectable>();
- if (component)
- {
- flag2 = component.interactable;
- }
- if (flag && flag2)
- {
- GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Click);
- }
- }
- [SerializeField]
- private AVRController m_Controller;
- [SerializeField]
- private bool m_IsLeftHand;
- [SerializeField]
- private float m_RaycastMaxLength = 3f;
- [SerializeField]
- private LineRenderer m_RaycastLineRenderer;
- [SerializeField]
- protected GameObject m_RaycastPointEffect;
- [SerializeField]
- private Color m_LineColorNormal = Color.red;
- [SerializeField]
- private Color m_LineColorHighlighted = Color.green;
- [SerializeField]
- private float m_RayLength = 0.01f;
- protected float m_PosScreenX = 0.5f;
- protected float m_PosScreenY = 0.5f;
- }
|