protected override void OnUpdate() { var commandBuffer = barrier.CreateCommandBuffer().AsParallelWriter(); var randomArray = World.GetExistingSystem <RandomSystem>().RandomArray; var surfaceAABB = surfaceAabb; Entities .WithAll <PathAgent>() .WithNone <PathProblem, PathDestination, PathBufferElement>() .WithNativeDisableParallelForRestriction(randomArray) .ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex) => { var random = randomArray[nativeThreadIndex]; var pos = NavUtil.GetRandomPointInBounds( ref random, surfaceAABB, 1, float3.zero ); commandBuffer.AddComponent(entityInQueryIndex, entity, new PathDestination { WorldPoint = pos }); randomArray[nativeThreadIndex] = random; }) .WithName("PathDestinationJob") .ScheduleParallel(); barrier.AddJobHandleForProducer(Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if ( !SceneManager.GetActiveScene().name.Equals("NavPerformanceDemo") && !SceneManager.GetActiveScene().name.Equals("NavMovingJumpDemo") ) { return(inputDeps); } var commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); var jumpableBufferFromEntity = GetBufferFromEntity <NavJumpableBufferElement>(true); var renderBoundsFromEntity = GetComponentDataFromEntity <RenderBounds>(true); var randomArray = World.GetExistingSystem <RandomSystem>().RandomArray; var job = Entities .WithNone <NavLerping>() .WithReadOnly(jumpableBufferFromEntity) .WithReadOnly(renderBoundsFromEntity) .WithNativeDisableParallelForRestriction(randomArray) .ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, ref NavAgent agent) => { if ( agent.Surface.Equals(Entity.Null) || !jumpableBufferFromEntity.Exists(agent.Surface) ) { return; } var jumpableSurfaces = jumpableBufferFromEntity[agent.Surface]; var random = randomArray[nativeThreadIndex]; if (jumpableSurfaces.Length == 0) { // For the NavPerformanceDemo scene. var bounds = renderBoundsFromEntity[agent.Surface].Value; agent.WorldDestination = NavUtil.GetRandomPointInBounds(ref random, bounds, agent.Offset, 99); } else { // For the NavMovingJumpDemo scene. agent.DestinationSurface = jumpableSurfaces[random.NextInt(0, jumpableSurfaces.Length)]; var bounds = renderBoundsFromEntity[agent.DestinationSurface].Value; agent.LocalDestination = NavUtil.GetRandomPointInBounds(ref random, bounds, agent.Offset, 0.7f); // Agents should not try to jump too close to an edge, hence the scale. } commandBuffer.AddComponent <NavPlanning>(entityInQueryIndex, entity); randomArray[nativeThreadIndex] = random; }) .WithName("NavDestinationJob") .Schedule(inputDeps); barrier.AddJobHandleForProducer(job); return(job); }
protected override void OnUpdate() { var physicsWorld = buildPhysicsWorld.PhysicsWorld; var settings = navSystem.Settings; var commandBuffer = barrier.CreateCommandBuffer().AsParallelWriter(); var jumpableBufferFromEntity = GetBufferFromEntity <NavJumpableBufferElement>(true); var renderBoundsFromEntity = GetComponentDataFromEntity <RenderBounds>(true); var randomArray = World.GetExistingSystem <RandomSystem>().RandomArray; Dependency = JobHandle.CombineDependencies(Dependency, buildPhysicsWorld.GetOutputDependency()); Entities .WithNone <NavProblem, NavDestination, NavPlanning>() .WithReadOnly(jumpableBufferFromEntity) .WithReadOnly(renderBoundsFromEntity) .WithReadOnly(physicsWorld) .WithNativeDisableParallelForRestriction(randomArray) .ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, ref NavAgent agent, in Parent surface, in LocalToWorld localToWorld) => { if ( surface.Value.Equals(Entity.Null) || !jumpableBufferFromEntity.HasComponent(surface.Value) ) { return; } var jumpableSurfaces = jumpableBufferFromEntity[surface.Value]; var random = randomArray[nativeThreadIndex]; if ( physicsWorld.GetPointOnSurfaceLayer( localToWorld, NavUtil.GetRandomPointInBounds( ref random, renderBoundsFromEntity[surface.Value].Value, 99 ), out var validDestination, settings.ObstacleRaycastDistanceMax, settings.ColliderLayer, settings.SurfaceLayer ) ) { commandBuffer.AddComponent(entityInQueryIndex, entity, new NavDestination { WorldPoint = validDestination }); } randomArray[nativeThreadIndex] = random; })
protected override void OnUpdate() { var commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); var jumpableBufferFromEntity = GetBufferFromEntity <NavJumpableBufferElement>(true); var renderBoundsFromEntity = GetComponentDataFromEntity <RenderBounds>(true); var localToWorldFromEntity = GetComponentDataFromEntity <LocalToWorld>(true); var randomArray = World.GetExistingSystem <RandomSystem>().RandomArray; Entities .WithNone <NavHasProblem, NavNeedsDestination>() .WithReadOnly(jumpableBufferFromEntity) .WithReadOnly(renderBoundsFromEntity) .WithReadOnly(localToWorldFromEntity) .WithNativeDisableParallelForRestriction(randomArray) .ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, ref NavAgent agent, in Parent surface) => { if ( surface.Value.Equals(Entity.Null) || !jumpableBufferFromEntity.Exists(surface.Value) ) { return; } var jumpableSurfaces = jumpableBufferFromEntity[surface.Value]; var random = randomArray[nativeThreadIndex]; var destinationSurface = jumpableSurfaces[random.NextInt(0, jumpableSurfaces.Length)]; var localPoint = NavUtil.GetRandomPointInBounds( ref random, renderBoundsFromEntity[destinationSurface].Value, 3 ); var worldPoint = NavUtil.MultiplyPoint3x4( localToWorldFromEntity[destinationSurface.Value].Value, localPoint ); commandBuffer.AddComponent(entityInQueryIndex, entity, new NavNeedsDestination { Destination = worldPoint }); randomArray[nativeThreadIndex] = random; }) .WithName("NavMovingJumpDestinationJob") .ScheduleParallel(); barrier.AddJobHandleForProducer(Dependency); }
protected override void OnUpdate() { var commandBuffer = barrier.CreateCommandBuffer().AsParallelWriter(); var jumpableBufferFromEntity = GetBufferFromEntity <NavJumpableBufferElement>(true); var renderBoundsFromEntity = GetComponentDataFromEntity <RenderBounds>(true); var randomArray = World.GetExistingSystem <RandomSystem>().RandomArray; Entities .WithNone <NavProblem, NavDestination>() .WithReadOnly(jumpableBufferFromEntity) .WithReadOnly(renderBoundsFromEntity) .WithNativeDisableParallelForRestriction(randomArray) .ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, ref NavAgent agent, in Parent surface) => { if ( surface.Value.Equals(Entity.Null) || !jumpableBufferFromEntity.HasComponent(surface.Value) ) { return; } var jumpableSurfaces = jumpableBufferFromEntity[surface.Value]; var random = randomArray[nativeThreadIndex]; commandBuffer.AddComponent(entityInQueryIndex, entity, new NavDestination { WorldPoint = NavUtil.GetRandomPointInBounds( ref random, renderBoundsFromEntity[surface.Value].Value, 99, float3.zero ) }); randomArray[nativeThreadIndex] = random; }) .WithName("NavPerformanceDestinationJob") .ScheduleParallel(); barrier.AddJobHandleForProducer(Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if ( !SceneManager.GetActiveScene().name.Equals("NavPerformanceDemo") && !SceneManager.GetActiveScene().name.Equals("NavMovingJumpDemo") ) { return(inputDeps); } var commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); var jumpableBufferFromEntity = GetBufferFromEntity <NavJumpableBufferElement>(true); var renderBoundsFromEntity = GetComponentDataFromEntity <RenderBounds>(true); var localToWorldFromEntity = GetComponentDataFromEntity <LocalToWorld>(true); var randomArray = World.GetExistingSystem <RandomSystem>().RandomArray; var job = Entities .WithNone <NavNeedsDestination>() .WithReadOnly(jumpableBufferFromEntity) .WithReadOnly(renderBoundsFromEntity) .WithReadOnly(localToWorldFromEntity) .WithNativeDisableParallelForRestriction(randomArray) .ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, ref NavAgent agent, in Parent surface) => { if ( surface.Value.Equals(Entity.Null) || !jumpableBufferFromEntity.Exists(surface.Value) ) { return; } var jumpableSurfaces = jumpableBufferFromEntity[surface.Value]; var random = randomArray[nativeThreadIndex]; if (jumpableSurfaces.Length == 0) { // For the NavPerformanceDemo scene. commandBuffer.AddComponent(entityInQueryIndex, entity, new NavNeedsDestination { Value = NavUtil.GetRandomPointInBounds( ref random, renderBoundsFromEntity[surface.Value].Value, agent.Offset, 99 ) }); } else { // For the NavMovingJumpDemo scene. var destinationSurface = jumpableSurfaces[random.NextInt(0, jumpableSurfaces.Length)]; var localPoint = NavUtil.GetRandomPointInBounds( ref random, renderBoundsFromEntity[destinationSurface].Value, agent.Offset, 3 ); var worldPoint = NavUtil.MultiplyPoint3x4( localToWorldFromEntity[destinationSurface.Value].Value, localPoint ); commandBuffer.AddComponent(entityInQueryIndex, entity, new NavNeedsDestination { Value = worldPoint }); } randomArray[nativeThreadIndex] = random; }) .WithName("NavDestinationJob") .Schedule(inputDeps); barrier.AddJobHandleForProducer(job); return(job); }