Пример #1
0
 static void OnDrag(SliderEvent slider, UserAction action, Vector2 v)
 {
     if (slider.direction == Direction.Horizontal)
     {
         float w = slider.endPos.x - slider.startPos.x;
         float s = w * slider.GlobalScale.x;
         slider.m_value += v.x / s;
     }
     else
     {
         float h = slider.startPos.y - slider.endPos.y;
         float s = h * slider.GlobalScale.y;
         slider.m_value += v.y / s;
     }
 }
Пример #2
0
        static void ValueChanged(SliderEvent slider)
        {
            float o = slider.Value;

            if (slider.Number)
            {
                int   v = slider.maxNum - slider.minNum;
                float a = slider.minNum + slider.m_value * v;
                slider.Value = (int)a;
            }
            else
            {
                if (slider.m_value < 0)
                {
                    slider.m_value = 0;
                }
                else
                if (slider.m_value > 1)
                {
                    slider.m_value = 1;
                }
                slider.Value = slider.m_value;
            }
            if (slider.Nob != null)
            {
                if (slider.direction == Direction.Horizontal)
                {
                    slider.Nob.localPosition = (slider.endPos - slider.startPos) * slider.Value + slider.startPos + slider.NobOffset;
                }
                else
                {
                    slider.Nob.localPosition = (slider.startPos - slider.endPos) * slider.Value + slider.endPos + slider.NobOffset;
                }
                slider.Nob.sizeDelta = (slider.endSize - slider.startSize) * slider.Value + slider.startSize;
            }
            if (slider.SliderImage != null)
            {
                slider.SliderImage.fillAmount = slider.Value;
            }
        }
Пример #3
0
        static void OnClick(EventCallBack back, UserAction action)
        {
            SliderEvent slider = back as SliderEvent;

            if (slider.direction == Direction.Horizontal)
            {
                float x  = slider.GlobalPosition.x;
                float ox = action.CanPosition.x - x;
                float w  = back.Target.sizeDelta.x;
                float s  = w * slider.GlobalScale.x;
                slider.m_value = ox / s + 0.5f;
            }
            else
            {
                float y  = slider.GlobalPosition.y;
                float oy = action.CanPosition.y - y;
                float w  = back.Target.sizeDelta.y;
                float s  = w * slider.GlobalScale.y;
                slider.m_value = oy / s + 0.5f;
            }
            ValueChanged(slider);
        }