protected override JobHandle OnUpdate(JobHandle inputDeps) { if (m_CharacterControllersGroup.CalculateEntityCount() == 0) { return(inputDeps); } var chunks = m_CharacterControllersGroup.CreateArchetypeChunkArray(Allocator.TempJob); var characterMoveType = GetArchetypeChunkComponentType <CharacterMoveSetting>(); var userCommandType = GetArchetypeChunkComponentType <UserCommand>(); var movePredictedType = GetArchetypeChunkComponentType <CharacterMovePredictedState>(); var transformType = GetArchetypeChunkComponentType <TransformPredictedState>(); var velocityType = GetArchetypeChunkComponentType <VelocityPredictedState>(); var physicsColliderType = GetArchetypeChunkComponentType <PhysicsCollider>(); var entityType = GetArchetypeChunkEntityType(); var deferredImpulses = new NativeStream(chunks.Length, Allocator.TempJob); var tickDuration = GetSingleton <WorldTime>().TickDuration; var ccJob = new CharacterControllerJob { EntityType = entityType, // Archetypes CharacterMoveType = characterMoveType, UserCommandComponentType = userCommandType, CharacterMovePredictedType = movePredictedType, PhysicsColliderType = physicsColliderType, TransformType = transformType, VelocityType = velocityType, // Input DeltaTime = tickDuration, PhysicsWorld = m_BuildPhysicsWorldSystem.PhysicsWorld, DeferredImpulseWriter = deferredImpulses.AsWriter() }; inputDeps = JobHandle.CombineDependencies(inputDeps, m_ExportPhysicsWorldSystem.FinalJobHandle); inputDeps = ccJob.Schedule(m_CharacterControllersGroup, inputDeps); var applyJob = new ApplyDefferedPhysicsUpdatesJob { Chunks = chunks, DeferredImpulseReader = deferredImpulses.AsReader(), PhysicsMassData = GetComponentDataFromEntity <PhysicsMass>(), TransformPredictedData = GetComponentDataFromEntity <TransformPredictedState>(), VelocityPredictedData = GetComponentDataFromEntity <VelocityPredictedState>(), CharacterMovePredictedData = GetComponentDataFromEntity <CharacterMovePredictedState>() }; inputDeps = applyJob.Schedule(inputDeps); var disposeHandle = deferredImpulses.Dispose(inputDeps); disposeHandle.Complete(); // Must finish all jobs before physics step end // m_EndFramePhysicsSystem.HandlesToWaitFor.Add(disposeHandle); return(inputDeps); }
protected override void OnUpdate() { if (m_CharacterControllersGroup.CalculateEntityCount() == 0) { return; } var chunks = m_CharacterControllersGroup.CreateArchetypeChunkArray(Allocator.TempJob); var ccComponentType = GetComponentTypeHandle <CharacterControllerComponentData>(); var ccInternalType = GetComponentTypeHandle <CharacterControllerInternalData>(); var physicsColliderType = GetComponentTypeHandle <PhysicsCollider>(); var translationType = GetComponentTypeHandle <Translation>(); var rotationType = GetComponentTypeHandle <Rotation>(); var collisionEventBufferType = GetBufferTypeHandle <StatefulCollisionEvent>(); var triggerEventBufferType = GetBufferTypeHandle <StatefulTriggerEvent>(); var deferredImpulses = new NativeStream(chunks.Length, Allocator.TempJob); var ccJob = new CharacterControllerJob { // Archetypes CharacterControllerComponentType = ccComponentType, CharacterControllerInternalType = ccInternalType, PhysicsColliderType = physicsColliderType, TranslationType = translationType, RotationType = rotationType, CollisionEventBufferType = collisionEventBufferType, TriggerEventBufferType = triggerEventBufferType, // Input DeltaTime = UnityEngine.Time.fixedDeltaTime, PhysicsWorld = m_BuildPhysicsWorldSystem.PhysicsWorld, DeferredImpulseWriter = deferredImpulses.AsWriter() }; Dependency = JobHandle.CombineDependencies(Dependency, m_ExportPhysicsWorldSystem.GetOutputDependency()); Dependency = ccJob.Schedule(m_CharacterControllersGroup, Dependency); var applyJob = new ApplyDefferedPhysicsUpdatesJob() { Chunks = chunks, DeferredImpulseReader = deferredImpulses.AsReader(), PhysicsVelocityData = GetComponentDataFromEntity <PhysicsVelocity>(), PhysicsMassData = GetComponentDataFromEntity <PhysicsMass>(), TranslationData = GetComponentDataFromEntity <Translation>(), RotationData = GetComponentDataFromEntity <Rotation>() }; Dependency = applyJob.Schedule(Dependency); var disposeHandle = deferredImpulses.Dispose(Dependency); // Must finish all jobs before physics step end m_EndFramePhysicsSystem.AddInputDependency(disposeHandle); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (m_CharacterControllersGroup.CalculateEntityCount() == 0) { return(inputDeps); } var chunks = m_CharacterControllersGroup.CreateArchetypeChunkArray(Allocator.TempJob); var ccComponentType = GetArchetypeChunkComponentType <CharacterControllerComponentData>(); var ccInternalType = GetArchetypeChunkComponentType <CharacterControllerInternalData>(); var physicsColliderType = GetArchetypeChunkComponentType <PhysicsCollider>(); var translationType = GetArchetypeChunkComponentType <Translation>(); var rotationType = GetArchetypeChunkComponentType <Rotation>(); var deferredImpulses = new NativeStream(chunks.Length, Allocator.TempJob); var ccJob = new CharacterControllerJob { // Archetypes CharacterControllerComponentType = ccComponentType, CharacterControllerInternalType = ccInternalType, PhysicsColliderType = physicsColliderType, TranslationType = translationType, RotationType = rotationType, // Input DeltaTime = UnityEngine.Time.fixedDeltaTime, cameraWorldPoint = mainCamera.ScreenToWorldPoint(Input.mousePosition), PhysicsWorld = m_BuildPhysicsWorldSystem.PhysicsWorld, DeferredImpulseWriter = deferredImpulses.AsWriter() }; inputDeps = JobHandle.CombineDependencies(inputDeps, m_ExportPhysicsWorldSystem.FinalJobHandle); inputDeps = ccJob.Schedule(m_CharacterControllersGroup, inputDeps); var applyJob = new ApplyDefferedPhysicsUpdatesJob() { Chunks = chunks, DeferredImpulseReader = deferredImpulses.AsReader(), PhysicsVelocityData = GetComponentDataFromEntity <PhysicsVelocity>(), PhysicsMassData = GetComponentDataFromEntity <PhysicsMass>(), TranslationData = GetComponentDataFromEntity <Translation>(), RotationData = GetComponentDataFromEntity <Rotation>() }; inputDeps = applyJob.Schedule(inputDeps); var disposeHandle = deferredImpulses.Dispose(inputDeps); // Must finish all jobs before physics step end m_EndFramePhysicsSystem.HandlesToWaitFor.Add(disposeHandle); return(inputDeps); }