55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace CurvedUI
|
|
{
|
|
public class CurvedUILaserBeam : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Transform LaserBeamTransform;
|
|
|
|
[SerializeField]
|
|
private Transform LaserBeamDot;
|
|
|
|
[SerializeField]
|
|
private bool CollideWithMyLayerOnly;
|
|
|
|
[SerializeField]
|
|
private bool hideWhenNotAimingAtCanvas;
|
|
|
|
protected void Update()
|
|
{
|
|
Ray ray = new Ray(base.transform.position, base.transform.forward);
|
|
if (!LaserBeamTransform || !LaserBeamDot)
|
|
{
|
|
return;
|
|
}
|
|
float num = 10000f;
|
|
int layerMask = -1;
|
|
if (CollideWithMyLayerOnly)
|
|
{
|
|
layerMask = 1 << base.gameObject.layer;
|
|
}
|
|
RaycastHit hitInfo;
|
|
if (Physics.Raycast(ray, out hitInfo, num, layerMask))
|
|
{
|
|
num = Vector3.Distance(hitInfo.point, base.transform.position);
|
|
CurvedUISettings componentInParent = hitInfo.collider.GetComponentInParent<CurvedUISettings>();
|
|
if (componentInParent != null)
|
|
{
|
|
num = ((componentInParent.GetObjectsUnderPointer().FindAll((GameObject x) => x != null && x.GetComponent<Graphic>() != null && x.GetComponent<Graphic>().depth != -1).Count != 0) ? Vector3.Distance(hitInfo.point, base.transform.position) : 10000f);
|
|
}
|
|
else if (hideWhenNotAimingAtCanvas)
|
|
{
|
|
num = 0f;
|
|
}
|
|
}
|
|
else if (hideWhenNotAimingAtCanvas)
|
|
{
|
|
num = 0f;
|
|
}
|
|
LaserBeamTransform.localScale = LaserBeamTransform.localScale.ModifyZ(num);
|
|
}
|
|
}
|
|
}
|