using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Collections.Generic;
namespace CurvedUI
{
///
/// Raycaster used for interactions with 3D objects.
///
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 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()) 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
///
/// This Component's event mask + eventCamera's event mask.
///
public int CompoundEventMask {
get { return (eventCamera != null) ? eventCamera.cullingMask & eventMask : -1; }
}
///
/// Layer mask used to filter raycasts. Combined with eventCamera's culling mask.
///
public LayerMask EventMask {
get { return eventMask; }
set { eventMask = value; }
}
///
/// Camera used to process events
///
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
}
}