Example #1
0
        //------------------------------------------------------------------------------------------

        private void WriteTile(KD2DTile a_grazedTile, GameObject a_currenTileGameObject, float a_nextG)
        {
            a_grazedTile.Father = a_currenTileGameObject;
            a_grazedTile.G      = a_nextG;
            a_grazedTile.SetF();
            Reorder(a_grazedTile.gameObject, m_openList);
        }
Example #2
0
    //---------------------------------------------------------------------------------------------

    public override void OnTileEnter(KD2DTile a_tile)
    {
        if (m_isDynamic)
        {
            a_tile.Occupied = true;
        }
    }
Example #3
0
    //---------------------------------------------------------------------------------------------

    public override void OnTileExit(KD2DTile a_tile)
    {
        if (m_isDynamic)
        {
            a_tile.Occupied = false;
        }
    }
Example #4
0
    //---------------------------------------------------------------------------------------------

    public override void OnTileEnter(KD2DTile a_tile)
    {
        if (!OverlapedTiles.Contains(a_tile))
        {
            a_tile.Penalty += m_penaltyPercentage;
            OverlapedTiles.Add(a_tile);
        }
    }
Example #5
0
    //---------------------------------------------------------------------------------------------

    public override void OnTileEnter(KD2DTile a_tile)
    {
        if (!OverlapedTiles.Contains(a_tile))
        {
            a_tile.Penalty += m_penaltyPercentage;
            OverlapedTiles.Add(a_tile);
        }
    }
Example #6
0
        //------------------------------------------------------------------------------------------

        private static List <KD2DTile> FinalList(KD2DTile a_destination)
        {
            var list = new List <KD2DTile>();

            for (var c = a_destination; c.Father != null; c = c.Father.GetComponent <KD2DTile>())
            {
                list.Add(c);
            }

            return(list);
        }
Example #7
0
        //------------------------------------------------------------------------------------------

        private void WriteTile
        (
            KD2DTile a_tile,
            GameObject a_currenTileGameObject,
            float a_nextG,
            Vector2 a_end
        )
        {
            Vector3 nextTilePosition = a_tile.gameObject.transform.position;

            a_tile.Father   = a_currenTileGameObject;
            a_tile.G        = a_nextG;
            a_tile.H        = Math.Abs(a_end.x - nextTilePosition.x) + Math.Abs(a_end.y - nextTilePosition.y);
            a_tile.IsWrited = true;
            a_tile.SetF();
            Insert(a_tile.gameObject, m_openList);
        }
Example #8
0
    //---------------------------------------------------------------------------------------------

    /// <summary>
    /// Move over all p_tiles of the route and verify every step if the route has suffered some alterations
    /// </summary>
    /// <param name="a_tiles">full route for going from start to goal</param>
    /// <returns></returns>
    private IEnumerator Walk(List <KD2DTile> a_tiles)
    {
        if (a_tiles.Count > 0)
        {
            KD2DTile currentTile2DTile = a_tiles.Last();
            Vector2  currentStep       = currentTile2DTile.transform.position;
            bool     repathForObstacle;
            do
            {
#if UNITY_EDITOR
                var routePoints = a_tiles.Select
                                  (
                    a_tile => new Vector2(a_tile.transform.position.x, a_tile.transform.position.y)
                                  ).ToList();

                DrawRouteLines(routePoints, _color);
#endif
                transform.Translate
                (
                    new Vector2
                    (
                        currentStep.x - transform.position.x,
                        currentStep.y - transform.position.y
                    ).normalized *Time.deltaTime *Speed
                );

                yield return(null);

                repathForObstacle = a_tiles.Exists(a_tile => a_tile.Occupied);
            }while
            (
                Vector2.Distance(transform.position, currentStep) > m_speed * Time.deltaTime &&
                !repathForObstacle
            );

            if (repathForObstacle || RepathThisAgent || m_nav2D.RepathAfterTile)
            {
                Vector3 destiation = a_tiles.First().transform.position;
                NearestTile = currentTile2DTile;
                SetDestination(destiation);
            }
            else
            {
                a_tiles.Remove(currentTile2DTile);

                KDAgentStates state;
                StateMachine  stateCoroutine;

                if (a_tiles.Count == 0)
                {
                    stateCoroutine = Wait;
                    state          = KDAgentStates.Waiting;
                }
                else
                {
                    stateCoroutine = Turn;
                    state          = KDAgentStates.Turning;
                }
                NearestTile = currentTile2DTile;
                StartCurrentState(stateCoroutine, state, a_tiles);
            }
        }
        else
        {
            StartCurrentState(Wait, KDAgentStates.Waiting, a_tiles);
        }
    }
