2026-06-30 02:19:13 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 挂在 touchArray 的每个子球体上,点击时把 woman 移动到 womanPointArray 对应位置。
|
2026-06-30 02:32:27 +08:00
|
|
|
/// 自动关闭 MeshRenderer 只显示蓝描边,描边闪烁提示用户点击。
|
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:32:27 +08:00
|
|
|
private LineRenderer _outlineRenderer;
|
|
|
|
|
|
2026-06-30 02:24:54 +08:00
|
|
|
private void Start()
|
|
|
|
|
{
|
2026-06-30 02:32:27 +08:00
|
|
|
// 关闭球体本身的 MeshRenderer,只留碰撞体 + 描边
|
|
|
|
|
var mr = GetComponent<MeshRenderer>();
|
|
|
|
|
if (mr != null) mr.enabled = false;
|
|
|
|
|
|
2026-06-30 02:24:54 +08:00
|
|
|
CreateBlueOutline();
|
2026-06-30 02:32:27 +08:00
|
|
|
StartCoroutine(BlinkOutline());
|
2026-06-30 02:24:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateBlueOutline()
|
|
|
|
|
{
|
|
|
|
|
var ringGo = new GameObject("BlueRing");
|
|
|
|
|
ringGo.transform.SetParent(transform, false);
|
2026-06-30 02:32:27 +08:00
|
|
|
ringGo.transform.localPosition = new Vector3(0, 0.02f, 0); // 稍微抬高防穿地
|
|
|
|
|
ringGo.transform.localRotation = Quaternion.Euler(90f, 0, 0);
|
2026-06-30 02:24:54 +08:00
|
|
|
|
2026-06-30 02:32:27 +08:00
|
|
|
_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);
|
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:32:27 +08:00
|
|
|
_outlineRenderer.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:32:27 +08:00
|
|
|
_outlineRenderer.SetPosition(i, new Vector3(Mathf.Cos(a) * r, Mathf.Sin(a) * r, 0));
|
|
|
|
|
}
|
|
|
|
|
Debug.Log($"[TouchPosition] {name}: 蓝描边已创建 (r={r}, Unlit/Color)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private System.Collections.IEnumerator BlinkOutline()
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (_outlineRenderer != null)
|
|
|
|
|
_outlineRenderer.enabled = !_outlineRenderer.enabled;
|
|
|
|
|
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;
|
|
|
|
|
Debug.Log($"[TouchPosition] woman 移动到 {targetPosition.name} ({targetPosition.position})");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning($"[TouchPosition] {name}: womanObject 或 targetPosition 为空");
|
|
|
|
|
}
|
2026-06-30 02:24:54 +08:00
|
|
|
|
2026-06-30 02:32:27 +08:00
|
|
|
// 停止闪烁,隐藏描边
|
|
|
|
|
StopAllCoroutines();
|
|
|
|
|
if (_outlineRenderer != null)
|
|
|
|
|
_outlineRenderer.enabled = false;
|
|
|
|
|
|
2026-06-30 02:24:54 +08:00
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
if (nextTouchObject != null)
|
|
|
|
|
{
|
|
|
|
|
nextTouchObject.SetActive(true);
|
|
|
|
|
Debug.Log($"[TouchPosition] {name} 已隐藏 -> {nextTouchObject.name} 已显示");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"[TouchPosition] {name} 已隐藏,无下一个");
|
|
|
|
|
}
|
2026-06-30 02:19:13 +08:00
|
|
|
}
|
|
|
|
|
}
|