Ejemplo n.º 1
0
 /// <summary>
 /// 刷新参考线
 /// </summary>
 void UpdateReferenceLine()
 {
     if (ReferenceValue.Length != ReferenceLine.Count)
     {
         ClearList(ReferenceLine);
         for (int i = 0; i < ReferenceValue.Length; i++)
         {
             RectTransform go = Instantiate(DataImage_Prefab, DataImageParent);
             go.name = "参考线 " + ReferenceValue[i].ToString();
             ReferenceLine.Add(go);
         }
     }
     if (DataImageParent.gameObject.activeInHierarchy)
     {
         for (int i = 0; i < ReferenceValue.Length; i++)
         {
             float value = ValueAdjust.ToPercent01(ReferenceValue[i], DataRange.x, DataRange.y) * DataImageParent.sizeDelta.y;
             ReferenceLine[i].offsetMax = new Vector2(DataImageParent.sizeDelta.x, value + 1);
             ReferenceLine[i].offsetMin = new Vector2(0, value - 1);
             Color newColor = new HSVColor(360f * i / ReferenceValue.Length, 1, 1, 1).ToColor();
             if (ReferenceLine[i].GetComponent <Image>())
             {
                 ReferenceLine[i].GetComponent <Image>().color = newColor;
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 刷新数据绘制
 /// </summary>
 private void OnDraw()
 {
     if (DataImageParent.gameObject.activeInHierarchy)
     {
         for (int i = 0; i < DataImages.Count; i++)
         {
             if (RecordData.Count - DataImages.Count + i <= 0)
             {
                 //DataImages[i].sizeDelta = new Vector2(DataImage_Prefab.sizeDelta.x, 0);
                 DataImages[i].localScale = new Vector3(1, 0, 1);
             }
             else
             {
                 float data = RecordData[RecordData.Count - DataImages.Count + i];
                 //DataImages[i].sizeDelta = new Vector2(DataImage_Prefab.sizeDelta.x, RecordData[RecordData.Count - DataImages.Count + i] * 3);
                 DataImages[i].localScale = new Vector3(1, ValueAdjust.ToPercent01(data, DataRange.x, DataRange.y, 1, false), 1);
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据序号获取路径上的宽度
        /// </summary>
        /// <param name="pos">序号</param>
        /// <returns>速度</returns>
        public float EvaluateWidth(float pos)
        {
            float result = 0;

            if (m_Waypoints.Length > 0)
            {
                UpdateControlPoints();
                pos = GetBoundingIndices(pos, out int indexA, out int indexB);
                if (indexA == indexB)
                {
                    result = m_Waypoints[indexA].width;
                }
                else
                {
                    result = Mathf.Lerp(m_Waypoints[indexA].width, m_Waypoints[indexB].width, ValueAdjust.ToPercent01(pos, indexA, indexB));
                }
                //result = SplineHelpers.Bezier1(pos - indexA,
                //    m_Waypoints[indexA].width, m_ControlPoints1[indexA].width,
                //    m_ControlPoints2[indexA].width, m_Waypoints[indexB].width);
            }
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据序号获取路径上的速度,忽略<0
        /// </summary>
        /// <param name="pos">序号</param>
        /// <param name="indexA">前点</param>
        /// <param name="indexB">后点</param>
        /// <returns>速度</returns>
        public float EvaluateSpeed(float pos, out int indexA, out int indexB)
        {
            float result = 0;

            pos = StandardizePos(pos);
            int numWaypoints = m_Waypoints.Length;

            if (numWaypoints < 2)
            {
                indexA = indexB = 0;
            }
            else if (IsAllSpeedNull())
            {
                indexA = indexB = 0;
                return(0);
            }
            else
            {
                indexA = Mathf.FloorToInt(pos);
                if (indexA >= numWaypoints)
                {
                    // Only true if looped
                    pos   -= MaxPos;
                    indexA = 0;
                }
                while (m_Waypoints[indexA].speed < 0)
                {
                    indexA--;
                    if (indexA < 0)
                    {
                        if (Looped)
                        {
                            indexA = numWaypoints - 1;
                        }
                        else
                        {
                            indexA = 0;
                            break;
                        }
                    }
                }
                indexB = indexA + 1;
                if (indexB == numWaypoints)
                {
                    if (Looped)
                    {
                        indexB = 0;
                    }
                    else
                    {
                        --indexB;
                        --indexA;
                    }
                }
                while (m_Waypoints[indexB].speed < 0)
                {
                    indexB++;
                    if (indexB >= numWaypoints)
                    {
                        if (Looped)
                        {
                            indexB -= numWaypoints;
                        }
                        else
                        {
                            indexB = numWaypoints - 1;
                            break;
                        }
                    }
                }
            }
            if (m_Waypoints[indexA].speed < 0 || m_Waypoints[indexB].speed < 0)
            {
                result = 0;
            }
            else
            {
                result = Mathf.Lerp(m_Waypoints[indexA].speed, m_Waypoints[indexB].speed, indexA > indexB ? ValueAdjust.ToPercent01(pos, indexA, indexB + numWaypoints) : ValueAdjust.ToPercent01(pos, indexA, indexB));
            }
            return(result);
        }