int OpenSnapApp(bool success) { if (success) { var snapApp = GameObject.Instantiate(Resources.Load("Prefabs/SnapApp") as GameObject); snapApp.transform.position = new Vector3( transform.position.x + 1.0f, transform.position.y + 0.4f, -5.0f); cameraController.PanToLocation(transform.position); cameraController.SetOrthographicSize(5.0f); ioController.DisableClicking(); ioController.DisableScrolling(); } return(0); }
// Given a destination, finds a path to that node and starts the hero on it. // callback is for if another objects calls this in order to send the hero somewhere and needs to do something // once the hero gets there. public void StartPath(NodeGrid destination, Func <bool, int> callback = null) { Vector2 nodeToEmpty; if (pathfinding) { var reverseNodes = nodes; reverseNodes.Reverse(); nodeToEmpty = new Vector2(reverseNodes[0].x, reverseNodes[0].y); if (destinationIndicator) { GameObject.Destroy(destinationIndicator); } foreach (var indicator in pathIndicators) { GameObject.Destroy(indicator); } pathIndicators.Clear(); } else { nodeToEmpty = new Vector2(transform.position.x, transform.position.y); } currentCallback = callback; NodeGrid heroNode = grid.FindClosestNode(transform.position.x, transform.position.y); grid.EmptyOutNode(nodeToEmpty.x, nodeToEmpty.y); nodes = grid.FindPath(new Location(heroNode.loc.x, heroNode.loc.y), new Location(destination.loc.x, destination.loc.y)); if (nodes.Count > 1) { animator.Play("Walking"); pathfinding = true; nodeIndex = 0; destinationIndicator = GameObject.Instantiate(Resources.Load("Prefabs/DestinationIndicator") as GameObject); destinationIndicator.transform.position = new Vector3(destination.loc.x, destination.loc.y, 20.0f); foreach (Location location in nodes) { if (location == destination.loc) { break; } var indicator = GameObject.Instantiate(Resources.Load("Prefabs/PathIndicator") as GameObject); indicator.transform.position = new Vector3(location.x, location.y, 18.0f); pathIndicators.Enqueue(indicator); } // For now, choose the end node for which direction to face // Eventually, would be better to find next horizontal node that // forces a change in direction FaceTheRightWay(nodes[nodes.Count - 1].x); } else // Assuming already at destination { if (null != currentCallback) { currentCallback(true); } } grid.FillUpNode(destination.loc.x, destination.loc.y, this.gameObject); mainCam.PanToLocation(new Vector2(destination.loc.x, destination.loc.y)); }