fix: ShoseClickHandler回归OnMouseDown+SphereCollider(3.0)最简方案
This commit is contained in:
@@ -7,17 +7,14 @@ public class ShoseClickHandler : MonoBehaviour
|
|||||||
private MeshRenderer _outlineMesh;
|
private MeshRenderer _outlineMesh;
|
||||||
private bool _clicked;
|
private bool _clicked;
|
||||||
|
|
||||||
void OnEnable()
|
void Start()
|
||||||
{
|
{
|
||||||
var col = GetComponent<Collider>();
|
var col = GetComponent<Collider>();
|
||||||
if (col == null) col = gameObject.AddComponent<SphereCollider>();
|
if (col == null) { col = gameObject.AddComponent<SphereCollider>(); ((SphereCollider)col).radius = 3f; }
|
||||||
col.enabled = true;
|
col.enabled = true;
|
||||||
if (col is SphereCollider sc) { sc.radius = 1.5f; sc.isTrigger = false; }
|
|
||||||
CreateOutlineMesh();
|
CreateOutlineMesh();
|
||||||
StopAllCoroutines();
|
|
||||||
StartCoroutine(BlinkOutline());
|
StartCoroutine(BlinkOutline());
|
||||||
_clicked = false;
|
Debug.Log($"[ShoseClick] Start obj={gameObject.name} col={col.enabled} radius={((SphereCollider)col).radius}");
|
||||||
Debug.Log($"[ShoseClick] OnEnable obj={gameObject.name} outline={_outlineMesh!=null} col enabled={col.enabled} radius={((SphereCollider)col).radius}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateOutlineMesh()
|
void CreateOutlineMesh()
|
||||||
@@ -46,38 +43,14 @@ public class ShoseClickHandler : MonoBehaviour
|
|||||||
while (true) { if (_outlineMesh != null) _outlineMesh.enabled = !_outlineMesh.enabled; yield return new WaitForSeconds(0.4f); }
|
while (true) { if (_outlineMesh != null) _outlineMesh.enabled = !_outlineMesh.enabled; yield return new WaitForSeconds(0.4f); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void OnMouseDown()
|
||||||
{
|
|
||||||
if (_clicked || !Input.GetMouseButtonDown(0)) return;
|
|
||||||
var cams = Object.FindObjectsOfType<Camera>();
|
|
||||||
foreach (var cam in cams)
|
|
||||||
{
|
|
||||||
if (!cam.enabled) continue;
|
|
||||||
var hits = Physics.RaycastAll(cam.ScreenPointToRay(Input.mousePosition), 200f);
|
|
||||||
if (hits.Length > 0)
|
|
||||||
{
|
|
||||||
var names = new System.Text.StringBuilder();
|
|
||||||
foreach (var h in hits) names.Append(h.collider?.gameObject?.name ?? "null").Append(", ");
|
|
||||||
Debug.Log($"[ShoseClick] ★ Update click! hits={hits.Length} — {names}");
|
|
||||||
}
|
|
||||||
foreach (var h in hits)
|
|
||||||
{
|
|
||||||
if (h.collider != null && (h.collider.gameObject == gameObject || h.collider.gameObject.name == gameObject.name))
|
|
||||||
{
|
|
||||||
OnClicked(); return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnClicked()
|
|
||||||
{
|
{
|
||||||
|
if (_clicked) return;
|
||||||
_clicked = true;
|
_clicked = true;
|
||||||
Debug.Log($"[ShoseClick] ★ {gameObject.name} 被点击了 ★");
|
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; Debug.Log($"[ShoseClick] 移动到 {targetPoint.name}"); }
|
if (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; }
|
||||||
else Debug.LogWarning("[ShoseClick] targetPoint 为空");
|
|
||||||
if (nextObject != null) nextObject.SetActive(true);
|
if (nextObject != null) nextObject.SetActive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.coplaydev.unity-mcp": "https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#main",
|
"com.coplaydev.unity-mcp": "https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#main",
|
||||||
|
"com.unity.cinemachine": "3.1.7",
|
||||||
|
"com.unity.cloud.gltfast": "6.14.1",
|
||||||
"com.unity.collab-proxy": "2.7.1",
|
"com.unity.collab-proxy": "2.7.1",
|
||||||
"com.unity.ide.rider": "3.0.36",
|
"com.unity.ide.rider": "3.0.36",
|
||||||
"com.unity.ide.visualstudio": "2.0.22",
|
"com.unity.ide.visualstudio": "2.0.22",
|
||||||
"com.unity.ide.vscode": "1.2.5",
|
"com.unity.ide.vscode": "1.2.5",
|
||||||
|
"com.unity.probuilder": "5.2.4",
|
||||||
"com.unity.render-pipelines.universal": "14.0.12",
|
"com.unity.render-pipelines.universal": "14.0.12",
|
||||||
"com.unity.test-framework": "1.1.33",
|
"com.unity.test-framework": "1.1.33",
|
||||||
"com.unity.textmeshpro": "3.0.7",
|
"com.unity.textmeshpro": "3.0.7",
|
||||||
"com.unity.timeline": "1.7.7",
|
"com.unity.timeline": "1.7.7",
|
||||||
"com.unity.ugui": "1.0.0",
|
"com.unity.ugui": "1.0.0",
|
||||||
|
"com.unity.visualeffectgraph": "14.0.12",
|
||||||
"com.unity.visualscripting": "1.9.4",
|
"com.unity.visualscripting": "1.9.4",
|
||||||
"com.unity.modules.ai": "1.0.0",
|
"com.unity.modules.ai": "1.0.0",
|
||||||
"com.unity.modules.androidjni": "1.0.0",
|
"com.unity.modules.androidjni": "1.0.0",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"hash": "11836003a5e2ffcb7715ecec7e1fbb9d9cdb5bb8"
|
"hash": "11836003a5e2ffcb7715ecec7e1fbb9d9cdb5bb8"
|
||||||
},
|
},
|
||||||
"com.unity.burst": {
|
"com.unity.burst": {
|
||||||
"version": "1.8.21",
|
"version": "1.8.24",
|
||||||
"depth": 1,
|
"depth": 1,
|
||||||
"source": "registry",
|
"source": "registry",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -27,6 +27,29 @@
|
|||||||
},
|
},
|
||||||
"url": "https://packages.unity.cn"
|
"url": "https://packages.unity.cn"
|
||||||
},
|
},
|
||||||
|
"com.unity.cinemachine": {
|
||||||
|
"version": "3.1.7",
|
||||||
|
"depth": 0,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {
|
||||||
|
"com.unity.splines": "2.0.0",
|
||||||
|
"com.unity.modules.imgui": "1.0.0"
|
||||||
|
},
|
||||||
|
"url": "https://packages.unity.cn"
|
||||||
|
},
|
||||||
|
"com.unity.cloud.gltfast": {
|
||||||
|
"version": "6.14.1",
|
||||||
|
"depth": 0,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {
|
||||||
|
"com.unity.burst": "1.8.24",
|
||||||
|
"com.unity.collections": "1.2.4",
|
||||||
|
"com.unity.mathematics": "1.2.6",
|
||||||
|
"com.unity.modules.jsonserialize": "1.0.0",
|
||||||
|
"com.unity.modules.unitywebrequest": "1.0.0"
|
||||||
|
},
|
||||||
|
"url": "https://packages.unity.cn"
|
||||||
|
},
|
||||||
"com.unity.collab-proxy": {
|
"com.unity.collab-proxy": {
|
||||||
"version": "2.7.1",
|
"version": "2.7.1",
|
||||||
"depth": 0,
|
"depth": 0,
|
||||||
@@ -34,6 +57,16 @@
|
|||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"url": "https://packages.unity.cn"
|
"url": "https://packages.unity.cn"
|
||||||
},
|
},
|
||||||
|
"com.unity.collections": {
|
||||||
|
"version": "1.2.4",
|
||||||
|
"depth": 1,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {
|
||||||
|
"com.unity.burst": "1.6.6",
|
||||||
|
"com.unity.test-framework": "1.1.31"
|
||||||
|
},
|
||||||
|
"url": "https://packages.unity.cn"
|
||||||
|
},
|
||||||
"com.unity.ext.nunit": {
|
"com.unity.ext.nunit": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"depth": 1,
|
"depth": 1,
|
||||||
@@ -80,6 +113,17 @@
|
|||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"url": "https://packages.unity.cn"
|
"url": "https://packages.unity.cn"
|
||||||
},
|
},
|
||||||
|
"com.unity.probuilder": {
|
||||||
|
"version": "5.2.4",
|
||||||
|
"depth": 0,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {
|
||||||
|
"com.unity.modules.imgui": "1.0.0",
|
||||||
|
"com.unity.modules.physics": "1.0.0",
|
||||||
|
"com.unity.settings-manager": "1.0.3"
|
||||||
|
},
|
||||||
|
"url": "https://packages.unity.cn"
|
||||||
|
},
|
||||||
"com.unity.render-pipelines.core": {
|
"com.unity.render-pipelines.core": {
|
||||||
"version": "14.0.12",
|
"version": "14.0.12",
|
||||||
"depth": 1,
|
"depth": 1,
|
||||||
@@ -118,6 +162,13 @@
|
|||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"url": "https://packages.unity.cn"
|
"url": "https://packages.unity.cn"
|
||||||
},
|
},
|
||||||
|
"com.unity.settings-manager": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"depth": 1,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {},
|
||||||
|
"url": "https://packages.unity.cn"
|
||||||
|
},
|
||||||
"com.unity.shadergraph": {
|
"com.unity.shadergraph": {
|
||||||
"version": "14.0.12",
|
"version": "14.0.12",
|
||||||
"depth": 1,
|
"depth": 1,
|
||||||
@@ -127,6 +178,17 @@
|
|||||||
"com.unity.searcher": "4.9.2"
|
"com.unity.searcher": "4.9.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"com.unity.splines": {
|
||||||
|
"version": "2.8.0",
|
||||||
|
"depth": 1,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {
|
||||||
|
"com.unity.mathematics": "1.2.1",
|
||||||
|
"com.unity.modules.imgui": "1.0.0",
|
||||||
|
"com.unity.settings-manager": "1.0.3"
|
||||||
|
},
|
||||||
|
"url": "https://packages.unity.cn"
|
||||||
|
},
|
||||||
"com.unity.test-framework": {
|
"com.unity.test-framework": {
|
||||||
"version": "1.1.33",
|
"version": "1.1.33",
|
||||||
"depth": 0,
|
"depth": 0,
|
||||||
@@ -168,6 +230,15 @@
|
|||||||
"com.unity.modules.imgui": "1.0.0"
|
"com.unity.modules.imgui": "1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"com.unity.visualeffectgraph": {
|
||||||
|
"version": "14.0.12",
|
||||||
|
"depth": 0,
|
||||||
|
"source": "builtin",
|
||||||
|
"dependencies": {
|
||||||
|
"com.unity.shadergraph": "14.0.12",
|
||||||
|
"com.unity.render-pipelines.core": "14.0.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"com.unity.visualscripting": {
|
"com.unity.visualscripting": {
|
||||||
"version": "1.9.4",
|
"version": "1.9.4",
|
||||||
"depth": 0,
|
"depth": 0,
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"m_Dictionary": {
|
||||||
|
"m_DictionaryValues": [
|
||||||
|
{
|
||||||
|
"type": "UnityEngine.ProBuilder.SemVer, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||||
|
"key": "about.identifier",
|
||||||
|
"value": "{\"m_Value\":{\"m_Major\":5,\"m_Minor\":2,\"m_Patch\":4,\"m_Build\":-1,\"m_Type\":\"\",\"m_Metadata\":\"\",\"m_Date\":\"\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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\":\"\"}}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user