예제 #1
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)
            {
                Color randomColor       = new Color(Random.value, Random.value, Random.value);
                float keyTime           = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, guiEvent.mousePosition.x);
                Color interpolatedColor = gradient.Evaluate(keyTime);
                selectedKeyIndex   = gradient.AddColorKey(gradient.randomizeColor ? randomColor : interpolatedColor, 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.KeyCount)
            {
                selectedKeyIndex--;
            }
            needsRepaint = true;
        }
    }