private void OnAddKeyClicked(Image image, MouseButton button) { if (button == MouseButton.Left && Curve != null) { // Evaluate a value var time = Timeline.CurrentTime; if (!TryGetValue(out var value)) { Curve.Evaluate(out value, time); } // Find keyframe at the current location for (int i = Curve.KeyframesCount - 1; i >= 0; i--) { Curve.GetKeyframe(i, out var kTime, out var kValue, out _, out _); var frame = Mathf.FloorToInt(kTime * Timeline.FramesPerSecond); if (frame == Timeline.CurrentFrame) { // Skip if value is the same if (Equals(kValue, value)) { return; } // Update existing key value Curve.SetKeyframeValue(i, value); UpdatePreviewValue(); return; } } // Add a new key using (new TrackUndoBlock(this)) Curve.AddKeyframe(time, value); } }
private void OnAddKeyClicked(Image image, MouseButton button) { if (button == MouseButton.Left && Curve != null) { // Evaluate a value var time = Timeline.CurrentTime; if (!TryGetValue(out var value)) { Curve.Evaluate(out value, time); } // Find keyframe at the current location var keyframes = Curve.GetKeyframes(); for (int i = keyframes.Length - 1; i >= 0; i--) { var k = keyframes[i]; var frame = Mathf.FloorToInt(k.Time * Timeline.FramesPerSecond); if (frame == Timeline.CurrentFrame) { // Skip if value is the same if (k.Value == value) { return; } // Update existing key value Curve.SetKeyframe(i, value); UpdatePreviewValue(); return; } } // Add a new key Curve.AddKeyframe(time, value); } }