fix: 描边从单环改为交叉双环(横+竖),世界空间绘制避免视角失真

- 水平环(XZ平面) + 垂直环(XY平面) 交叉形成球形轮廓
- useWorldSpace=true 直接在世界空间画,避免子物体旋转导致的视角变形
- 半径0.15, 线宽0.06, 亮蓝色, 两个环同步闪烁
This commit is contained in:
yangbear
2026-06-30 02:48:13 +08:00
parent ea12c51677
commit 3d407dec63
2 changed files with 108 additions and 39 deletions
+55 -2
View File
@@ -1203,6 +1203,7 @@ GameObject:
- component: {fileID: 30774416}
- component: {fileID: 30774415}
- component: {fileID: 30774414}
- component: {fileID: 30774417}
m_Layer: 0
m_Name: point1
m_TagString: Untagged
@@ -1296,6 +1297,21 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 30774412}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &30774417
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 30774412}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa18d349de8cc4564984a4f44c712138, type: 3}
m_Name:
m_EditorClassIdentifier:
targetPosition: {fileID: 773787683}
womanObject: {fileID: 1096492308}
nextTouchObject: {fileID: 559340216}
--- !u!1 &37271315
GameObject:
m_ObjectHideFlags: 0
@@ -1503,6 +1519,11 @@ PrefabInstance:
propertyPath: m_Name
value: medicalBox
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 1b1ce20a2102247d99cac16ad09ceb1a,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
@@ -2027,13 +2048,14 @@ GameObject:
- component: {fileID: 198874071}
- component: {fileID: 198874070}
- component: {fileID: 198874069}
- component: {fileID: 198874072}
m_Layer: 0
m_Name: point3
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &198874068
Transform:
m_ObjectHideFlags: 0
@@ -2120,6 +2142,21 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 198874067}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &198874072
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 198874067}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa18d349de8cc4564984a4f44c712138, type: 3}
m_Name:
m_EditorClassIdentifier:
targetPosition: {fileID: 1109298010}
womanObject: {fileID: 1096492308}
nextTouchObject: {fileID: 0}
--- !u!1 &200058300
GameObject:
m_ObjectHideFlags: 0
@@ -3502,13 +3539,14 @@ GameObject:
- component: {fileID: 559340220}
- component: {fileID: 559340219}
- component: {fileID: 559340218}
- component: {fileID: 559340221}
m_Layer: 0
m_Name: point2
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &559340217
Transform:
m_ObjectHideFlags: 0
@@ -3595,6 +3633,21 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 559340216}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &559340221
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 559340216}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa18d349de8cc4564984a4f44c712138, type: 3}
m_Name:
m_EditorClassIdentifier:
targetPosition: {fileID: 958160146}
womanObject: {fileID: 1096492308}
nextTouchObject: {fileID: 198874067}
--- !u!1 &574962406
GameObject:
m_ObjectHideFlags: 0
@@ -2,7 +2,7 @@ using UnityEngine;
/// <summary>
/// 挂在 touchArray 的每个子球体上,点击时把 woman 移动到 womanPointArray 对应位置。
/// 自动关闭 MeshRenderer 只显示蓝描边,描边闪烁提示用户点击
/// 两个交叉圆环形成球形轮廓闪烁提示
/// </summary>
public class TouchPositionHandler : MonoBehaviour
{
@@ -10,52 +10,73 @@ public class TouchPositionHandler : MonoBehaviour
public GameObject womanObject;
public GameObject nextTouchObject;
private LineRenderer _outlineRenderer;
private LineRenderer _ringH; // 水平环
private LineRenderer _ringV; // 垂直环
private void Start()
{
// 关闭球体本身的 MeshRenderer,只留碰撞体 + 描边
var mr = GetComponent<MeshRenderer>();
if (mr != null) mr.enabled = false;
CreateBlueOutline();
StartCoroutine(BlinkOutline());
CreateCrossRings();
StartCoroutine(BlinkRings());
}
private void CreateBlueOutline()
private void CreateCrossRings()
{
var ringGo = new GameObject("BlueRing");
ringGo.transform.SetParent(transform, false);
ringGo.transform.localPosition = new Vector3(0, 0.02f, 0); // 稍微抬高防穿地
ringGo.transform.localRotation = Quaternion.Euler(90f, 0, 0);
_outlineRenderer = ringGo.AddComponent<LineRenderer>();
_outlineRenderer.useWorldSpace = false;
_outlineRenderer.loop = true;
_outlineRenderer.startWidth = 0.06f;
_outlineRenderer.endWidth = 0.06f;
_outlineRenderer.material = new Material(Shader.Find("Unlit/Color"));
_outlineRenderer.material.color = new Color(0.2f, 0.5f, 1f); // 亮蓝
_outlineRenderer.startColor = new Color(0.2f, 0.5f, 1f);
_outlineRenderer.endColor = new Color(0.2f, 0.5f, 1f);
float r = 0.15f;
int segs = 32;
_outlineRenderer.positionCount = segs;
float yOff = 0.05f;
Color blue = new Color(0.2f, 0.5f, 1f);
// 水平环 —— 世界空间 XZ 平面
var hGo = new GameObject("RingH");
hGo.transform.SetParent(transform, false);
_ringH = hGo.AddComponent<LineRenderer>();
SetupRing(_ringH, blue);
_ringH.useWorldSpace = true;
_ringH.positionCount = segs;
Vector3 center = transform.position + Vector3.up * yOff;
for (int i = 0; i < segs; i++)
{
float a = i * 2f * Mathf.PI / segs;
_outlineRenderer.SetPosition(i, new Vector3(Mathf.Cos(a) * r, Mathf.Sin(a) * r, 0));
_ringH.SetPosition(i, center + new Vector3(Mathf.Cos(a) * r, 0, Mathf.Sin(a) * r));
}
Debug.Log($"[TouchPosition] {name}: 蓝描边已创建 (r={r}, Unlit/Color)");
// 垂直环 —— 世界空间 XY 平面(竖起来)
var vGo = new GameObject("RingV");
vGo.transform.SetParent(transform, false);
_ringV = vGo.AddComponent<LineRenderer>();
SetupRing(_ringV, blue);
_ringV.useWorldSpace = true;
_ringV.positionCount = segs;
for (int i = 0; i < segs; i++)
{
float a = i * 2f * Mathf.PI / segs;
_ringV.SetPosition(i, center + new Vector3(Mathf.Cos(a) * r, Mathf.Sin(a) * r, 0));
}
Debug.Log($"[TouchPosition] {name}: 交叉蓝环已创建 (r={r})");
}
private System.Collections.IEnumerator BlinkOutline()
private void SetupRing(LineRenderer lr, Color c)
{
lr.loop = true;
lr.startWidth = 0.06f;
lr.endWidth = 0.06f;
lr.material = new Material(Shader.Find("Unlit/Color"));
lr.material.color = c;
lr.startColor = c;
lr.endColor = c;
}
private System.Collections.IEnumerator BlinkRings()
{
while (true)
{
if (_outlineRenderer != null)
_outlineRenderer.enabled = !_outlineRenderer.enabled;
bool on = !_ringH.enabled;
if (_ringH != null) _ringH.enabled = on;
if (_ringV != null) _ringV.enabled = on;
yield return new WaitForSeconds(0.4f);
}
}
@@ -68,27 +89,22 @@ public class TouchPositionHandler : MonoBehaviour
{
womanObject.transform.position = targetPosition.position;
womanObject.transform.rotation = targetPosition.rotation;
Debug.Log($"[TouchPosition] woman 移动到 {targetPosition.name} ({targetPosition.position})");
Debug.Log($"[TouchPosition] woman 移动到 {targetPosition.name}");
}
else
{
Debug.LogWarning($"[TouchPosition] {name}: womanObject 或 targetPosition 为空");
Debug.LogWarning($"[TouchPosition] {name}: 引用为空");
}
// 停止闪烁,隐藏描边
StopAllCoroutines();
if (_outlineRenderer != null)
_outlineRenderer.enabled = false;
if (_ringH != null) _ringH.enabled = false;
if (_ringV != null) _ringV.enabled = false;
gameObject.SetActive(false);
if (nextTouchObject != null)
{
nextTouchObject.SetActive(true);
Debug.Log($"[TouchPosition] {name} 已隐藏 -> {nextTouchObject.name} 显示");
}
else
{
Debug.Log($"[TouchPosition] {name} 已隐藏,无下一个");
Debug.Log($"[TouchPosition] {name} {nextTouchObject.name} 显示");
}
}
}