using TowerDefense.Agents; using TowerDefense.MeshCreator; using UnityEngine; namespace TowerDefense.Nodes { /// /// A point along the path which agents will navigate towards before recieving the next instruction from the NodeSelector /// Requires a collider to be added manually. /// Agent孵化和移动的节点,有相应的功能封装。 /// [RequireComponent(typeof(Collider))] public class Node : MonoBehaviour { /// /// 是否是对手方刷新点,根据这个值来判断刷新出来的Agent是哪一方 /// public bool bOpponentSide = false; /// /// Reference to the MeshObject created by an AreaMeshCreator /// [HideInInspector] public AreaMeshCreator areaMesh; /// /// Selection weight of the node /// public int weight = 1; /// /// Gets the next node from the selector /// /// Next node, or null if this is the terminating node public Node GetNextNode() { var selector = GetComponent(); if (selector != null) { return selector.GetNextNode(); } return null; } /// /// Gets a random point inside the area defined by a node's meshcreator /// /// A random point within the MeshObject's area public Vector3 GetRandomPointInNodeArea() { // Fallback to our position if we have no mesh return transform.position; // 返回随机位置信息. //return areaMesh == null ? transform.position : areaMesh.GetRandomPointInside(); } /// /// When agent enters the node area, get the next node /// public virtual void OnTriggerEnter(Collider other) { // var agent = other.gameObject.GetComponent(); // if (agent != null) // { // agent.MoveToNextNode(this); // } } #if UNITY_EDITOR /// /// Ensure the collider is a trigger /// protected void OnValidate() { var trigger = GetComponent(); if (trigger != null) { trigger.isTrigger = true; } // Try and find AreaMeshCreator if (areaMesh == null) { areaMesh = GetComponentInChildren(); } } void OnDrawGizmos() { Gizmos.DrawIcon(transform.position + Vector3.up, "movement_node.png", true); } #endif } }