diff --git a/Assets/Scripts/Interaction/ShoseClickHandler.cs b/Assets/Scripts/Interaction/ShoseClickHandler.cs index 271ac8b..5613b5f 100644 --- a/Assets/Scripts/Interaction/ShoseClickHandler.cs +++ b/Assets/Scripts/Interaction/ShoseClickHandler.cs @@ -5,16 +5,39 @@ public class ShoseClickHandler : MonoBehaviour public GameObject nextObject; public Transform targetPoint; private MeshRenderer _outlineMesh; + private Bounds _meshBounds; private bool _clicked; void Start() { - var col = GetComponent(); - if (col == null) { col = gameObject.AddComponent(); ((SphereCollider)col).radius = 3f; } - col.enabled = true; + // 用模型的精确 Bounds 设 BoxCollider + var mf = GetComponent(); + if (mf == null) mf = GetComponentInChildren(); + if (mf != null && mf.sharedMesh != null) + { + _meshBounds = mf.sharedMesh.bounds; + var col = GetComponent(); + if (col == null) col = gameObject.AddComponent(); + // 移除旧 SphereCollider + var oldCol = GetComponent(); + if (oldCol != null) Destroy(oldCol); + col.center = _meshBounds.center; + col.size = _meshBounds.size * 1.2f; // 稍微扩大一点好点 + col.enabled = true; + Debug.Log($"[ShoseClick] BoxCollider center={col.center} size={col.size} bounds={_meshBounds}"); + } + else + { + // fallback + var col = gameObject.AddComponent(); + col.radius = 3f; + col.enabled = true; + Debug.LogWarning("[ShoseClick] 无MeshFilter,用SphereCollider fallback"); + } + CreateOutlineMesh(); StartCoroutine(BlinkOutline()); - Debug.Log($"[ShoseClick] Start obj={gameObject.name} col={col.enabled} radius={((SphereCollider)col).radius}"); + Debug.Log($"[ShoseClick] Start done. obj={gameObject.name} pos={transform.position} scale={transform.lossyScale}"); } void CreateOutlineMesh() @@ -45,12 +68,35 @@ public class ShoseClickHandler : MonoBehaviour void OnMouseDown() { + Debug.Log($"[ShoseClick] OnMouseDown fired! clicked={_clicked} mousePos={Input.mousePosition}"); if (_clicked) return; _clicked = true; Debug.Log("[ShoseClick] ★ 模型被点击了! ★"); StopAllCoroutines(); if (_outlineMesh != null) _outlineMesh.enabled = false; - if (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; } + if (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; Debug.Log($"[ShoseClick] 移动到 {targetPoint.name} pos={targetPoint.position}"); } if (nextObject != null) nextObject.SetActive(true); } + +#if UNITY_EDITOR + void OnDrawGizmos() + { + var col = GetComponent(); + if (col != null) + { + Gizmos.color = Color.green; + Gizmos.matrix = transform.localToWorldMatrix; + Gizmos.DrawWireCube(col.center, col.size); + } + else + { + var sc = GetComponent(); + if (sc != null) + { + Gizmos.color = Color.green; + Gizmos.DrawWireSphere(transform.position, sc.radius); + } + } + } +#endif } diff --git a/ProjectSettings/Packages/com.unity.probuilder/Settings.json b/ProjectSettings/Packages/com.unity.probuilder/Settings.json index 4eac871..59b16de 100644 --- a/ProjectSettings/Packages/com.unity.probuilder/Settings.json +++ b/ProjectSettings/Packages/com.unity.probuilder/Settings.json @@ -10,6 +10,26 @@ "type": "UnityEngine.ProBuilder.SemVer, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "key": "preferences.version", "value": "{\"m_Value\":{\"m_Major\":5,\"m_Minor\":2,\"m_Patch\":4,\"m_Build\":-1,\"m_Type\":\"\",\"m_Metadata\":\"\",\"m_Date\":\"\"}}" + }, + { + "type": "UnityEngine.ProBuilder.LogLevel, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", + "key": "log.level", + "value": "{\"m_Value\":3}" + }, + { + "type": "UnityEngine.ProBuilder.LogOutput, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", + "key": "log.output", + "value": "{\"m_Value\":1}" + }, + { + "type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", + "key": "log.path", + "value": "{\"m_Value\":\"ProBuilderLog.txt\"}" + }, + { + "type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", + "key": "lightmapping.autoUnwrapLightmapUV", + "value": "{\"m_Value\":true}" } ] }