Class CreateAnimationBindingAttribute
Use this attribute on an animatable field of a MonoBehaviour that acts as a proxy to a field in an IComponentData. The general use-case is when we have an authoring component that doesn't match 1-to-1 with the generated component(s) but we still want to animate fields on the resulting component(s).
Namespace: Unity.Tiny.Animation
Syntax
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
public class CreateAnimationBindingAttribute : Attribute, _Attribute
Remarks
We consider a field animatable on a MonoBehaviour when it is:
- a float or a Vector type
- serialized either through [SerializeField] or because it is public
- not explicitly marked with [NotKeyable]
- not in a type marked with [NotKeyable]
We consider a field animatable on an IComponentData when it is:
- a float or a floatX type
- public
- not explicitly marked with [NotKeyable]
- not in a type marked with [NotKeyable]
Note that conversion between VectorX and floatX is handled implicitly.
Examples
In this example, we want to animate the value of
FloatValue
so we add the serializable field float m_Value
on the authoring component FloatValueAuthoring
on which we apply the CreateAnimationBinding
attribute.
struct FloatValue : IComponentData { public float value; } // We want to be able to animate value
class FloatValueAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
[SerializeField]
[CreateAnimationBinding(typeof(FloatValue), nameof(FloatValue.value))] // We use the attribute to tell the system what IComponentData field it should match
float m_Value;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
dstManager.AddComponentData(entity, new FloatValue { value = m_Value } );
}
}
Constructors
CreateAnimationBindingAttribute(Type, String)
Constructor for CreateAnimationBindingAttribute
Declaration
public CreateAnimationBindingAttribute(Type componentType, string propertyPath)
Parameters
Type | Name | Description |
---|---|---|
Type | componentType | The type of the IComponentData struct containing the field we want to animate. |
String | propertyPath | The path to the field we want to animate. For simple cases, it is possible to use .
For more complex cases, use the format "field.subField.subField".
|
Properties
BindsTo
Declaration
public string BindsTo { get; }
Property Value
Type | Description |
---|---|
String |