Exemplo n.º 1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="curveItems"></param>
        public void Init(CurveScrollerItemData[] curveItems)
        {
            if (isInit)
            {
                return;
            }
            if (tweenPath.path.wpLengths.Length <= 1)
            {
                Debug.LogError("tween Path 没有点位信息");
                return;
            }

            isInit = true;
            //获取path总长度
            float pathLength = tweenPath.tween.PathLength();

            //获取每个点的长度 第一个点为0 排除
            float[] needwplengths = new float[tweenPath.path.wpLengths.Length - 1];
            for (int i = 0; i < tweenPath.path.wpLengths.Length; i++)
            {
                //第一个永远是0 不需要
                if (i == 0)
                {
                    continue;
                }
                needwplengths[i - 1] = tweenPath.path.wpLengths[i];
            }

            //添加数据
            //数据过少 就循环添加
            if (curveItems.Length < needwplengths.Length)
            {
                int arrayIndex = 0;
                //多添加一个
                for (int i = 0; i <= needwplengths.Length; i++)
                {
                    listData.Add(curveItems[arrayIndex]);
                    arrayIndex++;
                    if (arrayIndex > curveItems.Length - 1)
                    {
                        arrayIndex = 0;
                    }
                }
            }
            else
            {
                for (int i = 0; i < curveItems.Length; i++)
                {
                    listData.Add(curveItems[i]);
                }
            }

            //计算比例
            basePercentages = new float[needwplengths.Length];
            float tempPercentage = 0;

            for (int i = 0; i < needwplengths.Length; i++)
            {
                tempPercentage    += needwplengths[i] / pathLength;
                basePercentages[i] = tempPercentage;
            }

            for (int i = 0; i < basePercentages.Length; i++)
            {
                //克隆对象
                CurveScrollerItemView cutveItem = Instantiate(curveItemPrefab.gameObject).GetComponent <CurveScrollerItemView>();
                cutveItem.transform.transform.SetParent(this.transform);
                //cutveItem.transform.localScale = Vector3.one;

                CurveScrollerItemData curveItemData = listData.RemoveStart();
                curveItemData.Percentage = basePercentages[i];
                cutveItem.SetData(curveItemData);
                SetTransPosForTweenPerc(cutveItem.transform, basePercentages[i]);

                //添加到列表
                listTransPerc.Add(new TransPercentageStruct(cutveItem, curveItemData));
            }
            listTransPerc.Capacity = listTransPerc.Count;
        }
Exemplo n.º 2
0
 public void SetData(CurveScrollerItemData _curveItemData)
 {
     this.curveItemData = _curveItemData;
     curveItemView.SetData(_curveItemData);
 }