fix: Shose BoxCollider精确匹配mesh+OnDrawGizmos可视化+全量日志
This commit is contained in:
@@ -5,16 +5,39 @@ public class ShoseClickHandler : MonoBehaviour
|
|||||||
public GameObject nextObject;
|
public GameObject nextObject;
|
||||||
public Transform targetPoint;
|
public Transform targetPoint;
|
||||||
private MeshRenderer _outlineMesh;
|
private MeshRenderer _outlineMesh;
|
||||||
|
private Bounds _meshBounds;
|
||||||
private bool _clicked;
|
private bool _clicked;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
var col = GetComponent<Collider>();
|
// 用模型的精确 Bounds 设 BoxCollider
|
||||||
if (col == null) { col = gameObject.AddComponent<SphereCollider>(); ((SphereCollider)col).radius = 3f; }
|
var mf = GetComponent<MeshFilter>();
|
||||||
col.enabled = true;
|
if (mf == null) mf = GetComponentInChildren<MeshFilter>();
|
||||||
|
if (mf != null && mf.sharedMesh != null)
|
||||||
|
{
|
||||||
|
_meshBounds = mf.sharedMesh.bounds;
|
||||||
|
var col = GetComponent<BoxCollider>();
|
||||||
|
if (col == null) col = gameObject.AddComponent<BoxCollider>();
|
||||||
|
// 移除旧 SphereCollider
|
||||||
|
var oldCol = GetComponent<SphereCollider>();
|
||||||
|
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<SphereCollider>();
|
||||||
|
col.radius = 3f;
|
||||||
|
col.enabled = true;
|
||||||
|
Debug.LogWarning("[ShoseClick] 无MeshFilter,用SphereCollider fallback");
|
||||||
|
}
|
||||||
|
|
||||||
CreateOutlineMesh();
|
CreateOutlineMesh();
|
||||||
StartCoroutine(BlinkOutline());
|
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()
|
void CreateOutlineMesh()
|
||||||
@@ -45,12 +68,35 @@ public class ShoseClickHandler : MonoBehaviour
|
|||||||
|
|
||||||
void OnMouseDown()
|
void OnMouseDown()
|
||||||
{
|
{
|
||||||
|
Debug.Log($"[ShoseClick] OnMouseDown fired! clicked={_clicked} mousePos={Input.mousePosition}");
|
||||||
if (_clicked) return;
|
if (_clicked) return;
|
||||||
_clicked = true;
|
_clicked = true;
|
||||||
Debug.Log("[ShoseClick] ★ 模型被点击了! ★");
|
Debug.Log("[ShoseClick] ★ 模型被点击了! ★");
|
||||||
StopAllCoroutines();
|
StopAllCoroutines();
|
||||||
if (_outlineMesh != null) _outlineMesh.enabled = false;
|
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 (nextObject != null) nextObject.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
void OnDrawGizmos()
|
||||||
|
{
|
||||||
|
var col = GetComponent<BoxCollider>();
|
||||||
|
if (col != null)
|
||||||
|
{
|
||||||
|
Gizmos.color = Color.green;
|
||||||
|
Gizmos.matrix = transform.localToWorldMatrix;
|
||||||
|
Gizmos.DrawWireCube(col.center, col.size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var sc = GetComponent<SphereCollider>();
|
||||||
|
if (sc != null)
|
||||||
|
{
|
||||||
|
Gizmos.color = Color.green;
|
||||||
|
Gizmos.DrawWireSphere(transform.position, sc.radius);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,26 @@
|
|||||||
"type": "UnityEngine.ProBuilder.SemVer, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
"type": "UnityEngine.ProBuilder.SemVer, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||||
"key": "preferences.version",
|
"key": "preferences.version",
|
||||||
"value": "{\"m_Value\":{\"m_Major\":5,\"m_Minor\":2,\"m_Patch\":4,\"m_Build\":-1,\"m_Type\":\"\",\"m_Metadata\":\"\",\"m_Date\":\"\"}}"
|
"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}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user