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; } }
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(); } }
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; } }
void HandleInput() { Event e = Event.current; if (e.type == EventType.MouseDown && e.button == 0) { for (int i = 0; i < keyRects.Length; i++) { if (keyRects[i].Contains(e.mousePosition)) { mouseIsDownOverKey = true; selectedKeyIndex = i; needRepaint = true; break; } } if (!mouseIsDownOverKey) { Color randomColor = new Color(Random.value, Random.value, Random.value); float keyTime = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, e.mousePosition.x); selectedKeyIndex = gradient.AddKey(randomColor, keyTime); mouseIsDownOverKey = true; needRepaint = true; } } if (e.type == EventType.MouseUp && e.button == 0) { mouseIsDownOverKey = false; } if (mouseIsDownOverKey && e.type == EventType.MouseDrag && e.button == 0) { float keyTime = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, e.mousePosition.x); selectedKeyIndex = gradient.UpdateKeyTime(selectedKeyIndex, keyTime); needRepaint = true; } if (e.type == EventType.KeyDown && e.keyCode == KeyCode.Backspace) { gradient.RemoveKey(selectedKeyIndex); if (selectedKeyIndex >= gradient.KeyCount) { selectedKeyIndex--; } needRepaint = true; } }
private void HandleGradientInput(ControlState state) { Event guiEvent = Event.current; Rect temp = gradientPreviewRect; temp.x = 0; temp.y = 0; 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; break; } } if (!mouseIsDownOverKey && temp.Contains(guiEvent.mousePosition) && guiEvent.clickCount == 2) { float keyTime = (guiEvent.mousePosition.x - state.translation.x) / state.scale.x; Color interpolatedColour = gradient.Evaluate(keyTime); selectedKeyIndex = gradient.AddKey(interpolatedColour, keyTime); mouseIsDownOverKey = true; } } if (guiEvent.type == EventType.MouseUp && guiEvent.button == 0) { mouseIsDownOverKey = false; } if (mouseIsDownOverKey && guiEvent.type == EventType.MouseDrag && guiEvent.button == 0) { float keyTime = (guiEvent.mousePosition.x - state.translation.x) / state.scale.x; for (int i = 0; i < gradient.NumKeys; i++) { if (keyTime.Equals(gradient.GetKey(i).Time)) { keyTime += 0.1f; } } selectedKeyIndex = gradient.UpdateKeyTime(selectedKeyIndex, keyTime); } if (guiEvent.keyCode == KeyCode.Delete && guiEvent.type == EventType.KeyDown) { for (int i = 0; i < keyRects.Length; i++) { if (keyRects[i].Contains(guiEvent.mousePosition)) { gradient.RemoveKey(selectedKeyIndex); if (selectedKeyIndex >= gradient.NumKeys) { selectedKeyIndex--; } break; } } } }