using Framework.Scripts.Runtime.Engine.Engine.Camera; using Framework.Scripts.Runtime.Engine.Engine.Camera.UIMoveTarget; using TMPro; using UnityEngine; using UnityEngine.EventSystems; namespace DefaultNamespace { public class ToolsCameraComponent : MonoBehaviour { private IRaycastable _raycastComponent; private IUIFollow _uiFollow; public RectTransform ui; private void Awake() { _raycastComponent = new CameraRaycastComponent(); _uiFollow = new CameraFollowComponent(); } void OnEnable() { _raycastComponent.OnRaycastHit += HandleRaycastHit; } // 处理射线命中事件并打印物体名称 void HandleRaycastHit(RaycastHit hit) { if (!EventSystem.current.IsPointerOverGameObject()) { if (hit.collider.CompareTag("Tools")) { // Debug.Log("Raycast hit: " + hit.collider.name); _uiFollow.FollowObject(hit.collider.transform, ui, Camera.main); ui.gameObject.SetActive(true); ui.transform.Find("Text").GetComponent().text = hit.transform.name; } else { ui.gameObject.SetActive(false); } } else { ui.gameObject.SetActive(false); } } void Update() { // 调用射线功能 _raycastComponent?.Raycast(); } } }