Example #1
0
    public RoadPathManager()
    {
        m_Sectors      = new List <Sector>();
        m_takenSectors = new List <int>();

        simpleRPF = new SimpleRoadPathFinding();

        _drawSectors = new Dictionary <string, Sector>();
    }
Example #2
0
    private void PullKing()
    {
        var kingPos = MapService.GetKingPosition();
        var kingX   = (int)kingPos.x;
        var kingZ   = (int)kingPos.z;

        if (KingPath == null)
        {
            var roadPathFinding = new RoadPathFinding();
            KingPath = new List <MovingStep>(roadPathFinding.FromTo(kingX, kingZ));
        }

        if (CurrentKingPath == null)
        {
            var step = KingPath.Where(s => s.X == kingX && s.Z == kingZ).FirstOrDefault();
            if (step == null)
            {
                CurrentKingPath = KingPath.FirstOrDefault();
            }
            else
            {
                CurrentKingPath = step;
            }
        }

        // still null nothing todo
        if (CurrentKingPath == null)
        {
            KingPath = null;
            return;
        }

        Progress += Time.deltaTime * PullKingSpeed;

        Vector3 start = new Vector3(kingX, kingPos.y, kingZ);
        Vector3 end   = new Vector3(CurrentKingPath.X, kingPos.y, CurrentKingPath.Z);

        MapService.SetKingPosition(Vector3.Lerp(start, end, Progress));

        if (Progress >= 1)
        {
            Progress = 0;

            if (PullKingPreviousZ.HasValue)
            {
                var pos = transform.localPosition;
                pos.y = PullKingPreviousZ.Value;
                transform.localPosition = pos;
                CurrentKingPath         = null;

                kingPos = MapService.GetKingPosition();
                kingX   = (int)kingPos.x;
                kingZ   = (int)kingPos.z;

                var kingStep = KingPath.Where(s => s.X == kingX && s.Z == kingZ).FirstOrDefault();
                if (kingStep != null)
                {
                    var kingStepIndex = KingPath.IndexOf(kingStep);
                    kingStepIndex++;
                    if (kingStepIndex < KingPath.Count)
                    {
                        CurrentMovingStep = KingPath[kingStepIndex];
                    }
                }
            }
        }
    }