Class Baker<TAuthoringType>
Inherit this class to bake an authoring component.
Inherited Members
Namespace: Unity.Entities
Assembly: solution.dll
Syntax
public abstract class Baker<TAuthoringType> : IBaker where TAuthoringType : Component
Type Parameters
Name | Description |
---|---|
TAuthoringType | The type of the authoring component. |
Remarks
Use the methods in Baker<TAuthoringType> to access any data outside of the authoring component. This ensures that the baking pipeline can keep track of any dependencies. This applies to GameObjects, Components, prefabs, and assets.
For example you should use Baker<TAuthoringType>.GetComponent<T>() to query the authoring components instead of GameObject.GetComponent<T>().
Examples
public class MyAuthoring : MonoBehaviour
{
public int Value;
}
public struct MyComponent : IComponentData
{
public int Value;
public float3 Position;
}
public class MyBaker : Baker<MyAuthoring>
{
public override void Bake(MyAuthoring authoring)
{
// Accessing the transform using Baker function, not the GameObject one
// so the this baker can keep track of the dependency
var transform = GetComponent<Transform>();
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new MyComponent
{
Value = authoring.Value,
Position = transform.position
} );
}
}
Methods
Name | Description |
---|---|
Bake(TAuthoringType) | Called in the baking process to bake the authoring component |