Beispiel #1
0
    // Events
    private void OnPathCompleted(PathComputer pathResult)
    {
        m_state = ePathFindingState.completed;

        if (m_pathCompleteCallback != null)
        {
            m_pathCompleteCallback(pathResult);
            m_pathCompleteCallback = null;
        }
    }
Beispiel #2
0
    // 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);
    }
    // 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;
    }