using Rukhanka; using Unity.Burst; using Unity.Collections; using Unity.Entities; #if RUKHANKA_WITH_NETCODE using Unity.NetCode; #endif using UnityEngine; using static Rukhanka.AnimatorControllerSystemJobs; ///////////////////////////////////////////////////////////////////////////////////////////////////// [assembly: RegisterGenericSystemType(typeof(AnimatorControllerSystem))] [assembly: RegisterGenericSystemType(typeof(AnimatorControllerSystem))] ///////////////////////////////////////////////////////////////////////////////////////////////////// namespace Rukhanka { [DisableAutoCreation] public partial struct AnimatorControllerSystem: ISystem where T: AnimatorControllerQueryCreator, new() { EntityQuery animatorControllerQuery; ///////////////////////////////////////////////////////////////////////////////////////////////////// [BurstCompile] public void OnCreate(ref SystemState ss) { var queryCreator = new T(); animatorControllerQuery = queryCreator.CreateQuery(ref ss); ss.RequireForUpdate(animatorControllerQuery); } ///////////////////////////////////////////////////////////////////////////////////////////////////// [BurstCompile] public void OnUpdate(ref SystemState ss) { var dt = SystemAPI.Time.DeltaTime; var controllerLayersBufferHandle = SystemAPI.GetBufferTypeHandle(); var controllerParametersBufferHandle = SystemAPI.GetBufferTypeHandle(); var animatorOverrideAnimationsLookup = SystemAPI.GetComponentLookup(true); var entityTypeHandle = SystemAPI.GetEntityTypeHandle(); var controllerEventsBufferLookup = SystemAPI.GetBufferLookup(); var animDBSingleton = SystemAPI.GetSingleton(); var internalDataSingletonQuery = SystemAPI.QueryBuilder().WithAllRW().Build(); var internalAnimatorData = FillAnimationsFromControllerSystem.GetInternalDataSingleton(internalDataSingletonQuery, ref ss); var stateMachineProcessJob = new StateMachineProcessJob() { controllerLayersBufferHandle = controllerLayersBufferHandle, controllerParametersBufferHandle = controllerParametersBufferHandle, dt = dt, entityTypeHandle = entityTypeHandle, controllerEventsBufferLookup = controllerEventsBufferLookup, animationDatabase = animDBSingleton.animations, animatorOverrideAnimationLookup = animatorOverrideAnimationsLookup, animatorOverrideAnimationsMap = internalAnimatorData.animatorOverrideAnimationsMap.AsParallelWriter() }; ss.Dependency = stateMachineProcessJob.ScheduleParallel(animatorControllerQuery, ss.Dependency); } } ///////////////////////////////////////////////////////////////////////////////////////////////////// public interface AnimatorControllerQueryCreator { EntityQuery CreateQuery(ref SystemState ss); } ///////////////////////////////////////////////////////////////////////////////////////////////////// public struct PredictedAnimatorControllerQuery: AnimatorControllerQueryCreator { public EntityQuery CreateQuery(ref SystemState ss) { var eqBuilder0 = new EntityQueryBuilder(Allocator.Temp) .WithAllRW() #if RUKHANKA_WITH_NETCODE .WithAll() #endif ; var animatorControllerQuery = ss.GetEntityQuery(eqBuilder0); return animatorControllerQuery; } } ///////////////////////////////////////////////////////////////////////////////////////////////////// public struct AnimatorControllerQuery: AnimatorControllerQueryCreator { public EntityQuery CreateQuery(ref SystemState ss) { var eqBuilder0 = new EntityQueryBuilder(Allocator.Temp) .WithAllRW() #if RUKHANKA_WITH_NETCODE .WithNone() #endif ; var animatorControllerQuery = ss.GetEntityQuery(eqBuilder0); return animatorControllerQuery; } } }