Skip to content

Game.Prefabs.AnimationProperties

Assembly: Assembly-CSharp (Game)
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
AnimationProperties is a prefab component that holds baked GPU animation clip metadata (BakedAnimationClip[]) for a prefab and, during prefab initialization, converts that data into ECS AnimationClip buffer entries. It bridges authoring-time baked animation textures (Texture2DArray) and runtime GPU animation playback data used by Colossal.GPUAnimation and rendering systems. This component is typically filled in the editor (inspector) with baked animation clips and then used to populate an Entity's AnimationClip DynamicBuffer at initialization time.


Fields

  • public BakedAnimationClip[] m_Clips
    Holds an array of baked animation descriptors (see nested BakedAnimationClip). Each element references an animation texture slice range and per-clip metadata which will be converted into runtime AnimationClip data and written to the entity's AnimationClip buffer during Initialize.

Nested type: BakedAnimationClip fields:

  • public string name
    Name of the original animation clip.

  • public int pixelStart
    Start pixel (column) in the Texture2DArray where this clip begins.

  • public int pixelEnd
    End pixel (column) in the Texture2DArray where this clip ends.

  • public float animationLength
    Length/duration of the source animation clip in seconds.

  • public bool looping
    Whether the original clip was looped (wrap mode).

  • public Texture2DArray animationTexture
    Reference to the Texture2DArray that contains baked keyframe textures for this clip.

  • public AnimationType m_Type
    Type of the animation (enum from Colossal.GPUAnimation / game).

  • public ActivityType m_Activity
    Activity type used by the game's animation/activity system.

  • public float m_MovementSpeed
    Movement speed encoded for the clip, used by playback/motion logic.

  • public float3 m_RootOffset
    Root position offset for the clip (Unity.Mathematics.float3).

  • public quaternion m_RootRotation
    Root rotation for the clip (Unity.Mathematics.quaternion).

Properties

  • None.

Constructors

  • public AnimationProperties()
    Default MonoBehaviour/ComponentBase constructor (no explicit initialization in source).

Nested type constructor:

  • public BakedAnimationClip(Texture2DArray animTexture, KeyframeTextureBaker.AnimationClipData clipData)
    Initializes a BakedAnimationClip from a baked animation texture and the corresponding KeyframeTextureBaker.AnimationClipData, copying name, pixelStart/pixelEnd, animationLength and looping flag, and storing the Texture2DArray reference.

Methods

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Override present but empty in this class; no archetype components added by this component. (No-op.)

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime component type required by the prefab: AnimationClip (ReadWrite). This ensures entities created from this prefab have an AnimationClip DynamicBuffer.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    If m_Clips is not null, resizes the entity's AnimationClip DynamicBuffer to m_Clips.Length, then for each BakedAnimationClip:

  • Creates a default AnimationClip struct.
  • Calls BakedAnimationClip.CalculatePlaybackData(ref clip) to populate texture offsets, pixel/width values, animation length, root offsets/rotation, movement speed, type, activity, layer and playback settings.
  • Writes the populated AnimationClip into the entity's buffer at the matching index.

Nested type method:

  • public void CalculatePlaybackData(ref AnimationClip clip)
    Converts baked clip metadata + animationTexture into runtime AnimationClip fields:
  • Computes texture offsets (m_TextureOffset, m_TextureRange), one-pixel offsets and inv widths, and sets texture width related fields.
  • Copies animationLength, movement speed, root offset/rotation, type, activity.
  • Sets m_PropID to new AnimatedPropID(-1), m_Layer to AnimationLayer.Body.
  • Sets m_Playback to RandomLoop if looping is true, otherwise Once.
  • This prepares the AnimationClip struct for use by GPU animation playback systems.

Usage Example

// Authoring: assign m_Clips in the prefab inspector. Each BakedAnimationClip should reference
// a Texture2DArray and the source KeyframeTextureBaker.AnimationClipData (created during baking).

// At runtime (prefab initialization) the component will populate the AnimationClip DynamicBuffer.
// Example of reading back the populated buffer in a system or script:

EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
if (em.HasComponent<AnimationClip>(entity))
{
    DynamicBuffer<AnimationClip> buffer = em.GetBuffer<AnimationClip>(entity);
    for (int i = 0; i < buffer.Length; i++)
    {
        AnimationClip clip = buffer[i];
        Debug.Log($"Clip {i}: textureOffset={clip.m_TextureOffset}, range={clip.m_TextureRange}, length={clip.m_AnimationLength}");
    }
}

// If you are authoring a BakedAnimationClip manually (editor tooling), use the constructor:
var baked = new AnimationProperties.BakedAnimationClip(animTextureArray, clipData);
// Populate optional fields:
baked.m_MovementSpeed = 1.0f;
baked.m_RootOffset = new float3(0, 0, 0);
baked.m_RootRotation = quaternion.identity;

Notes: - This component depends on Colossal.GPUAnimation types (AnimationClip, AnimatedPropID, AnimationLayer, AnimationPlayback) and Unity.Entities (DynamicBuffer, EntityManager). - The CalculatePlaybackData method expects the animation texture to be laid out such that pixelStart/pixelEnd correspond to column indices within animationTexture.width.