using System; using MotionFramework; using UnityEngine; namespace Framework.Scripts.Runtime.Engine.Engine.Camera { public class CameraRaycastComponent : IRaycastable { public LayerMask RaycastLayerMask = ~0; public float RaycastDistance = 100f; public event Action OnRaycastHit; private UnityEngine.Camera camera; public void Init() { camera=UnityEngine.Camera.main; } public void PerformRaycast() { if (camera == null) { Debug.LogError("没有找到主摄像机"); return; } Ray ray = camera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit, RaycastDistance, RaycastLayerMask)) { OnRaycastHit?.Invoke(hit); } } } }