コード例 #1
0
    void Start()
    {
        m_requestQueue = new List<PathComputer>();

        // TODO: Add a path cache in the event that a same start and end are requested multiple times in a row
        m_instance= this;
    }
コード例 #2
0
    void Start()
    {
        m_requestQueue = new List <PathComputer>();

        // TODO: Add a path cache in the event that a same start and end are requested multiple times in a row
        m_instance = this;
    }
コード例 #3
0
    public void Execute(OnRequestCompleteDelegate onComplete)
    {
        if (Status != eRequestStatus.pending_path_find || Status != eRequestStatus.pending_server_response)
        {
            Status = eRequestStatus.pending_path_find;
            m_onCompleteCallback = onComplete;

            PathfindingSystem.AddPathRequest(m_entity.CurrentRoomKey, m_entity.Position, TargetPosition, this.OnPathComputed);
        }
    }
コード例 #4
0
    // Конструктор системы поиска пути
    public PathfindingSystem(int width, int height, float cellSize, Vector3 position, bool debugMode)
    {
        InstancePath = this;
        DebugMode    = debugMode;
        grid         = new GridSystem <Node>(width, height, cellSize, position, (int x, int y) => new Node(x, y), DebugMode);


        debugTextArrayH = new List <TextMesh>();
        debugTextArrayG = new List <TextMesh>();
        debugTextArrayF = new List <TextMesh>();
    }
コード例 #5
0
ファイル: TestPath.cs プロジェクト: Raindery/NoNameProject
    // Start is called before the first frame update

    void Start()
    {
        system = new PathfindingSystem(10, 10, 2f, transform.position, true);



        enemyRb = enemy.GetComponent <Rigidbody2D>();


        startPosition = system.Grid.GetCellPosition(0, 0);
    }
コード例 #6
0
ファイル: BaseMover.cs プロジェクト: zamp/space-station-14
        protected void Setup(IEntity owner)
        {
            Owner       = owner;
            _mapManager = IoCManager.Resolve <IMapManager>();
            _pathfinder = IoCManager.Resolve <IEntitySystemManager>().GetEntitySystem <PathfindingSystem>();
            if (!Owner.TryGetComponent(out AiControllerComponent controllerComponent))
            {
                throw new InvalidOperationException();
            }

            _controller = controllerComponent;
        }
コード例 #7
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);
    }
コード例 #8
0
    public void Execute(OnRequestCompleteDelegate onComplete)
    {
        if (Status != eRequestStatus.pending_path_find || Status != eRequestStatus.pending_server_response)
        {
            m_onCompleteCallback = onComplete;

            if (Point3d.DistanceSquared(OriginalPosition, OriginPortalEntryPoint) > WITHIN_PORTAL_TOLERANCE_SQUARED)
            {
                Status = eRequestStatus.pending_path_find;

                PathfindingSystem.AddPathRequest(
                    m_entity.CurrentRoomKey,
                    m_entity.Position,
                    OriginPortalEntryPoint,
                    this.OnPathComputed);
            }
            else
            {
                Status = eRequestStatus.pending_server_response;
            }
        }
    }
コード例 #9
0
    private void DebugDrawNavMesh()
    {
        RoomKey roomKey = _gameWorldController.Model.CurrentGame.CurrentRoomKey;

        AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

        if (navMesh != null)
        {
            for (uint navCellIndex = 0; navCellIndex < navMesh.GetNavCellCount(); navCellIndex++)
            {
                int connectivityId = navMesh.GetNavCellConnectivityID(navCellIndex);

                if (connectivityId != AsyncRPGSharedLib.Navigation.NavMesh.EMPTY_NAV_CELL)
                {
                    for (MathConstants.eDirection direction = MathConstants.eDirection.first;
                         direction < MathConstants.eDirection.count;
                         direction++)
                    {
                        if (!navMesh.NavCellHasNeighbor(navCellIndex, direction))
                        {
                            Point3d portalLeft, portalRight;
                            Vector3 portalVertexLeft, portalVertexRight;

                            navMesh.ComputePointsOnNavCellSide(navCellIndex, direction, out portalLeft, out portalRight);
                            portalVertexLeft  = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalLeft);
                            portalVertexRight = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalRight);

                            Debug.DrawLine(
                                portalVertexLeft,
                                portalVertexRight,
                                Color.yellow,
                                0.0f,   // duration
                                false); // depth test
                        }
                    }
                }
            }
        }
    }
