static public void Init() { GameObject obj = new GameObject(); nodeGenerator = obj.AddComponent <NodeGeneratorTD>(); thisT = obj.transform; obj.name = "NodeGenerator"; }
public void GenerateNode(float heightOffset) { nodeGraph = NodeGeneratorTD.GenerateNode(this, heightOffset); graphGenerated = true; }
static public List <NodeTD> GetNodeInFootprint(NodeTD origin, int footprint) { if (footprint <= 0) { return(new List <NodeTD>()); } bool connectDNeighbour = NodeGeneratorTD.ConnectDiagonalNeighbour(); List <NodeTD> currentList = new List <NodeTD>(); List <NodeTD> openList = new List <NodeTD>(); List <NodeTD> closeList = new List <NodeTD>(); if (connectDNeighbour) { closeList.Add(origin); foreach (NodeTD node in origin.neighbourNode) { currentList.Add(node); } for (int i = 0; i < footprint; i++) { openList = currentList; currentList = new List <NodeTD>(); foreach (NodeTD node in openList) { foreach (NodeTD neighbour in node.neighbourNode) { if (!openList.Contains(neighbour) && !closeList.Contains(neighbour)) { currentList.Add(neighbour); } } closeList.Add(node); } } } else { closeList.Add(origin); foreach (NodeTD node in origin.neighbourNode) { currentList.Add(node); } //~ float range=1.5f*(footprint)*BuildManager.GetGridSize(); float range = 1 * (footprint) * BuildManager.GetGridSize() + BuildManager.GetGridSize() * 0.25f; for (int i = 0; i < footprint * 2; i++) { openList = currentList; currentList = new List <NodeTD>(); foreach (NodeTD node in openList) { foreach (NodeTD neighbour in node.neighbourNode) { //~ if(Vector3.Distance(origin.pos, neighbour.pos)<range){ if (Mathf.Abs(origin.pos.x - neighbour.pos.x) <= range && Mathf.Abs(origin.pos.z - neighbour.pos.z) <= range) { if (!openList.Contains(neighbour) && !closeList.Contains(neighbour)) { currentList.Add(neighbour); } } } closeList.Add(node); } } } return(closeList); }
//~ static Transform refT; void Awake() { nodeGenerator = this; thisT = transform; }