Beispiel #1
0
    /// <summary>
    /// 起始点 初始化
    /// </summary>
    /// <param name="_currentStep">_current step.</param>
    /// <param name="_cmpFun">_cmp fun.</param>
    public void M_startStep(int _currentStep, CallBack _cmpFun)
    {
        int segmentIndex = M_calculateSegmentIndex(_currentStep);

        if (segmentIndex > 0)
        {
            if (segmentIndex == 1)
            {
                currentLastStep = 0;
                startStep       = 1;
            }
            else
            {
                lastRotatioin   = roadSample.M_getSegmentRotation(segmentIndex - 2);
                currentLastStep = M_calculateSegmentTotalStep(segmentIndex - 2);
                startStep       = currentLastStep + 1;
            }
            EnumRoadSegment curType = EnumRoadSegmentKit.M_getType(roadSegmentType[segmentIndex - 1]);
            M_creatSegment(curType);
        }
        else
        {
            currentLastStep = 0;
            startStep       = 1;
        }
        M_goStep(_currentStep, _cmpFun);
    }
Beispiel #2
0
    /// <summary>
    /// 构建路线 直到路线能达到的最远步点满足当前步点数
    /// 如果没有达到 则递归调用
    /// </summary>
    /// <returns>The segment view.</returns>
    /// <param name="_currentStep">_current step.</param>
    private IEnumerator M_updateSegmentView(int _currentStep)
    {
        if (currentLastStep >= totalStep)
        {
            if (creatSegmentCmp != null)
            {
                creatSegmentCmp();
            }
            creatSegmentCmp = null;
            yield break;
        }

        if (creatRoadDynamic)
        {
            if (_currentStep + preMaxLoadStepCount <= currentLastStep)
            {
                if (creatSegmentCmp != null)
                {
                    creatSegmentCmp();
                }
                creatSegmentCmp = null;
                yield break;
            }
        }

        int             segmentIndex = M_calculateSegmentIndex(currentLastStep + 1);
        EnumRoadSegment curType      = EnumRoadSegmentKit.M_getType(roadSegmentType[segmentIndex]);

        M_creatSegment(curType);


        yield return(new WaitForSeconds(0.1f));

        if (creatRoadDynamic)
        {
            if (currentStep + preMaxLoadStepCount > currentLastStep)
            {
                _currentStep++;
                StartCoroutine("M_updateSegmentView", _currentStep);
            }
            else
            {
                if (creatSegmentCmp != null)
                {
                    creatSegmentCmp();
                }
                creatSegmentCmp = null;
            }
        }
        else
        {
            _currentStep++;
            StartCoroutine("M_updateSegmentView", _currentStep);
        }
    }
Beispiel #3
0
    /// <summary>
    /// 计算索引路段对应的总的到达的步点数
    /// </summary>
    /// <returns>The segment total step.</returns>
    /// <param name="_index">_index.</param>
    private int M_calculateSegmentTotalStep(int _index)
    {
        int stepCount = 0;
        MissionRoadSegment tempSegment;

        for (int i = 0; i <= _index; i++)
        {
            tempSegment = M_getRoadSegment(EnumRoadSegmentKit.M_getType(roadSegmentType[i]));
            stepCount  += tempSegment.totalSteps;
        }
        return(stepCount);
    }
Beispiel #4
0
    /// <summary>
    /// 计算步点数所对应的路段索引
    /// </summary>
    /// <returns>The segment index.</returns>
    /// <param name="_step">_step.</param>
    public int M_calculateSegmentIndex(int _step)
    {
        int index = 0;
        MissionRoadSegment tempSegment;

        for (int i = 0, tempStep = 0, length = roadSegmentType.Length; i < length; i++)
        {
            tempSegment = M_getRoadSegment(EnumRoadSegmentKit.M_getType(roadSegmentType[i]));
            tempStep   += tempSegment.totalSteps;
            if (tempStep >= _step)
            {
                index = i;
                break;
            }
        }
        return(index);
    }
    /// <summary>
    /// 根据一个路段模型 构建该路线的的:路径构建的顺序,
    /// </summary>
    /// <param name="_currentRoad">_current road.</param>
    public void M_creatRandom(MissionRoad _currentRoad)
    {
        segmentTypes = null;
        int             tempTotalStep = 0;
        List <string>   tempTyps      = new List <string>();
        EnumRoadSegment type;

        bool fristLineHasCreat = false;

        while (tempTotalStep <= pointCount)
        {
            if (tempTotalStep == 0)
            {
                type = EnumRoadSegment.Start;
            }
            else if (pointCount - tempTotalStep <= _currentRoad.segments_end.totalSteps)
            {
                type = EnumRoadSegment.End;
            }
            else
            {
                if (!fristLineHasCreat)
                {
                    type = EnumRoadSegment.Middle_Line;
                    fristLineHasCreat = true;
                }
                else
                {
                    type = EnumRoadSegmentKit.M_getRandomMiddleRandom();
                }
            }
            tempTotalStep += _currentRoad.M_getSegmentStepCount(type);
            tempTyps.Add(Enum.GetName(typeof(EnumRoadSegment), type));
        }
        segmentTypes = tempTyps.ToArray();
        tempTyps.Clear();
        tempTyps = null;
    }