Exemple #1
0
    private void HandleInput()
    {
        Event currentEvent = Event.current;

        if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
        {
            // check if we've clicked an existing key
            for (int i = 0; i < keyRects.Length; i++)
            {
                if (keyRects [i].Contains(currentEvent.mousePosition))
                {
                    selectedKeyIndex = i;
                    mouseDownOverKey = true;
                    break;
                }
            }
            // add a new key, if we're not clicking on an existing one
            if (!mouseDownOverKey && biomeRect.Contains(currentEvent.mousePosition))
            {
                float newHeight = Mathf.InverseLerp(biomeRect.yMax, biomeRect.y, currentEvent.mousePosition.y);
                Color newColour = biome.EvaluateToColour(newHeight);
                selectedKeyIndex = biome.AddRegion(newHeight, newColour);
                mouseDownOverKey = true;
                needsRepaint     = true;
            }
        }
        if (currentEvent.type == EventType.MouseUp && currentEvent.button == 0)
        {
            mouseDownOverKey = false;
        }
        if (mouseDownOverKey && currentEvent.type == EventType.MouseDrag && currentEvent.button == 0)
        {
            float newHeight = Mathf.InverseLerp(biomeRect.yMax, biomeRect.y, currentEvent.mousePosition.y);
            selectedKeyIndex = biome.SetRegionHeight(selectedKeyIndex, newHeight);
            needsRepaint     = true;
        }
        if (currentEvent.keyCode == KeyCode.Backspace && currentEvent.type == EventType.KeyDown)
        {
            biome.RemoveRegion(selectedKeyIndex);
            if (selectedKeyIndex >= biome.regions.Count)
            {
                selectedKeyIndex -= 1;
            }
            needsRepaint = true;
        }
    }