123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using UnityEngine;
- using System.Collections;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- using System.Collections.Generic;
- namespace CurvedUI
- {
- /// <summary>
- /// Raycaster used for interactions with 3D objects.
- /// </summary>
- public class CurvedUIPhysicsRaycaster : PhysicsRaycaster {
- #region VARIABLES AND SETTINGS
- //settings
- [SerializeField]
- protected LayerMask eventMask = -1; //Which layers should we raycast on?
- //[SerializeField]
- //protected int sortOrder = 20;
- //variables
- RaycastHit hitInfo;
- RaycastResult result;
- #endregion
- #region CONSTRUCTOR
- protected CurvedUIPhysicsRaycaster() { }
- #endregion
- #region RAYCASTING
- public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
- {
- //check if we have camera from which to cast a ray
- if (CurvedUIInputModule.Instance == null || CurvedUIInputModule.Instance.EventCamera == null)
- return;
- if (Physics.Raycast(CurvedUIInputModule.Instance.GetEventRay(), out hitInfo, float.PositiveInfinity, CompoundEventMask))
- {
- if (hitInfo.collider.GetComponentInParent<CurvedUISettings>()) return; //a canvas is hit - these raycastsResults are handled by CurvedUIRaycasters
- result = new RaycastResult
- {
- gameObject = hitInfo.collider.gameObject,
- module = this,
- distance = hitInfo.distance,
- index = resultAppendList.Count,
- worldPosition = hitInfo.point,
- worldNormal = hitInfo.normal,
- };
- resultAppendList.Add(result);
- }
- //Debug.Log("CUIPhysRaycaster: " + resultAppendList.Count);
- }
- #endregion
- #region SETTERS AND GETTERS
- /// <summary>
- /// This Component's event mask + eventCamera's event mask.
- /// </summary>
- public int CompoundEventMask {
- get { return (eventCamera != null) ? eventCamera.cullingMask & eventMask : -1; }
- }
- /// <summary>
- /// Layer mask used to filter raycasts. Combined with eventCamera's culling mask.
- /// </summary>
- public LayerMask EventMask {
- get { return eventMask; }
- set { eventMask = value; }
- }
- /// <summary>
- /// Camera used to process events
- /// </summary>
- public override Camera eventCamera {
- get { return CurvedUIInputModule.Instance? CurvedUIInputModule.Instance.EventCamera : null; }
- }
- public virtual int Depth {
- get { return (eventCamera != null) ? (int)eventCamera.depth : 0xFFFFFF; }
- }
- //public override int sortOrderPriority {
- // get { return sortOrder; }
- //}
- #endregion
- }
- }
|