Example #9
0
    //---------------------------------------------------------------------------------------------

    public override void OnTileExit(KD2DTile a_tile)
    {
        a_tile.Penalty -= m_penaltyPercentage;
        OverlapedTiles.Remove(a_tile);
    }
Example #10
0
        //------------------------------------------------------------------------------------------

        private void BinaryDelete
        (
            IList <GameObject> a_openList,
            List <GameObject> a_closeList,
            out GameObject a_tile,
            out KD2DTile a_currentTile)
        {
            a_tile                 = a_openList.FirstOrDefault();
            a_currentTile          = a_tile.GetComponent <KD2DTile>();
            a_currentTile.IsBloked = true;
            a_closeList.Add(a_tile);

            a_openList.RemoveAt(0);
            if (a_openList.Count > 0)
            {
                a_openList.Insert(0, a_openList[a_openList.Count - 1]);
                a_openList.RemoveAt(a_openList.Count - 1);

                var i = 0;

                while (true)
                {
                    var j = i;

                    if (2 * j + 1 <= a_openList.Count - 1)
                    {
                        if
                        (
                            a_openList[j].GetComponent <KD2DTile>().F >=
                            a_openList[2 * j].GetComponent <KD2DTile>().F
                        )
                        {
                            i = 2 * j;
                        }

                        if
                        (
                            a_openList[i].GetComponent <KD2DTile>().F >=
                            a_openList[2 * j + 1].GetComponent <KD2DTile>().F
                        )
                        {
                            i = 2 * j + 1;
                        }
                    }
                    else if
                    (
                        2 * j <= a_openList.Count - 1 &&
                        a_openList[j].GetComponent <KD2DTile>().F >=
                        a_openList[2 * j].GetComponent <KD2DTile>().F
                    )
                    {
                        i = 2 * j;
                    }

                    if (i == j)
                    {
                        break;
                    }

                    var temp = a_openList[j];
                    a_openList[j] = a_openList[i];
                    a_openList[i] = temp;
                }
            }
        }
Example #11
0
    //----------------------------------------------------------------------------------------------

    public KD2DTile NearestNodeToPosition(Vector2 a_position)
    {
        KD2DTile nearestTile = m_pathFinder.NearestTile(a_position);

        return(nearestTile);
    }
Example #12
0
    //---------------------------------------------------------------------------------------------

    /// <summary>
    /// The interaction between the tiles inside of the navigation Area when the are enter on the p_tile
    /// </summary>
    /// <param name="a_tile"></param>
    public abstract void OnTileEnter(KD2DTile a_tile);
Example #13
0
    //---------------------------------------------------------------------------------------------

    /// <summary>
    /// The interaction between the tiles inside of the navigation Area when the area leaves the p_tile
    /// </summary>
    /// <param name="a_tile"></param>
    public abstract void OnTileExit(KD2DTile a_tile);
Example #14
0
    //---------------------------------------------------------------------------------------------

    public override void OnTileExit(KD2DTile a_tile)
    {
        a_tile.Penalty -= m_penaltyPercentage;
        OverlapedTiles.Remove(a_tile);
    }
Example #15
0
    //---------------------------------------------------------------------------------------------

    /// <summary>
    /// The interaction between the tiles inside of the navigation Area when the are enter on the p_tile
    /// </summary>
    /// <param name="a_tile"></param>
    public abstract void OnTileEnter(KD2DTile a_tile);
Example #16
0
    //---------------------------------------------------------------------------------------------

    public override void OnTileExit(KD2DTile a_tile)
    {
        if (m_isDynamic)
            a_tile.Occupied = false;
    }
Example #17
0
    //---------------------------------------------------------------------------------------------

    public override void OnTileEnter(KD2DTile a_tile)
    {
        if (m_isDynamic)
            a_tile.Occupied = true;
    }
Example #18
0
    //---------------------------------------------------------------------------------------------

    /// <summary>
    /// The interaction between the tiles inside of the navigation Area when the area leaves the p_tile
    /// </summary>
    /// <param name="a_tile"></param>
    public abstract void OnTileExit(KD2DTile a_tile);