public PathfindingComponent(IEntity entity) { m_entity = entity; m_destinationPoint = new Point3d(entity.Position); m_destinationFacing = new Vector2d(entity.Facing); m_pathCompleteCallback = null; ClearPath(); }
// Events private void OnPathCompleted(PathComputer pathResult) { m_state = ePathFindingState.completed; if (m_pathCompleteCallback != null) { m_pathCompleteCallback(pathResult); m_pathCompleteCallback = null; } }
// Requests public bool SubmitPathRequest( Point3d point, Vector2d facing, PathComputer.OnPathComputerComplete pathCompletedCallback) { bool success = false; m_pathSteps = new List <PathStep>(); m_pathStepIndex = 0; m_pathCompleteCallback = pathCompletedCallback; m_destinationPoint.Set(point); m_destinationFacing.Copy(facing); if (Point3d.DistanceSquared(m_destinationPoint, m_entity.Position) > MathConstants.EPSILON_SQUARED) { success = PathfindingSystem.AddPathRequest( m_entity.CurrentRoomKey, m_entity.Position, m_destinationPoint, (PathComputer pathResult) => { if (pathResult.ResultCode == PathComputer.eResult.success) { m_state = ePathFindingState.in_progress; m_pathSteps = pathResult.FinalPath; } else { OnPathCompleted(pathResult); } }); } else { OnPathCompleted(null); success = true; } return(success); }
public static bool AddPathRequest( RoomKey roomKey, Point3d startPoint, Point3d endPoint, PathComputer.OnPathComputerComplete onComplete) { bool success = false; if (m_instance != null) { PathComputer pathComputer = new PathComputer(); AsyncRPGSharedLib.Navigation.NavMesh navMesh = GetNavMesh(roomKey); if (pathComputer.NonBlockingPathRequest(navMesh, roomKey, startPoint, endPoint, onComplete)) { m_instance.m_requestQueue.Add(pathComputer); success = true; } } return(success); }
// Requests public bool SubmitPathRequest( Point3d point, Vector2d facing, PathComputer.OnPathComputerComplete pathCompletedCallback) { bool success = false; m_pathSteps = new List<PathStep>(); m_pathStepIndex = 0; m_pathCompleteCallback = pathCompletedCallback; m_destinationPoint.Set(point); m_destinationFacing.Copy(facing); if (Point3d.DistanceSquared(m_destinationPoint, m_entity.Position) > MathConstants.EPSILON_SQUARED) { success = PathfindingSystem.AddPathRequest( m_entity.CurrentRoomKey, m_entity.Position, m_destinationPoint, (PathComputer pathResult) => { if (pathResult.ResultCode == PathComputer.eResult.success) { m_state = ePathFindingState.in_progress; m_pathSteps = pathResult.FinalPath; } else { OnPathCompleted(pathResult); } }); } else { OnPathCompleted(null); success = true; } return success; }