fix: Shose collider强制设1.2+干掉DraggableObject+大字号点击日志

This commit is contained in:
yangbear
2026-07-05 21:29:26 +08:00
parent 4f008e14a9
commit 8aa9fa3086
+14 -16
View File
@@ -1,28 +1,25 @@
using UnityEngine;
/// <summary>
/// Shose 交互:模型可见 + 外圈蓝色描边闪烁,点击后移动到 ShosePoint
/// </summary>
public class ShoseClickHandler : MonoBehaviour
{
public GameObject nextObject;
public Transform targetPoint;
private MeshRenderer _outlineMesh;
void OnEnable()
{
// 不隐藏模型!只加描边子对象
if (GetComponent<Collider>() == null)
{
var sc = gameObject.AddComponent<SphereCollider>();
sc.radius = 1.0f;
sc.isTrigger = false;
}
// 强制确保有足够大的 collider
var col = GetComponent<Collider>();
if (col == null) col = gameObject.AddComponent<SphereCollider>();
if (col is SphereCollider sc) { sc.radius = 1.2f; sc.isTrigger = false; }
// 干掉可能拦截点击的旧组件
var drag = GetComponent<DraggableObject>();
if (drag != null) Destroy(drag);
CreateOutlineMesh();
StopAllCoroutines();
StartCoroutine(BlinkOutline());
Debug.Log($"[ShoseClick] OnEnable outline={_outlineMesh!=null} collider={GetComponent<Collider>()!=null}");
Debug.Log($"[ShoseClick] OnEnable outline={_outlineMesh!=null} col radius={(col is SphereCollider sc2?sc2.radius:-1)}");
}
void CreateOutlineMesh()
@@ -30,9 +27,9 @@ public class ShoseClickHandler : MonoBehaviour
if (_outlineMesh != null) return;
var mf = GetComponent<MeshFilter>();
if (mf == null) mf = GetComponentInChildren<MeshFilter>();
if (mf == null || mf.sharedMesh == null) { Debug.LogWarning("[ShoseClick] 无Mesh"); return; }
if (mf == null || mf.sharedMesh == null) return;
var shader = Shader.Find("Custom/OutlineUnlit");
if (shader == null) { Debug.LogWarning("[ShoseClick] Shader缺失"); return; }
if (shader == null) return;
var mat = new Material(shader);
mat.SetColor("_OutlineColor", new Color(0.2f, 0.5f, 1f, 1f));
mat.SetColor("_MainColor", new Color(0, 0, 0, 0));
@@ -57,10 +54,11 @@ public class ShoseClickHandler : MonoBehaviour
void OnMouseDown()
{
Debug.Log("[ShoseClick] 被点击");
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}"); }
else Debug.LogWarning("[ShoseClick] targetPoint 为空!");
if (nextObject != null) nextObject.SetActive(true);
}
}