private void Update() { if (path == null) { path = gameObject.GetComponent <ASPath>(); } }
private LocalTile[,] tileData; // A local copy of the mapGrid tiles, with added costs, heuristics etc. // Use this for initialization void Start() { path = gameObject.AddComponent <ASPath>(); // Create a path attached to this game object tileData = new LocalTile[mapGrid.tiles.GetLength(0), mapGrid.tiles.GetLength(1)]; // Allocate size of local tileData array for (int x = 0; x < mapGrid.tiles.GetLength(0); x++) // Loop through mapGrid tiles { for (int y = 0; y < mapGrid.tiles.GetLength(1); y++) { tileData[x, y] = new LocalTile(mapGrid.tiles[x, y]); // Create a new localTile tileData[x, y].pathNode = Instantiate(nodeType); // Spawn a PathNode prefab object to be associated with the tile tileData[x, y].pathNode.transform.parent = mapGrid.transform; // Assign this PathNode as a child of the MapGrid (To not clog up the heirarchy) tileData[x, y].pathNode.transform.position = tileData[x, y].tile.position; // Move this PathNode to the position of the tile } } }
private float waitTime = 0.0f; // How long the agent has been stopped for. private void Start() { if (path == null) { path = gameObject.GetComponent <ASPath>(); } // Return error and stop application from running if both loop and loopBackwards are true if (loop && loopBackwards) { Debug.LogError("Path follower error: loop and loopBackwards cannot both be true!"); UnityEditor.EditorApplication.isPlaying = false; } if (startAtClosest) // If the agent should start at the closest node as opposed to the first node. { currentNode = findClosestNode(); // Set the current node to the closest one } }
/// <summary> /// Draws each path node and the path between them when selected in Editor. /// </summary> private void OnSceneGUI() { ASPath path = (ASPath)target; // Path object in game float nodeSize = 0.5f; Handles.color = Color.white; // Set colour to green if (path.nodes.Count == 0) { return; } for (int i = 0; i < path.nodes.Count - 1; i++) // Loop through all nodes except last one { Handles.SphereHandleCap(i, path.nodes[i].transform.position, Quaternion.Euler(0.0f, 0.0f, 0.0f), nodeSize, EventType.Repaint); // Draw sphere Handles.DrawLine(path.nodes[i].transform.position, path.nodes[i + 1].transform.position); // Draw a line from this node to the next one } Handles.SphereHandleCap(path.nodes.Count, path.nodes[path.nodes.Count - 1].transform.position, Quaternion.Euler(0.0f, 0.0f, 0.0f), nodeSize, EventType.Repaint); // Draw sphere }