/// <summary> /// Sets up the entire scene's pathfinding system. /// </summary> /// <remarks> /// This is a crappy o(n^2) solution, so it can take a while. /// </remarks> private void SetupPathfindingSystem() { // Clear all preexisting relationships in the node setup. PathfindingService pathfindingService = PathfindingService.GetSingleton() as PathfindingService; pathfindingService.CalculateNodeGraphAdjacencies(); }
public MovementHandler( MessageHub messageHub, CollisionHandler collisionHandler, PathfindingService pathfindingService) { _messageHub = messageHub; _pathfinding = pathfindingService; _collisionHandler = collisionHandler; }
/// <summary> /// Populates each node with its adjacency data. Takes a short while to calculate. /// </summary> /// <remarks> /// Crap-tier code. /// </remarks> public void CalculateNodeGraphAdjacencies() { // Get pathfinding service & all gameobjects with a Node component. GameObject[] allObjects = GameObject.FindObjectsOfType <GameObject>(); List <Node> allNodes = new List <Node>(); foreach (GameObject go in allObjects) { Node node = go.GetComponent <Node>(); if (go.activeInHierarchy && node != null) { allNodes.Add(node); } } // Clear all preexisting relationships in the node setup. PathfindingService pathfindingService = PathfindingService.GetSingleton() as PathfindingService; pathfindingService.graph.Clear(); foreach (Node node in allNodes) { node.neighborNodes.Clear(); } // For each node, cast a ray to see if the nodes are visible. If they are, link them together. foreach (Node node in allNodes) { // Add the node to the graph. pathfindingService.graph.Add(node); foreach (Node otherNode in allNodes) { // Skip if identical node or already linked. if (node == otherNode || node.neighborNodes.ContainsKey(otherNode)) { continue; } Vector3 vectorToOtherNode = (otherNode.transform.position - node.transform.position); RaycastHit2D hit = Physics2D.Raycast(node.transform.position, vectorToOtherNode.normalized); if (hit.transform == null) { node.neighborNodes.Add(otherNode, vectorToOtherNode.magnitude); } } } Debug.Log("Recalculation done."); }
/// <summary> /// OnSceneGUI is called when the scene's GUI updates. /// </summary> private void OnSceneGUI() { // Draw all node links if (shouldDrawNodeLinks) { PathfindingService pathfindingService = PathfindingService.GetSingleton() as PathfindingService; foreach (Node node in pathfindingService.graph) { // Draw node outlines Debug.DrawLine(node.transform.position + new Vector3(.5f, .5f), node.transform.position + new Vector3(-.5f, .5f)); Debug.DrawLine(node.transform.position + new Vector3(-.5f, .5f), node.transform.position + new Vector3(-.5f, -.5f)); Debug.DrawLine(node.transform.position + new Vector3(-.5f, -.5f), node.transform.position + new Vector3(.5f, -.5f)); Debug.DrawLine(node.transform.position + new Vector3(.5f, -.5f), node.transform.position + new Vector3(.5f, .5f)); // Draw links foreach (KeyValuePair <Node, float> otherNode in node.neighborNodes) { Debug.DrawLine(node.transform.position, otherNode.Key.transform.position, Color.green, Time.deltaTime); } } } }
protected void RemoveScene(SceneInterface s) { ScriptThreadPool.Shutdown(); m_ParcelAccessManager.Stop(); Environment.OnEnvironmentControllerChangeParams -= StoreEnvironmentControllerData; Environment.Stop(); PathfindingService?.Stop(); int serializedcount = 0; foreach (ObjectPart part in Primitives) { foreach (ObjectPartInventoryItem item in part.Inventory.Values) { IScriptState state = item.ScriptState; if (state != null) { try { m_SimulationDataStorage.ScriptStates[ID, part.ID, item.ID] = state.ToDbSerializedState(); if (++serializedcount % 50 == 0) { m_Log.InfoFormat("Serialized {0} script states", serializedcount); } } catch (Exception e) { m_Log.ErrorFormat("Script state serialization failed for {0} ({1}): prim {2} ({3}): item {4} ({5}): {6}: {7}\n{8}", Name, ID, part.Name, part.ID, item.Name, item.ID, e.GetType().FullName, e.Message, e.StackTrace); } } } } if (serializedcount == 1) { m_Log.InfoFormat("Serialized {0} script state", serializedcount); } else if (serializedcount % 50 != 0) { m_Log.InfoFormat("Serialized {0} script states", serializedcount); } m_RestartObject = null; if (m_NeighborService != null) { RegionInfo rInfo = s.GetRegionInfo(); rInfo.Flags &= ~RegionFlags.RegionOnline; m_NeighborService.NotifyNeighborStatus(rInfo); } if (m_SceneListener != null) { m_SceneListener.StopStorageThread(); SceneListeners.Remove(m_SceneListener); } if (m_TerrainListener != null) { m_TerrainListener.StopStorageThread(); Terrain.TerrainListeners.Remove(m_TerrainListener); } if (m_IMRouter != null) { m_IMRouter.SceneIM.Remove(IMSend); } UDPCircuitsManager udpServer = m_UDPServer; udpServer?.Shutdown(); m_UDPServer = null; }
public PathfindingController() { _pathfindingService = new PathfindingService(); }
/// <summary> /// Start is called at initialization /// </summary> void Start() { service = PathfindingService.GetSingleton() as PathfindingService; }