diff --git a/Assets/Scripts/Tsq/ToolsCameraComponent.cs b/Assets/Scripts/Tsq/ToolsCameraComponent.cs index 9b50929..2cbd2d6 100644 --- a/Assets/Scripts/Tsq/ToolsCameraComponent.cs +++ b/Assets/Scripts/Tsq/ToolsCameraComponent.cs @@ -1,8 +1,9 @@ -using Framework.Scripts.Runtime.Engine.Engine.Camera.UIMoveTarget; -using Framework.Scripts.Runtime.Engine.Engine.Camera; + using TMPro; using UnityEngine; using UnityEngine.EventSystems; +using UnityEditor.UIElements; +using UnityEngine.UI; namespace DefaultNamespace { @@ -15,34 +16,32 @@ namespace DefaultNamespace public RectTransform ui; - private void Awake() + private void CheckToolModel() { - _raycastComponent = new CameraRaycastComponent(); - _uiFollow = new CameraFollowComponent(); - } - - void OnEnable() - { - _raycastComponent.OnRaycastHit += HandleRaycastHit; - } - - - // 处理射线命中事件并打印物体名称 - void HandleRaycastHit(RaycastHit hit) - { - if (!EventSystem.current.IsPointerOverGameObject()) + if (EventSystem.current.IsPointerOverGameObject()) { - if (hit.collider.CompareTag("Tools")) + return; + } + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + RaycastHit hit; + if (Physics.Raycast(ray, out hit, 2)) + { + bool raycast = Physics.Raycast(ray, out hit); + GameObject hitObject = hit.collider.gameObject; + //ToolBase tb = hit.transform.GetComponent(); + if (raycast) { - 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); + if (hitObject.CompareTag("Tools")) + { + ui.gameObject.SetActive(true); + ui.GetComponentInChildren().text = hit.collider.gameObject.name; + ui.transform.position = Input.mousePosition + new Vector3(10, 10, 0); + } + else + { + ui.gameObject.SetActive(false); + } } } else @@ -52,10 +51,13 @@ namespace DefaultNamespace } + + + void Update() { // 调用射线功能 - _raycastComponent?.Raycast(); + CheckToolModel(); } } }