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