using Framework.Scripts.Runtime.Engine.Engine.Camera;
using Framework.Scripts.Runtime.Engine.Engine.Camera.CameraControl;
using UnityEngine;

namespace TestScripts
{
    public class tttt : MonoBehaviour
    {
        private IRaycastable _raycastComponent;
        private ICameraController _cameraControlComponent;


        void Awake()
        {
            // 为组件赋值，可以通过查找对象或者直接赋值的方式
            _raycastComponent = new CameraRaycastComponent();
            _cameraControlComponent = new CameraControlComponent();

            if (_raycastComponent == null || _cameraControlComponent == null)
            {
                Debug.LogError("缺少必要的组件");
            }
        }

        void OnEnable()
        {
            _raycastComponent.OnRaycastHit += HandleRaycastHit;
        }

        void OnDisable()
        {
            _raycastComponent.OnRaycastHit -= HandleRaycastHit;
        }

        // 处理射线命中事件并打印物体名称
        void HandleRaycastHit(RaycastHit hit)
        {
            Debug.Log("Raycast hit: " + hit.collider.name);
            // 在这里可以添加更多处理逻辑，比如交互或特效
        }

        void Update()
        {
            // 调用射线功能
            if (Input.GetMouseButtonDown(0)) // 比如当按下鼠标左键时
            {
                _raycastComponent?.PerformRaycast();
            }

            // 调用镜头控制功能
            _cameraControlComponent?.ControlCamera();
        }
    }
}