コード例 #1
0
        public override void AddElement(ASceneElement element)
        {
            // 按屏幕坐标系方向组织顺序
            int index = elementCoordinates.AddSorted(GetOneDCoordinate(element.Position));

            elements.Insert(index, element);
        }
コード例 #2
0
        /// <summary>
        /// 回收一个场景元素实例到对象池。
        /// </summary>
        /// <param name="element">场景元素实例。</param>
        public static void Delete(ASceneElement element)
        {
            Type type = element.GetType();

            freeDic[type].Push(element);
            element.Reset();
        }
コード例 #3
0
        /// <summary>
        /// 获取 prefab 中 Sprite 在卷轴方向上的长度。
        /// </summary>
        /// <param name="element"></param>
        /// <returns>长度,单位 unit。</returns>
        private float GetElementSpriteLength(ASceneElement element)
        {
            float     prefabLen;
            Transform prefab = element.Prefab;

            if (!prefabLengthDic.TryGetValue(prefab, out prefabLen))
            {
                SpriteRenderer renderer = prefab.GetComponent <SpriteRenderer>();

                Assert.IsNotNull(renderer);
                Assert.IsNotNull(renderer.sprite);

                Vector3 spriteSize = renderer.sprite.bounds.size;

                prefabLen = ScrollAxis == ScrollAxis.Horizontal
                                ? spriteSize.x * prefab.localScale.x
                                : spriteSize.y * prefab.localScale.y;

                prefabLengthDic.Add(prefab, prefabLen);
            }

            float relativeScale = ScrollAxis == ScrollAxis.Horizontal
                                      ? element.RelativeScale.x
                                      : element.RelativeScale.y;

            return(prefabLen * relativeScale);
        }
コード例 #4
0
        protected override float JoinElement(ASceneElement element, float distance, bool isPositive)
        {
            float elementSpriteLen = GetElementSpriteLength(element);
            float sign             = isPositive ? 1 : -1;

            Vector3 elementPos;

            if (ScrollAxis == ScrollAxis.Horizontal)
            {
                elementPos =
                    new Vector3(LayerCamera.StartPosition.x + distance + sign * elementSpriteLen * 0.5f,
                                0,
                                0);
            }
            else
            {
                elementPos =
                    new Vector3(0,
                                LayerCamera.StartPosition.y + distance + sign * elementSpriteLen * 0.5f,
                                0);
            }

            element.SetPosition(elementPos);
            return(distance + sign * elementSpriteLen);
        }
コード例 #5
0
 public override void Modify(ASceneElement element)
 {
     if (Mathf.Approximately(minRelativeScale, maxRelativeScale))
     {
         element.SetRelativeScale(minRelativeScale * Vector3.one);
     }
     else
     {
         element.SetRelativeScale(Random.Range(minRelativeScale, maxRelativeScale) * Vector3.one);
     }
 }
コード例 #6
0
        /// <summary>
        /// 创建一个场景元素。
        /// </summary>
        /// <param name="isPositive">是否向正方向创建。</param>
        /// <param name="element">创建的场景元素。</param>
        /// <param name="filledDistance">当前填充的距离。</param>
        /// <returns>是否成功创建。</returns>
        private bool SpawnOneElement(bool isPositive, out ASceneElement element, ref float filledDistance)
        {
            element = GetProvider(filledDistance, isPositive).GetNext();

            if (element == null)
            {
                return(false);
            }

            Assert.IsNotNull(element.Prefab);
            filledDistance = JoinElement(element, filledDistance, isPositive);
            return(true);
        }
コード例 #7
0
        protected override float JoinElement(ASceneElement element, float distance, bool isPositive)
        {
            distance += GetNextInterval() * (isPositive ? 1 : -1);

            if (ScrollAxis == ScrollAxis.Horizontal)
            {
                element.SetPosition(new Vector3(LayerCamera.StartPosition.x + distance, 0, 0));
            }
            else
            {
                element.SetPosition(new Vector3(0, LayerCamera.StartPosition.x + distance, 0));
            }

            return(distance);
        }
コード例 #8
0
        public override void Modify(ASceneElement element)
        {
            Vector3 elementPos;

            if (scrollAxis == ScrollAxis.Horizontal)
            {
                elementPos =
                    new Vector3(element.Position.x, sidePosition, element.Position.z);
            }
            else
            {
                elementPos =
                    new Vector3(sidePosition, element.Position.y, element.Position.z);
            }

            element.SetPosition(elementPos);
        }
コード例 #9
0
 /// <summary>
 /// 将新场景元素添加到卷轴中。
 /// </summary>
 /// <param name="element">新场景元素。</param>
 /// <param name="distance">当前已填充的距离。</param>
 /// <param name="isPositive">是否正向填充。</param>
 abstract protected float JoinElement(ASceneElement element, float distance, bool isPositive);
コード例 #10
0
 /// <summary>
 /// 沿反方形生成下一个场景元素。
 /// </summary>
 /// <param name="element">场景元素。</param>
 /// <param name="filledDistance">填充距离。</param>
 /// <returns>是否成功生成场景元素。</returns>
 public bool SpawnOneNegativeElement(out ASceneElement element, ref float filledDistance)
 {
     return(SpawnOneElement(false, out element, ref filledDistance));
 }
コード例 #11
0
 /// <summary>
 /// 沿正方形生成下一个场景元素。
 /// </summary>
 /// <param name="element">场景元素。</param>
 /// <param name="filledDistance">填充距离。</param>
 /// <returns>是否成功生成场景元素。</returns>
 public bool SpawnOnePositiveElement(out ASceneElement element, ref float filledDistance)
 {
     return(SpawnOneElement(true, out element, ref filledDistance));
 }
コード例 #12
0
 /// <summary>
 /// 添加一个场景元素。
 /// </summary>
 /// <param name="element">场景元素。</param>
 abstract public void AddElement(ASceneElement element);
コード例 #13
0
 abstract public void Modify(ASceneElement element);