Example #1
0
        void SpawnOneSection(RoadSectionData data, float coinRate = 0, bool isEnd = false)
        {
            RoadSection section = Instantiate <RoadSection>(sectionPrefab) as RoadSection;

            section.transform.SetParent(transform);

            section.SetData(data, currentEndPosition, currentOrientation);

            // 生成Block
            section.Execute(coinRate);

            currentEndPosition = section.lastSectionTruePosition;

            currentOrientation = section.exitToward;

            // TODO: 生成终点碰撞器
            Vector3 endpos = (maxLength - currentLength) * new Vector3(0, 0, 1);

            if (isEnd)
            {
                section.SpawnEnd(endpos.z);
            }

            //currentEndLocalRotation = section.localRotation * section.localYaw;


            currentLength += section.getLength();
        }
Example #2
0
        /// <summary>
        /// 单步生成
        /// </summary>
        public void SpawnNextSection()
        {
            if (finished)
            {
                return;
            }
            if (Mathf.Approximately(currentLength, 0))
            {
                SpawnOneSection(startData, 0);
                return;
            }

            if (currentLength < maxLength - 10)
            {
                sectionIndex = Random.Range(0, datas.Length);
                RoadSectionData data = datas[sectionIndex];
                SpawnOneSection(data, coinRate);
                return;
            }
            else
            {
                finished = true;
                SpawnOneSection(endData, 0, true);
            }
        }
Example #3
0
 /// <summary>
 /// 设定起始点和真实朝向
 /// </summary>
 public void SetData(RoadSectionData data, Vector3 position, Orientation toward)
 {
     this.data = data;
     transform.localPosition = position;
     this.orientation        = toward;
     transform.eulerAngles   = DirectionUtil.TowardToEuler(toward);
 }
Example #4
0
        /// <summary>
        /// 生成所有
        /// </summary>
        /// <param name="coinRate"></param>
        public void SpawnAllSections(float coinRate = 0)
        {
            SpawnOneSection(startData, 0);
            while (currentLength < maxLength - 20)
            {
                int             rndIndex = Random.Range(0, datas.Length);
                RoadSectionData data     = datas[rndIndex];
                SpawnOneSection(data, coinRate);
            }

            SpawnOneSection(endData, 0);
        }