public EditPattern AddNewDefaultPattern() { var newPattern = new Animations.EditPattern(); newPattern.name = "New Pattern"; for (int i = 0; i < 20; ++i) { var grad = new EditRGBGradient(); grad.keyframes.Add(new EditRGBKeyframe() { time = 0.0f, color = Color.black }); grad.keyframes.Add(new EditRGBKeyframe() { time = 0.5f, color = Color.white }); grad.keyframes.Add(new EditRGBKeyframe() { time = 1.0f, color = Color.black }); newPattern.gradients.Add(grad); } patterns.Add(newPattern); return(newPattern); }
void Repaint(EditRGBGradient currentGradient) { Color[] pixels = _texture.GetPixels(); int x = 0, lastMax = 0; for (int i = 1; i < currentGradient.keyframes.Count; ++i) { int max = Mathf.RoundToInt(currentGradient.keyframes[i].time * pixels.Length); for (; x < max; ++x) { pixels[x] = Color.Lerp(currentGradient.keyframes[i - 1].color, currentGradient.keyframes[i].color, ((float)x - lastMax) / (max - lastMax)); } lastMax = max; } _texture.SetPixels(pixels); _texture.Apply(false); }
/// <summary> /// Invoke the color picker /// </sumary> public void Show(string title, EditRGBGradient previousGradient, System.Action <bool, EditRGBGradient> closeAction) { if (isShown) { Debug.LogWarning("Previous Color picker still active"); ForceHide(); } gameObject.SetActive(true); currentGradient = previousGradient.Duplicate(); titleText.text = title; multiSlider.FromGradient(currentGradient); multiSlider.HandleSelected += OnHandleSelected; multiSlider.SelectHandle(multiSlider.AllHandles[0]); colorEditor.onColorSelected += OnColorSelected; this.closeAction = closeAction; saveButton.gameObject.SetActive(true); }
void Hide(bool result, EditRGBGradient gradient) { gameObject.SetActive(false); closeAction?.Invoke(result, gradient); closeAction = null; }