-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathAnimationBakingSystem.cs
More file actions
37 lines (32 loc) · 1.26 KB
/
AnimationBakingSystem.cs
File metadata and controls
37 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 );
}
}
}