Game.UI.Widgets.AnimationCurveField
Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 mods)
Namespace:
Game.UI.Widgets
Type:
class
Base:
Field
Summary:
A UI field widget for editing an AnimationCurve. It caches keyframes and wrap modes and exposes a nested Bindings factory that creates runtime-callable bindings for manipulating the curve (move, add, set, remove keyframes). The widget implements IMutable
Fields
-
private System.Collections.Generic.List<UnityEngine.Keyframe> m_Keys
A cached list of Keyframe objects representing the last-known keys of the underlying AnimationCurve value. Used to detect changes to the curve's keys during Update. -
private UnityEngine.WrapMode m_PreWrapMode
Cache of the curve's preWrapMode to detect changes and mark the widget as needing property update. -
private UnityEngine.WrapMode m_PostWrapMode
Cache of the curve's postWrapMode to detect changes and mark the widget as needing property update.
Properties
- (No public properties declared in this class)
This class inherits the value handling from Fieldand implements IMutable . Access to the current AnimationCurve is provided via the IMutable/Field base APIs (e.g., GetValue/SetValue as implemented on the base or interface), not as a direct public property inside this class.
Constructors
public AnimationCurveField()
No explicit constructor is declared in the source; the default parameterless constructor is used. Initialization and lifecycle behavior are provided by the base Field class and the widget system.
Methods
-
protected override WidgetChanges Update() : WidgetChanges
Compares the current AnimationCurve value to the cached state (m_Keys, m_PreWrapMode, m_PostWrapMode). If keys or wrap modes changed since the last update, the method sets the WidgetChanges.Properties flag and updates the caches. Returns the accumulated WidgetChanges indicating what parts of the widget need refreshing. -
Nested type:
public class Bindings : IWidgetBindingFactory
Factory that creates bindings for external code (scripts, UI binding system) to manipulate this widget's AnimationCurve value. Its CreateBindings method yields several bindings: -
Binding: "moveKeyframe"
Signature: CallBinding
Behavior: Attempts to move the key at the given index to the provided Keyframe. Before moving it verifies adjacent key times to avoid conflicts (it will not move if either neighbor has the same time as the target). If smooth is true, it applies SmoothTangents at the moved index using average of in/out weights ((key.inWeight + key.outWeight)/2f). Invokes the provided onValueChanged callback when the operation completes. Returns the resulting index (may differ if MoveKey changes order). -
Binding: "addKeyframe"
Signature: CallBinding
Behavior: Adds a new key at the specified time/value via AnimationCurve.AddKey and returns the new key index. Calls onValueChanged after adding. -
Binding: "setKeyframes"
Signature: TriggerBinding
Behavior: Replaces all existing keys on the curve with the provided array of Keyframes. Implementation clears all keys, then adds each provided key (AddKey) and calls MoveKey for each to set full key data (time, value, tangents, weights). Calls onValueChanged after replacement. -
Binding: "removeKeyframe"
Signature: TriggerBinding
Behavior: Removes the key at the specified index (AnimationCurve.RemoveKey) and calls onValueChanged after removal.
For all bindings, if the widget instance passed into the binding does not implement IMutable
Usage Example
// Example: programmatically modify the curve stored by the field (assuming this code is inside a context
// where you have a reference to the AnimationCurveField instance or via UI scripting that resolves the widget):
AnimationCurveField field = /* resolved widget instance implementing IMutable<AnimationCurve> */;
if (field is IMutable<AnimationCurve> mutable)
{
// Add a key at time 1.0 with value 2.0
int newIndex = mutable.GetValue().AddKey(1.0f, 2.0f);
// Smooth tangents at the new key (average of in/out weights)
mutable.GetValue().SmoothTangents(newIndex, 0.5f);
// Notify the UI binding system or let the widget's own mechanisms detect changes.
}
// Alternatively, use the provided bindings from Bindings factory in the UI binding system:
// - "addKeyframe" to add
// - "moveKeyframe" to move and optionally smooth
// - "setKeyframes" to replace all keys
// - "removeKeyframe" to remove a key