namespace UnityEngine.Animations.Rigging { /// /// Interface for animatable property handles used to read and write /// values in the AnimationStream. /// /// The animatable value type public interface IAnimatableProperty { /// /// Gets the property value from a stream. /// /// The AnimationStream that holds the animated values. /// The property value. T Get(AnimationStream stream); /// /// Sets the property value into a stream. /// /// The AnimationStream that holds the animated values. /// The new property value. void Set(AnimationStream stream, T value); } /// /// Boolean property handle used to read and write values in the AnimationStream. /// public struct BoolProperty : IAnimatableProperty { /// The PropertyStreamHandle used in the AnimationStream. public PropertyStreamHandle value; /// /// Creates a BoolProperty handle representing a property binding on a Component. /// /// The Animator on which to bind the new handle. /// The Component owning the parameter. /// The property name /// Returns a BoolProperty handle that represents the new binding. public static BoolProperty Bind(Animator animator, Component component, string name) { return new BoolProperty() { value = animator.BindStreamProperty(component.transform, component.GetType(), name) }; } /// /// Creates a BoolProperty handle for a custom property in the AnimationStream to pass extra data to downstream animation jobs in the graph. /// /// The Animator on which to bind the new handle. /// The name of the property. /// Returns a BoolProperty handle that represents the new binding. public static BoolProperty BindCustom(Animator animator, string property) { return new BoolProperty { value = animator.BindCustomStreamProperty(property, CustomStreamPropertyType.Bool) }; } /// /// Gets the property value from a stream. /// /// The AnimationStream that holds the animated values. /// The boolean property value. public bool Get(AnimationStream stream) => value.GetBool(stream); /// /// Sets the property value into a stream. /// /// The AnimationStream that holds the animated values. /// The new boolean property value. public void Set(AnimationStream stream, bool v) => value.SetBool(stream, v); } /// /// Integer property handle used to read and write values in the AnimationStream. /// public struct IntProperty : IAnimatableProperty { /// The PropertyStreamHandle used in the AnimationStream. public PropertyStreamHandle value; /// /// Creates a IntProperty handle representing a property binding on a Component. /// /// The Animator on which to bind the new handle. /// The Component owning the parameter. /// The property name /// Returns a IntProperty handle that represents the new binding. public static IntProperty Bind(Animator animator, Component component, string name) { return new IntProperty() { value = animator.BindStreamProperty(component.transform, component.GetType(), name) }; } /// /// Creates a IntProperty handle for a custom property in the AnimationStream to pass extra data to downstream animation jobs in the graph. /// /// The Animator on which to bind the new handle. /// The name of the property. /// Returns a IntProperty handle that represents the new binding. public static IntProperty BindCustom(Animator animator, string property) { return new IntProperty { value = animator.BindCustomStreamProperty(property, CustomStreamPropertyType.Int) }; } /// /// Gets the property value from a stream. /// /// The AnimationStream that holds the animated values. /// The integer property value. public int Get(AnimationStream stream) => value.GetInt(stream); /// /// Sets the property value into a stream. /// /// The AnimationStream that holds the animated values. /// The new integer property value. public void Set(AnimationStream stream, int v) => value.SetInt(stream, v); } /// /// Float property handle used to read and write values in the AnimationStream. /// public struct FloatProperty : IAnimatableProperty { /// The PropertyStreamHandle used in the AnimationStream. public PropertyStreamHandle value; /// /// Creates a FloatProperty handle representing a property binding on a Component. /// /// The Animator on which to bind the new handle. /// The Component owning the parameter. /// The property name /// Returns a FloatProperty handle that represents the new binding. public static FloatProperty Bind(Animator animator, Component component, string name) { return new FloatProperty() { value = animator.BindStreamProperty(component.transform, component.GetType(), name) }; } /// /// Creates a FloatProperty handle for a custom property in the AnimationStream to pass extra data to downstream animation jobs in the graph. /// /// The Animator on which to bind the new handle. /// The name of the property. /// Returns a FloatProperty handle that represents the new binding. public static FloatProperty BindCustom(Animator animator, string property) { return new FloatProperty { value = animator.BindCustomStreamProperty(property, CustomStreamPropertyType.Float) }; } /// /// Gets the property value from a stream. /// /// The AnimationStream that holds the animated values. /// The float property value. public float Get(AnimationStream stream) => value.GetFloat(stream); /// /// Sets the property value into a stream. /// /// The AnimationStream that holds the animated values. /// The new float property value. public void Set(AnimationStream stream, float v) => value.SetFloat(stream, v); } /// /// Vector2 property handle used to read and write values in the AnimationStream. /// public struct Vector2Property : IAnimatableProperty { /// The PropertyStreamHandle used for the X component in the AnimationStream. public PropertyStreamHandle x; /// The PropertyStreamHandle used for the Y component in the AnimationStream. public PropertyStreamHandle y; /// /// Creates a Vector2Property handle representing a property binding on a Component. /// /// The Animator on which to bind the new handle. /// The Component owning the parameter. /// The property name /// Returns a Vector2Property handle that represents the new binding. public static Vector2Property Bind(Animator animator, Component component, string name) { var type = component.GetType(); return new Vector2Property { x = animator.BindStreamProperty(component.transform, type, name + ".x"), y = animator.BindStreamProperty(component.transform, type, name + ".y") }; } /// /// Creates a Vector2Property handle for a custom property in the AnimationStream to pass extra data to downstream animation jobs in the graph. /// /// The Animator on which to bind the new handle. /// The name of the property. /// Returns a Vector2Property handle that represents the new binding. public static Vector2Property BindCustom(Animator animator, string name) { return new Vector2Property { x = animator.BindCustomStreamProperty(name + ".x", CustomStreamPropertyType.Float), y = animator.BindCustomStreamProperty(name + ".y", CustomStreamPropertyType.Float) }; } /// /// Gets the property value from a stream. /// /// The AnimationStream that holds the animated values. /// The Vector2 property value. public Vector2 Get(AnimationStream stream) => new Vector2(x.GetFloat(stream), y.GetFloat(stream)); /// /// Sets the property value into a stream. /// /// The AnimationStream that holds the animated values. /// The new Vector2 property value. public void Set(AnimationStream stream, Vector2 value) { x.SetFloat(stream, value.x); y.SetFloat(stream, value.y); } } /// /// Vector3 property handle used to read and write values in the AnimationStream. /// public struct Vector3Property : IAnimatableProperty { /// The PropertyStreamHandle used for the X component in the AnimationStream. public PropertyStreamHandle x; /// The PropertyStreamHandle used for the Y component in the AnimationStream. public PropertyStreamHandle y; /// The PropertyStreamHandle used for the Z component in the AnimationStream. public PropertyStreamHandle z; /// /// Creates a Vector3Property handle representing a property binding on a Component. /// /// The Animator on which to bind the new handle. /// The Component owning the parameter. /// The property name /// Returns a Vector3Property handle that represents the new binding. public static Vector3Property Bind(Animator animator, Component component, string name) { var type = component.GetType(); return new Vector3Property { x = animator.BindStreamProperty(component.transform, type, name + ".x"), y = animator.BindStreamProperty(component.transform, type, name + ".y"), z = animator.BindStreamProperty(component.transform, type, name + ".z") }; } /// /// Creates a Vector3Property handle for a custom property in the AnimationStream to pass extra data to downstream animation jobs in the graph. /// /// The Animator on which to bind the new handle. /// The name of the property. /// Returns a Vector3Property handle that represents the new binding. public static Vector3Property BindCustom(Animator animator, string name) { return new Vector3Property { x = animator.BindCustomStreamProperty(name + ".x", CustomStreamPropertyType.Float), y = animator.BindCustomStreamProperty(name + ".y", CustomStreamPropertyType.Float), z = animator.BindCustomStreamProperty(name + ".z", CustomStreamPropertyType.Float) }; } /// /// Gets the property value from a stream. /// /// The AnimationStream that holds the animated values. /// The Vector3 property value. public Vector3 Get(AnimationStream stream) => new Vector3(x.GetFloat(stream), y.GetFloat(stream), z.GetFloat(stream)); /// /// Sets the property value into a stream. /// /// The AnimationStream that holds the animated values. /// The new Vector3 property value. public void Set(AnimationStream stream, Vector3 value) { x.SetFloat(stream, value.x); y.SetFloat(stream, value.y); z.SetFloat(stream, value.z); } } /// /// Vector3Int property handle used to read and write values in the AnimationStream. /// public struct Vector3IntProperty : IAnimatableProperty { /// The PropertyStreamHandle used for the X component in the AnimationStream. public PropertyStreamHandle x; /// The PropertyStreamHandle used for the Y component in the AnimationStream. public PropertyStreamHandle y; /// The PropertyStreamHandle used for the Z component in the AnimationStream. public PropertyStreamHandle z; /// /// Creates a Vector3IntProperty handle representing a property binding on a Component. /// /// The Animator on which to bind the new handle. /// The Component owning the parameter. /// The property name /// Returns a Vector3IntProperty handle that represents the new binding. public static Vector3IntProperty Bind(Animator animator, Component component, string name) { var type = component.GetType(); return new Vector3IntProperty { x = animator.BindStreamProperty(component.transform, type, name + ".x"), y = animator.BindStreamProperty(component.transform, type, name + ".y"), z = animator.BindStreamProperty(component.transform, type, name + ".z") }; } /// /// Creates a Vector3IntProperty handle for a custom property in the AnimationStream to pass extra data to downstream animation jobs in the graph. /// /// The Animator on which to bind the new handle. /// The name of the property. /// Returns a Vector3IntProperty handle that represents the new binding. public static Vector3IntProperty BindCustom(Animator animator, string name) { return new Vector3IntProperty { x = animator.BindCustomStreamProperty(name + ".x", CustomStreamPropertyType.Int), y = animator.BindCustomStreamProperty(name + ".y", CustomStreamPropertyType.Int), z = animator.BindCustomStreamProperty(name + ".z", CustomStreamPropertyType.Int) }; } /// /// Gets the property value from a stream. /// /// The AnimationStream that holds the animated values. /// The Vector3Int property value. public Vector3Int Get(AnimationStream stream) => new Vector3Int(x.GetInt(stream), y.GetInt(stream), z.GetInt(stream)); /// /// Sets the property value into a stream. /// /// The AnimationStream that holds the animated values. /// The new Vector3Int property value. public void Set(AnimationStream stream, Vector3Int value) { x.SetInt(stream, value.x); y.SetInt(stream, value.y); z.SetInt(stream, value.z); } } /// /// Vector3Bool property handle used to read and write values in the AnimationStream. /// public struct Vector3BoolProperty : IAnimatableProperty { /// The PropertyStreamHandle used for the X component in the AnimationStream. public PropertyStreamHandle x; /// The PropertyStreamHandle used for the Y component in the AnimationStream. public PropertyStreamHandle y; /// The PropertyStreamHandle used for the Z component in the AnimationStream. public PropertyStreamHandle z; /// /// Creates a Vector3BoolProperty handle representing a property binding on a Component. /// /// The Animator on which to bind the new handle. /// The Component owning the parameter. /// The property name /// Returns a Vector3BoolProperty handle that represents the new binding. public static Vector3BoolProperty Bind(Animator animator, Component component, string name) { var type = component.GetType(); return new Vector3BoolProperty { x = animator.BindStreamProperty(component.transform, type, name + ".x"), y = animator.BindStreamProperty(component.transform, type, name + ".y"), z = animator.BindStreamProperty(component.transform, type, name + ".z") }; } /// /// Creates a Vector3BoolProperty handle for a custom property in the AnimationStream to pass extra data to downstream animation jobs in the graph. /// /// The Animator on which to bind the new handle. /// The name of the property. /// Returns a Vector3BoolProperty handle that represents the new binding. public static Vector3BoolProperty BindCustom(Animator animator, string name) { return new Vector3BoolProperty { x = animator.BindCustomStreamProperty(name + ".x", CustomStreamPropertyType.Bool), y = animator.BindCustomStreamProperty(name + ".y", CustomStreamPropertyType.Bool), z = animator.BindCustomStreamProperty(name + ".z", CustomStreamPropertyType.Bool) }; } /// /// Gets the property value from a stream. /// /// The AnimationStream that holds the animated values. /// The Vector3Bool property value. public Vector3Bool Get(AnimationStream stream) => new Vector3Bool(x.GetBool(stream), y.GetBool(stream), z.GetBool(stream)); /// /// Sets the property value into a stream. /// /// The AnimationStream that holds the animated values. /// The new Vector3Bool property value. public void Set(AnimationStream stream, Vector3Bool value) { x.SetBool(stream, value.x); y.SetBool(stream, value.y); z.SetBool(stream, value.z); } } /// /// Vector4 property handle used to read and write values in the AnimationStream. /// public struct Vector4Property : IAnimatableProperty { /// The PropertyStreamHandle used for the X component in the AnimationStream. public PropertyStreamHandle x; /// The PropertyStreamHandle used for the Y component in the AnimationStream. public PropertyStreamHandle y; /// The PropertyStreamHandle used for the Z component in the AnimationStream. public PropertyStreamHandle z; /// The PropertyStreamHandle used for the X component in the AnimationStream. public PropertyStreamHandle w; /// /// Creates a Vector4Property handle representing a property binding on a Component. /// /// The Animator on which to bind the new handle. /// The Component owning the parameter. /// The property name /// Returns a Vector4Property handle that represents the new binding. public static Vector4Property Bind(Animator animator, Component component, string name) { var type = component.GetType(); return new Vector4Property { x = animator.BindStreamProperty(component.transform, type, name + ".x"), y = animator.BindStreamProperty(component.transform, type, name + ".y"), z = animator.BindStreamProperty(component.transform, type, name + ".z"), w = animator.BindStreamProperty(component.transform, type, name + ".w") }; } /// /// Creates a Vector4Property handle for a custom property in the AnimationStream to pass extra data to downstream animation jobs in the graph. /// /// The Animator on which to bind the new handle. /// The name of the property. /// Returns a Vector4Property handle that represents the new binding. public static Vector4Property BindCustom(Animator animator, string name) { return new Vector4Property { x = animator.BindCustomStreamProperty(name + ".x", CustomStreamPropertyType.Float), y = animator.BindCustomStreamProperty(name + ".y", CustomStreamPropertyType.Float), z = animator.BindCustomStreamProperty(name + ".z", CustomStreamPropertyType.Float), w = animator.BindCustomStreamProperty(name + ".w", CustomStreamPropertyType.Float) }; } /// /// Gets the property value from a stream. /// /// The AnimationStream that holds the animated values. /// The Vector4 property value. public Vector4 Get(AnimationStream stream) => new Vector4(x.GetFloat(stream), y.GetFloat(stream), z.GetFloat(stream), w.GetFloat(stream)); /// /// Sets the property value into a stream. /// /// The AnimationStream that holds the animated values. /// The new Vector4 property value. public void Set(AnimationStream stream, Vector4 value) { x.SetFloat(stream, value.x); y.SetFloat(stream, value.y); z.SetFloat(stream, value.z); w.SetFloat(stream, value.w); } } }