Beispiel #1
0
        public void CreateCurve()
        {
            var count = 100;

            // Test border
            _down = 0f;
            _top  = 1f;
            for (var i = 0; i < count; i++)
            {
                var x = i * 1f / count;
                var y = EaseFunction.Ease(0f, 1f, x);
                if (y < _down)
                {
                    _down = y;
                }
                if (y > _top)
                {
                    _top = y;
                }
            }

            // Value Slider
            SliderValue.minValue = _down;
            SliderValue.maxValue = _top;

            var sliderHeight = SliderTrans.rect.size.y;
            var invalidTop   = sliderHeight * (_top - 1f) / (_top - _down);
            var invalidDown  = sliderHeight * -_down / (_top - _down);

            SliderInvalidTop.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, invalidTop);
            SliderInvalidDown.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, invalidDown);

            _xMin = -Width;
            _xMax = Width;
            _yMin = Mathf.Lerp(-Height, Height, -_down / (_top - _down));
            _yMax = Mathf.Lerp(-Height, Height, (1f - _down) / (_top - _down));

            // Coordinate
            LineCoordinateTop.positionCount = 2;
            LineCoordinateTop.SetPositions(new Vector3[2] {
                new Vector3(_xMin, _yMax, -0.5f), new Vector3(_xMax, _yMax, -0.5f)
            });
            LineCoordinateDown.positionCount = 2;
            LineCoordinateDown.SetPositions(new Vector3[2] {
                new Vector3(_xMin, _yMin, -0.5f), new Vector3(_xMax, _yMin, -0.5f)
            });

            // Draw curve
            var posList = new Vector3[count];

            for (var i = 0; i < count; i++)
            {
                var x = i * 1f / count;
                var y = EaseFunction.Ease(0f, 1f, x);

                x = x * (_xMax - _xMin) + _xMin;
                y = y * (_yMax - _yMin) + _yMin;

                var pos = new Vector3(x, y, -1);
                posList[i] = pos;
            }

            LineCurve.positionCount = count;
            LineCurve.SetPositions(posList);
        }