Exemplo n.º 1
0
    private Texture2D GetTexture(ControlState state, Rect curveArea)
    {
        int       width   = (int)curveArea.width;
        Texture2D texture = new Texture2D(width, 1);

        Color[] colours = new Color[width];
        for (int i = 0; i < width; i++)
        {
            float t = (i - state.translation.x) / scale.x;
            colours[i] = gradient.Evaluate(t);
        }
        texture.SetPixels(colours);
        texture.Apply();
        return(texture);
    }
Exemplo n.º 2
0
    void DecreaseBar()
    {
        timeLeftSeconds -= refreshUpdateSeconds;

        if (timeLeftSeconds <= 0)
        {
            CancelInvoke(nameof(DecreaseBar));
            TimeExpired?.Invoke();
        }

        timeBar.fillAmount = timeLeftSeconds / totalTimeSeconds;
        timeBar.color      = gradient.Evaluate(timeBar.fillAmount);
    }
Exemplo n.º 3
0
    void HandleInput()
    {
        Event guiEvent = Event.current;

        if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
        {
            for (int i = 0; i < keyRects.Length; i++)
            {
                if (keyRects[i].Contains(guiEvent.mousePosition))
                {
                    mouseIsDownOverKey = true;
                    selectedKeyIndex   = i;
                    needsRepaint       = true;
                    break;
                }
            }

            if (!mouseIsDownOverKey)
            {
                float keyTime            = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, guiEvent.mousePosition.x);
                Color interpolatedColour = gradient.Evaluate(keyTime);
                Color randomColour       = new Color(Random.value, Random.value, Random.value);

                selectedKeyIndex   = gradient.AddKey((gradient.randomizeColour)?randomColour:interpolatedColour, keyTime);
                mouseIsDownOverKey = true;
                needsRepaint       = true;
            }
        }

        if (guiEvent.type == EventType.MouseUp && guiEvent.button == 0)
        {
            mouseIsDownOverKey = false;
        }

        if (mouseIsDownOverKey && guiEvent.type == EventType.MouseDrag && guiEvent.button == 0)
        {
            float keyTime = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, guiEvent.mousePosition.x);
            selectedKeyIndex = gradient.UpdateKeyTime(selectedKeyIndex, keyTime);
            needsRepaint     = true;
        }

        if (guiEvent.keyCode == KeyCode.Backspace && guiEvent.type == EventType.KeyDown)
        {
            gradient.RemoveKey(selectedKeyIndex);
            if (selectedKeyIndex >= gradient.NumKeys)
            {
                selectedKeyIndex--;
            }
            needsRepaint = true;
        }
    }
Exemplo n.º 4
0
    override protected void HandleInput()
    {
        Event guiEvent = Event.current;

        if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
        {
            for (int i = 0; i < keyRects.Length; i++)
            {
                if (keyRects[i].Contains(guiEvent.mousePosition))
                {
                    mouseDownOverKey = true;
                    selectedKeyIndex = i;
                    NeedsRepaint();
                }
            }

            if (gradientPreviewRect.Contains(guiEvent.mousePosition))
            {
                Color colour  = gradient.Evaluate(Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, guiEvent.mousePosition.x));
                float keyTime = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, guiEvent.mousePosition.x);
                selectedKeyIndex = gradient.AddKey(colour, keyTime);
                MarkSceneDirty();
                NeedsRepaint();
            }
        }

        if (guiEvent.type == EventType.MouseUp && guiEvent.button == 0)
        {
            mouseDownOverKey = false;
        }

        if (guiEvent.type == EventType.MouseDrag && guiEvent.button == 0 && mouseDownOverKey)
        {
            float keyTime = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, guiEvent.mousePosition.x);
            selectedKeyIndex = gradient.UpdateKeyTime(selectedKeyIndex, keyTime);
            MarkSceneDirty();
            NeedsRepaint();
        }

        if (guiEvent.type == EventType.KeyDown && (guiEvent.keyCode == KeyCode.Backspace || guiEvent.keyCode == KeyCode.Delete))
        {
            gradient.RemoveKey(selectedKeyIndex);
            if (selectedKeyIndex >= gradient.KeyCount())
            {
                selectedKeyIndex--;
            }
            MarkSceneDirty();
            NeedsRepaint();
        }
    }
Exemplo n.º 5
0
    private void HandleInput()
    {
        Event guiEvent = Event.current;

        if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
        {
            for (int i = 0; i < _keyRects.Length; i++)
            {
                if (_keyRects[i].Contains(guiEvent.mousePosition))
                {
                    // Hovering i-th keyRect
                    _selectedKeyIndex   = i;
                    _mouseIsDownOverKey = true;
                    _needsRepaint       = true;
                    break;
                }
            }

            if (!_mouseIsDownOverKey)
            {
                var   keyTime           = Mathf.InverseLerp(_gradientPreviewRect.x, _gradientPreviewRect.xMax, guiEvent.mousePosition.x);
                Color randomColor       = new Color(Random.value, Random.value, Random.value);
                Color interpolatedColor = _gradient.Evaluate(keyTime);
                _selectedKeyIndex   = _gradient.AddKey(_gradient.randomizeColor ? randomColor : interpolatedColor, keyTime);
                _mouseIsDownOverKey = true;
            }
        }

        if (guiEvent.type == EventType.MouseUp && guiEvent.button == 0)
        {
            _mouseIsDownOverKey = false;
        }

        if (_mouseIsDownOverKey && guiEvent.type == EventType.MouseDrag && guiEvent.button == 0)
        {
            var keyTime = Mathf.InverseLerp(_gradientPreviewRect.x, _gradientPreviewRect.xMax, guiEvent.mousePosition.x);
            _selectedKeyIndex = _gradient.UpdateKeyTime(_selectedKeyIndex, keyTime);
            _needsRepaint     = true;
        }

        if (guiEvent.keyCode == KeyCode.Backspace && guiEvent.type == EventType.KeyDown)
        {
            _gradient.RemoveKey(_selectedKeyIndex);
            if (_selectedKeyIndex >= _gradient.NumKeys)
            {
                _selectedKeyIndex--;
            }
            _needsRepaint = true;
        }
    }