123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class ColliderEventVR : MonoBehaviour
- {
- private void Awake()
- {
- ColliderEventVR.isTouch = false;
- ColliderEventVR.isActive = true;
- ColliderEventVR.colliderList = new List<GameObject>();
- }
- private void Update()
- {
- if (!GameMain.Instance.VRMode)
- {
- if (NInput.GetMouseButtonDown(0))
- {
- if (UICamera.Raycast(Input.mousePosition))
- {
- return;
- }
- Ray ray = GameMain.Instance.MainCamera.camera.ScreenPointToRay(Input.mousePosition);
- RaycastHit raycastHit = default(RaycastHit);
- if (!Physics.Raycast(ray, out raycastHit, float.PositiveInfinity, LayerMask.GetMask(new string[]
- {
- LayerMask.LayerToName(base.gameObject.layer)
- })) || raycastHit.transform != base.transform)
- {
- return;
- }
- if (this.onMouseDown != null)
- {
- this.onMouseDown();
- }
- return;
- }
- else if (NInput.GetMouseButtonUp(0))
- {
- if (UICamera.Raycast(Input.mousePosition))
- {
- return;
- }
- Ray ray2 = GameMain.Instance.MainCamera.camera.ScreenPointToRay(Input.mousePosition);
- RaycastHit raycastHit2 = default(RaycastHit);
- if (!Physics.Raycast(ray2, out raycastHit2, float.PositiveInfinity, LayerMask.GetMask(new string[]
- {
- LayerMask.LayerToName(base.gameObject.layer)
- })) || raycastHit2.transform != base.transform)
- {
- return;
- }
- if (this.onMouseUp != null)
- {
- this.onMouseUp();
- }
- return;
- }
- }
- }
- private void FixedUpdate()
- {
- if (GameMain.Instance.VRMode && ColliderEventVR.isActive && ColliderEventVR.isTouch && ColliderEventVR.colliderList.Count > 0 && ColliderEventVR.colliderList[0] == base.gameObject)
- {
- ColliderEventVR.isActive = false;
- if (this.onMouseDown != null)
- {
- this.onMouseDown();
- }
- }
- }
- private void OnTriggerEnter(Collider collider)
- {
- if (!ColliderEventVR.colliderList.Contains(base.gameObject))
- {
- ColliderEventVR.colliderList.Add(base.gameObject);
- }
- if (GameMain.Instance.VRMode && !ColliderEventVR.isTouch && collider.gameObject.layer == LayerMask.NameToLayer("OvrGrabHand"))
- {
- ColliderEventVR.isTouch = true;
- }
- }
- private void OnTriggerExit(Collider collider)
- {
- if (ColliderEventVR.colliderList.Contains(base.gameObject))
- {
- ColliderEventVR.colliderList.Remove(base.gameObject);
- }
- if (ColliderEventVR.colliderList.Count <= 0)
- {
- ColliderEventVR.isActive = true;
- ColliderEventVR.isTouch = false;
- }
- }
- public Action onMouseDown;
- public Action onMouseUp;
- private static bool isTouch;
- private static bool isActive = true;
- private static List<GameObject> colliderList;
- }
|