forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateAnimationStateSystem.cs
More file actions
51 lines (49 loc) · 2.05 KB
/
Copy pathUpdateAnimationStateSystem.cs
File metadata and controls
51 lines (49 loc) · 2.05 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#if !UNITY_DISABLE_MANAGED_COMPONENTS
using Unity.Entities;
using Unity.NetCode;
using Unity.NetCode.Hybrid;
using Unity.Transforms;
namespace Samples.HelloNetcode
{
/// <summary>
/// Run this system after collecting input but before Animator.Update is called.
/// As Animator.Update is invoked right after SimulationSystemGroup,
/// we inject our selves right after this system group runs.
/// </summary>
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
[UpdateInGroup(typeof(SimulationSystemGroup))]
public partial struct UpdateAnimationStateSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<EnableAnimation>();
}
public void OnUpdate(ref SystemState state)
{
var presentationGameObjectSystem =
state.World.GetExistingSystemManaged<GhostPresentationGameObjectSystem>();
foreach (var (input, localToWorld, character, entity) in SystemAPI
.Query<RefRO<CharacterControllerPlayerInput>, RefRW<LocalTransform>, RefRO<Character>>()
.WithAll<GhostOwnerIsLocal>()
.WithEntityAccess())
{
var gameObjectForEntity =
presentationGameObjectSystem.GetGameObjectForEntity(state.EntityManager, entity);
var myData = new CharacterAnimationData
{
IsShooting = input.ValueRO.PrimaryFire.IsSet,
Movement = input.ValueRO.Movement,
OnGround = character.ValueRO.OnGround == 1,
Pitch = input.ValueRO.Pitch,
Yaw = input.ValueRO.Yaw,
};
var characterAnimation = gameObjectForEntity.GetComponent<CharacterAnimation>();
if (characterAnimation != null)
{
localToWorld.ValueRW = characterAnimation.UpdateAnimationState(myData, localToWorld.ValueRO);
}
}
}
}
}
#endif