Files
VFSUnity/Assets/Scripts/Interaction/TouchPositionHandler.cs
T
yangbear 3d407dec63 fix: 描边从单环改为交叉双环(横+竖),世界空间绘制避免视角失真
- 水平环(XZ平面) + 垂直环(XY平面) 交叉形成球形轮廓
- useWorldSpace=true 直接在世界空间画,避免子物体旋转导致的视角变形
- 半径0.15, 线宽0.06, 亮蓝色, 两个环同步闪烁
2026-06-30 02:48:13 +08:00

111 lines
3.4 KiB
C#

using UnityEngine;
/// <summary>
/// 挂在 touchArray 的每个子球体上,点击时把 woman 移动到 womanPointArray 对应位置。
/// 两个交叉圆环形成球形轮廓闪烁提示。
/// </summary>
public class TouchPositionHandler : MonoBehaviour
{
public Transform targetPosition;
public GameObject womanObject;
public GameObject nextTouchObject;
private LineRenderer _ringH; // 水平环
private LineRenderer _ringV; // 垂直环
private void Start()
{
var mr = GetComponent<MeshRenderer>();
if (mr != null) mr.enabled = false;
CreateCrossRings();
StartCoroutine(BlinkRings());
}
private void CreateCrossRings()
{
float r = 0.15f;
int segs = 32;
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;
_ringH.SetPosition(i, center + new Vector3(Mathf.Cos(a) * r, 0, Mathf.Sin(a) * r));
}
// 垂直环 —— 世界空间 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 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)
{
bool on = !_ringH.enabled;
if (_ringH != null) _ringH.enabled = on;
if (_ringV != null) _ringV.enabled = on;
yield return new WaitForSeconds(0.4f);
}
}
private void OnMouseDown()
{
Debug.Log($"[TouchPosition] {name}: 被点击");
if (womanObject != null && targetPosition != null)
{
womanObject.transform.position = targetPosition.position;
womanObject.transform.rotation = targetPosition.rotation;
Debug.Log($"[TouchPosition] woman 移动到 {targetPosition.name}");
}
else
{
Debug.LogWarning($"[TouchPosition] {name}: 引用为空");
}
StopAllCoroutines();
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} 显示");
}
}
}