Exemple #1
0
 private bool EqualStop(LW_WidthStop other)
 {
     return(
         percentage == other.percentage &&
         width == other.width
         );
 }
Exemple #2
0
        internal float ScaleAtPercentage(float percentage)
        {
            float scale = 1;

            if (m_ScaleWithStroke)
            {
                if (m_Stroke != null)
                {
                    scale = m_Stroke.WidthAtPercentage(percentage);
                }
            }
            else if (m_VariableScales != null && m_VariableScales.Count > 0)
            {
                if (m_VariableScales.Count == 1)
                {
                    scale = m_VariableScales[0].width;
                }
                else
                {
                    int closestIndex = 0;
                    for (int i = 0; i < m_VariableScales.Count; i++)
                    {
                        if (m_VariableScales[i].percentage < percentage)
                        {
                            closestIndex = i;
                        }
                        else
                        {
                            break;
                        }
                    }
                    LW_WidthStop start = m_VariableScales[closestIndex];
                    LW_WidthStop end   = closestIndex < m_VariableScales.Count - 1 ? m_VariableScales[closestIndex + 1] : m_VariableScales[closestIndex];
                    if (start.percentage != end.percentage)
                    {
                        float t = (percentage - start.percentage) / (end.percentage - start.percentage);
                        scale = Mathf.Lerp(start.width, end.width, t);
                    }
                    else
                    {
                        scale = start.width;
                    }
                }
            }
            return(scale);
        }
Exemple #3
0
        protected override void OnValidate()
        {
            m_MiterLimit = Mathf.Max(m_MiterLimit, 1f);
            //if (m_VariableWidths == null) m_VariableWidths = new List<LW_WidthStop>(){new LW_WidthStop(1f, 0f)};
            if (m_VariableWidths != null && m_VariableWidths.Count > 0)
            {
                float min = 0;
                float max = 1;
                for (int i = 0; i < m_VariableWidths.Count; i++)
                {
                    max = i < m_VariableWidths.Count - 1 ? m_VariableWidths[i + 1].percentage : 1;
                    LW_WidthStop stop = m_VariableWidths[i];
                    stop.percentage     = Mathf.Clamp(stop.percentage, min, max);
                    m_VariableWidths[i] = stop;
                    min = stop.percentage;
                }

                /*
                 * m_VariableWidths.Sort(delegate(LW_WidthStop x, LW_WidthStop y){
                 *      if (x.percentage - y.percentage > 0) return 1;
                 *      else if (x.percentage - y.percentage < 0) return -1;
                 *      else return 0;
                 * });
                 */
                LW_WidthStop firstStop = m_VariableWidths[0];
                firstStop.percentage = 0;
                m_VariableWidths[0]  = firstStop;
                if (m_VariableWidths.Count > 1)
                {
                    LW_WidthStop lastStop = m_VariableWidths[m_VariableWidths.Count - 1];
                    lastStop.percentage = 1;
                    m_VariableWidths[m_VariableWidths.Count - 1] = lastStop;
                }
            }
            base.OnValidate();
        }
Exemple #4
0
        internal float WidthAtPercentage(float percentage)
        {
            float width = 0;

            if (m_VariableWidths != null && m_VariableWidths.Count > 0)
            {
                if (m_VariableWidths.Count == 1)
                {
                    width = m_VariableWidths[0].width;
                }
                else
                {
                    if (m_SpaceWidthsEvenly)
                    {
                        int          beforeIndex      = Mathf.FloorToInt(percentage * (m_VariableWidths.Count - 1));
                        int          afterIndex       = beforeIndex < m_VariableWidths.Count - 1 ? beforeIndex + 1 : beforeIndex;
                        LW_WidthStop beforeStop       = m_VariableWidths[beforeIndex];
                        LW_WidthStop afterStop        = m_VariableWidths[afterIndex];
                        float        beforePercentage = (float)beforeIndex / (float)(m_VariableWidths.Count - 1);
                        float        afterPercentage  = (float)afterIndex / (float)(m_VariableWidths.Count - 1);
                        if (beforePercentage != afterPercentage)
                        {
                            float t = (percentage - beforePercentage) / (afterPercentage - beforePercentage);
                            width = Mathf.Lerp(beforeStop.width, afterStop.width, t);
                        }
                        else
                        {
                            width = beforeStop.width;
                        }
                    }
                    else
                    {
                        int closestIndex = 0;
                        for (int i = 0; i < m_VariableWidths.Count; i++)
                        {
                            if (m_VariableWidths[i].percentage < percentage)
                            {
                                closestIndex = i;
                            }
                            else
                            {
                                break;
                            }
                        }
                        LW_WidthStop start = m_VariableWidths[closestIndex];
                        LW_WidthStop end   = closestIndex < m_VariableWidths.Count - 1 ? m_VariableWidths[closestIndex + 1] : m_VariableWidths[closestIndex];

                        if (start.percentage != end.percentage)
                        {
                            float t = (percentage - start.percentage) / (end.percentage - start.percentage);
                            width = Mathf.Lerp(start.width, end.width, t);
                        }
                        else
                        {
                            width = start.width;
                        }
                    }
                }
            }
            else
            {
                width = 1;
            }
            return(width * globalWidth);
        }