コード例 #10
0
    private void DebugDrawTestVisibility()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point3d startWorldPos = entity.Position;

            Point2d endPixelPos = GetMousePixelPosition();
            Point3d endWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(endPixelPos);

            // Draw the target nav cell
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef startNavRef = navMesh.ComputeNavRefAtPoint(startWorldPos);
                NavRef endNavRef   = navMesh.ComputeNavRefAtPoint(endWorldPos);

                if (startNavRef.IsValid && endNavRef.IsValid)
                {
                    bool  canSee     = navMesh.NavRefCanSeeOtherNavRef(startNavRef, endNavRef);
                    Color debugColor = canSee ? Color.green : Color.red;

                    // Draw a box around the nav cell
                    {
                        Point3d endCenterWorldPos = navMesh.ComputeNavCellCenter((uint)endNavRef.NavCellIndex);
                        Point2d endCenterPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(endCenterWorldPos);
                        float   halfWidth         = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                        Vector3 boxUL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxUR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxLR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);
                        Vector3 boxLL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);

                        Debug.DrawLine(boxUL, boxUR, debugColor);
                        Debug.DrawLine(boxUR, boxLR, debugColor);
                        Debug.DrawLine(boxLR, boxLL, debugColor);
                        Debug.DrawLine(boxLL, boxUL, debugColor);
                    }

                    // Update the visibility status label
                    _visibilityStatusLabel.Text = canSee ? "VISIBLE" : "INVISIBLE";
                    _visibilityStatusLabel.SetLocalPosition(endPixelPos.x, endPixelPos.y);
                    _visibilityStatusLabel.Color   = debugColor;
                    _visibilityStatusLabel.Visible = true;

                    // Render the ray-cast line
                    {
                        Vector3 startVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(startWorldPos);
                        Vector3 endVertex   = ClientGameConstants.ConvertRoomPositionToVertexPosition(endWorldPos);

                        Debug.DrawLine(startVertex, endVertex, debugColor);
                    }
                }
            }
        }
    }
コード例 #11
0
    private void DebugDrawTestPath()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point2d mousePixelPos = GetMousePixelPosition();
            Point3d mouseWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(mousePixelPos);

            // Draw the target nav cell
            string targetLabel = "";
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef navRef = navMesh.ComputeNavRefAtPoint(mouseWorldPos);

                if (navRef.IsValid)
                {
                    Point3d centerWorldPos = navMesh.ComputeNavCellCenter((uint)navRef.NavCellIndex);
                    Point2d centerPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(centerWorldPos);
                    float   halfWidth      = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                    Vector3 boxUL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxUR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxLR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y + halfWidth, 0.0f);
                    Vector3 boxLL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y + halfWidth, 0.0f);

                    Debug.DrawLine(boxUL, boxUR, Color.blue);
                    Debug.DrawLine(boxUR, boxLR, Color.blue);
                    Debug.DrawLine(boxLR, boxLL, Color.blue);
                    Debug.DrawLine(boxLL, boxUL, Color.blue);

                    targetLabel = "\nNavCell=" + navRef.NavCellIndex.ToString();
                }

                // Attempt to compute a path from the active player to the mouse
                _pathComputer.BlockingPathRequest(navMesh, roomKey, entity.Position, mouseWorldPos);

                // Update the path status label
                {
                    if (_pathComputer.ResultCode == PathComputer.eResult.success)
                    {
                        _pathStatusLabel.Text  = "VALID" + targetLabel;
                        _pathStatusLabel.Color = Color.green;
                    }
                    else
                    {
                        _pathStatusLabel.Text  = _pathComputer.ResultCode + targetLabel;
                        _pathStatusLabel.Color = Color.red;
                    }

                    _pathStatusLabel.SetLocalPosition(mousePixelPos.x, mousePixelPos.y);
                    _pathStatusLabel.Visible = true;
                }

                // Render the raw path
                for (int stepIndex = 1; stepIndex < _pathComputer.FinalPath.Count; stepIndex++)
                {
                    Point3d previousPoint      = _pathComputer.FinalPath[stepIndex - 1].StepPoint;
                    Point3d currentPoint       = _pathComputer.FinalPath[stepIndex].StepPoint;
                    Vector3 previousPixelPoint = ClientGameConstants.ConvertRoomPositionToVertexPosition(previousPoint);
                    Vector3 currentPixelPoint  = ClientGameConstants.ConvertRoomPositionToVertexPosition(currentPoint);

                    Debug.DrawLine(previousPixelPoint, currentPixelPoint, Color.green);
                }
            }
        }
    }
コード例 #12
0
 void Start()
 {
     PathfindingSystem system = new PathfindingSystem(width, height, cellSize, transform.position, debugMode);
 }
コード例 #13
0
 void OnDestroy()
 {
     m_instance= null;
 }
コード例 #14
0
 void OnDestroy()
 {
     m_instance = null;
 }