You've already forked taptap2024_GJ_chidouren
完成4种基础ai
This commit is contained in:
90
Assets/Scripts/Game/Component/Map/MovePathGroup.cs
Normal file
90
Assets/Scripts/Game/Component/Map/MovePathGroup.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user