Files
taptap2024_GJ_chidouren/Assets/Scripts/Game/Component/Map/MovePathGroup.cs

90 lines
2.6 KiB
C#
Raw Normal View History

2024-10-17 00:46:27 +08:00
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Game.Component.Map
{
public class MovePathGroup : MonoBehaviour
{
private List<Vector3> _pathList;
#if UNITY_EDITOR
public List<Transform> PathList;
private void OnDrawGizmos ()
{
if (PathList == null)
{
return;
}
//根据PathList绘制节点并按照顺序连接线段
for (int i = PathList.Count - 1; i >= 0 ; i--)
{
if (PathList[i] == null)
{
PathList.RemoveAt (i);
continue;
}
//每个节点绘制一个园
Gizmos.color = Color.red;
Gizmos.DrawWireSphere (PathList[i].position, 0.1f);
if (this.PathList.Count > 1)
{
if (i < PathList.Count - 1)
{
Gizmos.color = Color.green;
Gizmos.DrawLine (PathList[i].position, PathList[i + 1].position);
}
else
{
Gizmos.color = Color.green;
Gizmos.DrawLine (PathList[i].position, PathList[0].position);
}
}
}
UpdateNodeVector ();
}
[Button ("刷新路径")]
private void RefreshPath ()
{
this.PathList.Clear ();
for (int i = 0; i < transform.childCount; i++)
{
this.PathList.Add (transform.GetChild (i));
}
UpdateNodeVector ();
}
private void UpdateNodeVector ()
{
this._pathList = new List<Vector3>();
foreach (Transform t in PathList)
{
_pathList.Add (t.position);
}
}
[Button ("添加路径节点")]
private void AddPathNode ()
{
//创建一个空的游戏对象(编辑器中)
GameObject go = new GameObject ("PathNode");
UnityEditor.Selection.activeGameObject = go;
if (PathList != null && PathList.Count > 0)
{
go.transform.position = PathList[PathList.Count - 1].position + Vector3.up;
}
else
{
go.transform.position = transform.position;
}
go.transform.SetParent (this.transform);
PathList.Add (go.transform);
UpdateNodeVector ();
}
#endif
}
}