1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- namespace XRTool.WorldUI
- {
- /// <summary>
- /// Simple event system using physics raycasts.
- /// </summary>
- [AddComponentMenu("Event/XR Physics Raycaster")]
- [RequireComponent(typeof(Camera))]
- public class XRPhysicsRaycaster : PhysicsRaycaster
- {
- private RaycastResult minResult;
- private PhysicsRayConf layerConf;
- public PhysicsRayConf LayerConf { get => layerConf; set => layerConf = value; }
- protected override void Start()
- {
- base.Start();
- LayerConf = Resources.Load<PhysicsRayConf>("PhysicsRayConf");
- eventCamera.cullingMask = LayerConf.eventMask;
- eventMask = LayerConf.eventMask;
- }
- public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
- {
- if (resultAppendList != null && resultAppendList.Count > 0)
- {
- float minDis = float.MaxValue;
- int minIndex = 0;
- for (int i = 0; i < resultAppendList.Count; i++)
- {
- RaycastResult result = resultAppendList[i];
- if (result.distance < minDis)
- {
- minDis = result.distance;
- minIndex = i;
- }
- }
- minResult = resultAppendList[minIndex];
- resultAppendList.Clear();
- resultAppendList.Add(minResult);
- base.Raycast(eventData, resultAppendList);
- }
- else
- {
- base.Raycast(eventData, resultAppendList);
- }
- }
- }
- }
|