// Update is called once per frame void Update() { rate += speed * Time.deltaTime; var c = g1.Evaluate(rate); GetComponent <MeshRenderer>().sharedMaterial.color = c; }
private void HandleMouse(Event guiEvent) { if (guiEvent.button != 0) { return; } if (guiEvent.type == EventType.MouseDown) { for (int i = 0; i < keyRects.Length; i++) { var rect = keyRects[i]; rect.position += new Vector2(-2, -2); rect.size += new Vector2(4, 4); if (rect.Contains(guiEvent.mousePosition)) { selectedKeyIndex = i; mouseIsDownOverKey = true; needsRepaint = true; break; } } if (keyInteractiveRect.Contains(guiEvent.mousePosition) && !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) { if (mouseIsDownOverKey && gradientPreviewRect.Contains(guiEvent.mousePosition)) { selectedKeyIndex = DeleteKey(selectedKeyIndex); needsRepaint = true; } mouseIsDownOverKey = false; } if (mouseIsDownOverKey && guiEvent.type == EventType.MouseDrag) { float keyTime = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, guiEvent.mousePosition.x); //selectedKeyIndex = gradient.UpdateKeyTime(selectedKeyIndex, keyTime); var key = GetKeyProp(selectedKeyIndex).FindPropertyRelative("time"); key.floatValue = keyTime; needsRepaint = true; } }