mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2024-11-14 00:05:35 +01:00
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using Unity.Collections;
|
|
using Unity.Entities;
|
|
using Unity.Transforms;
|
|
using UnityEngine;
|
|
|
|
namespace TAO.VertexAnimation
|
|
{
|
|
|
|
[RequireMatchingQueriesForUpdate]
|
|
public partial class AnimationBakingSystem : SystemBase
|
|
{
|
|
protected override void OnUpdate()
|
|
{
|
|
EntityCommandBuffer entityCommandBuffer = new EntityCommandBuffer( Allocator.Temp );
|
|
foreach (var (animator, wait) in
|
|
SystemAPI.Query<RefRW<AnimatorComponent>, RefRW<AnimatorWaitingForBaking>>())
|
|
{
|
|
DynamicBuffer<Child> children = EntityManager.GetBuffer < Child >( wait.ValueRO.AnimatorEntity );
|
|
Debug.Log( children.Length );
|
|
animator.ValueRW.SkinnedMeshes = new NativeArray < Entity >( children.Length, Allocator.Persistent );
|
|
int i = 0;
|
|
foreach ( Child child in children )
|
|
{
|
|
animator.ValueRW.SkinnedMeshes[i] = child.Value;
|
|
i++;
|
|
}
|
|
|
|
wait.ValueRW.IsInitialized = true;
|
|
entityCommandBuffer.RemoveComponent<AnimatorWaitingForBaking>( wait.ValueRO.AnimatorEntity );
|
|
//EntityManager.RemoveComponent < AnimatorWaitingForBaking >( wait.AnimatorEntity );
|
|
}
|
|
|
|
entityCommandBuffer.Playback( EntityManager );
|
|
}
|
|
}
|
|
|
|
}
|