public void OnGUI() { Event guiEvent = Event.current; Rect gradientPreviewRect = new Rect(borderSize, borderSize, position.width - borderSize * 2, 25); GUI.DrawTexture(gradientPreviewRect, gradient.GetTexture((int)gradientPreviewRect.width, (int)gradientPreviewRect.height)); for (int i = 0; i < gradient.NumKeys(); i++) { CustomGradient.ColourKey key = gradient.GetKey(i); Rect keyRect = new Rect(gradientPreviewRect.x + gradientPreviewRect.width * key.Time - keyWidth / 2f, gradientPreviewRect.yMax + borderSize, keyWidth, keyHeight); EditorGUI.DrawRect(keyRect, key.Colour); } if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0) { Color randomColor = new Color(Random.value, Random.value, Random.value); float keyTime = Mathf.InverseLerp(gradientPreviewRect.x, gradientPreviewRect.xMax, guiEvent.mousePosition.x); gradient.AddKey(randomColor, keyTime); Repaint(); } }