protected override JobHandle OnUpdate(JobHandle inputDeps) { var ecb = m_BeginPresentationEcbSystem.CreateCommandBuffer().ToConcurrent(); PayMaintenance payMaintenance = new PayMaintenance() { environmentSettings = Environment.environmentSettings, ecb = ecb }; JobHandle jobHandle = payMaintenance.Schedule(m_Group, inputDeps); m_BeginPresentationEcbSystem.AddJobHandleForProducer(jobHandle); jobHandle.Complete(); DestroyPetals destroyPetals = new DestroyPetals() { environmentSettings = Environment.environmentSettings, ecb = ecb }; jobHandle = destroyPetals.Schedule(petalGroup, jobHandle); m_BeginPresentationEcbSystem.AddJobHandleForProducer(jobHandle); jobHandle.Complete(); return(jobHandle); }
protected override JobHandle OnUpdate(JobHandle inputDep) { int spawnCount = 0; int cnt; while (spawnCountQueue.TryDequeue(out cnt)) { spawnCount += cnt; } SetSingleton(new ParticleSpawnCountComponent { spawnCount = spawnCount }); var commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); var spawnJob = new ParticleSpawnJob(); spawnJob.spawnCountQueue = spawnCountQueue.ToConcurrent(); spawnJob.commandBuffer = commandBuffer; spawnJob.deltaTime = Time.deltaTime; spawnJob.m_ColorSizeParticleArchetype = m_ColorSizeParticleArchetype; spawnJob.m_ColorParticleArchetype = m_ColorParticleArchetype; spawnJob.m_SizeParticleArchetype = m_SizeParticleArchetype; spawnJob.m_ParticleArchetype = m_ParticleArchetype; inputDep = spawnJob.Schedule(this, inputDep); barrier.AddJobHandleForProducer(inputDep); return(inputDep); }
protected override void OnUpdate() { var commandBuffer = _entityCommandBufferSystem.CreateCommandBuffer(); // var commandBuffer = _entityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); var mapEntity = _mapQuery.GetSingletonEntity(); var mapData = _mapQuery.GetSingleton <MapData>(); var mapTileBuffer = EntityManager.GetBuffer <MapTileBuffer>(mapEntity); var visualMapEntity = _visualMapQuery.GetSingletonEntity(); var renderMesh = EntityManager.GetSharedComponentData <RenderMesh>(visualMapEntity); Entities .WithAll <GenerateVisualMap>() // .ForEach((Entity entity) => .ForEach((Entity entity, int entityInQueryIndex) => { var w = mapData.Width; var h = mapData.Height; Debug.Log($"Making grid mesh - w: {w} h: {h}"); var mesh = MeshUtility.GenerateGrid(w, h); renderMesh.mesh = mesh; commandBuffer.SetSharedComponent(visualMapEntity, renderMesh); // commandBuffer.SetSharedComponent(entityInQueryIndex, visualMapEntity, renderMesh); commandBuffer.DestroyEntity(entity); // commandBuffer.DestroyEntity(entityInQueryIndex, entity); }) .WithoutBurst() .Run(); // .Schedule(); _entityCommandBufferSystem.AddJobHandleForProducer(Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { timer += Time.DeltaTime; if (timer < interval) { return(inputDeps); } else { timer -= interval; } var employmentData = GetComponentDataFromEntity <EmploymentComponent>(true); var relatedUnitData = GetComponentDataFromEntity <RelatedUnitComponent>(false); var exchangeTaskData = GetComponentDataFromEntity <ExchangeTaskComponent>(true); var ecb = ecbSystem.CreateCommandBuffer().AsParallelWriter(); JobHandle jobHandle = Entities .WithReadOnly(employmentData) .WithNativeDisableParallelForRestriction(relatedUnitData) .WithReadOnly(exchangeTaskData) .WithAll <UnitTagComponent>() .ForEach((int entityInQueryIndex, Entity entity, ref Scale scale, in NeedsAndDutiesComponent needsAndDuties) => { if (needsAndDuties.HungerStatus != HungerStatus.Negative) { return; } if (employmentData.HasComponent(entity)) { var vacancy = employmentData[entity].Vacancy; var component = relatedUnitData[vacancy]; component.Entity = Entity.Null; ecb.SetComponent(entityInQueryIndex, vacancy, component); } if (exchangeTaskData.HasComponent(entity)) { var task = exchangeTaskData[entity]; if (task.TaskGiver != Entity.Null && task.Step == ExchangeTaskStep.Started) { var removal = ecb.CreateEntity(entityInQueryIndex); ecb.AddComponent(entityInQueryIndex, removal, new ThreadSafeOrderRemovalComponent { RequestedResourceName = task.RequestedResourceName, Orderer = task.ExchangeInventoryEntity, OrdersReceiver = task.TaskGiver, Recipe = task.Recipe, RequestedAmount = task.RequestedResourceAmount }); } } scale.Value = 0f; ecb.RemoveComponent <UnitTagComponent>(entityInQueryIndex, entity); }).Schedule(inputDeps); return(jobHandle); }
protected override JobHandle OnUpdate(JobHandle inputDep) { var job = new ParticleAgeJob(); job.commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); job.deltaTime = Time.deltaTime; var handle = job.Schedule(this, inputDep); barrier.AddJobHandleForProducer(handle); return(handle); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { NativeArray <DeleteEntityEvent> eventArray = m_Query.ToComponentDataArray <DeleteEntityEvent>(Allocator.TempJob); ParallellDeleteQueue parallellDeleteQueue = new ParallellDeleteQueue { lookup = GetBufferFromEntity <Child>(true), eventArray = eventArray, commandBuffer = beginPresentationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent() }; inputDeps = parallellDeleteQueue.Schedule(eventArray.Length, 32, inputDeps); beginPresentationEntityCommandBufferSystem.AddJobHandleForProducer(inputDeps); return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDep) { var commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); var initJob = new ParticleInitializeJob(); initJob.emitterComponentType = ComponentType.ReadWrite <ParticleEmitterComponentData>(); initJob.commandBuffer = commandBuffer; initJob.randomData = randomData; initJob.randomBase = randomDataBase; var spawnCount = GetSingleton <ParticleSpawnCountComponent>().spawnCount; randomDataBase = (randomDataBase + spawnCount) % randomData.Length; inputDep = initJob.Schedule(this, inputDep); barrier.AddJobHandleForProducer(inputDep); return(inputDep); }
protected override void OnUpdate() { int spawnCount = 0; int cnt; while (m_SpawnCountQueue.TryDequeue(out cnt)) { spawnCount += cnt; } SetSingleton(new ParticleSpawnCountComponent { spawnCount = spawnCount }); var commandBuffer = m_Barrier.CreateCommandBuffer().AsParallelWriter(); var spawnCountQueue = m_SpawnCountQueue.AsParallelWriter(); var colorSizeParticleArchetype = m_ColorSizeParticleArchetype; var colorParticleArchetype = m_ColorParticleArchetype; var sizeParticleArchetype = m_SizeParticleArchetype; var particleArchetype = m_ParticleArchetype; var deltaTime = Time.DeltaTime; Entities.WithNone <ParticleComponentData>().ForEach((Entity entity, int nativeThreadIndex, in ParticleEmitterComponentData emitter, in Translation position, in Rotation rotation) => { if (emitter.active == 0) { return; } int particles = (int)(deltaTime * emitter.particlesPerSecond + 0.5f); if (particles == 0) { return; } spawnCountQueue.Enqueue(particles); float2 spawnOffset = math.mul(rotation.Value, new float3(emitter.spawnOffset, 0)).xy; bool colorTrans = math.any(emitter.startColor != emitter.endColor); bool sizeTrans = emitter.startLength != emitter.endLength || emitter.startWidth != emitter.endWidth; EntityArchetype currentParticleType; if (colorTrans && sizeTrans) { currentParticleType = colorSizeParticleArchetype; } else if (colorTrans) { currentParticleType = colorParticleArchetype; } else if (sizeTrans) { currentParticleType = sizeParticleArchetype; } else { currentParticleType = particleArchetype; } // Create the first particle, then instantiate the rest based on its value var particle = commandBuffer.CreateEntity(nativeThreadIndex, currentParticleType); commandBuffer.SetComponent(nativeThreadIndex, particle, emitter); // Set initial data commandBuffer.SetComponent(nativeThreadIndex, particle, new ParticleVelocityComponentData()); commandBuffer.SetComponent(nativeThreadIndex, particle, new Translation { Value = position.Value + new float3(spawnOffset, 0) }); commandBuffer.SetComponent(nativeThreadIndex, particle, new Rotation { Value = rotation.Value }); if (colorTrans) { commandBuffer.SetComponent(nativeThreadIndex, particle, new ParticleColorTransitionComponentData(emitter.startColor, emitter.endColor)); } if (sizeTrans) { commandBuffer.SetComponent(nativeThreadIndex, particle, new ParticleSizeTransitionComponentData(emitter.startLength, emitter.endLength, emitter.startWidth, emitter.endWidth)); } if (particles > 1) { for (int i = 1; i < particles; ++i) { commandBuffer.Instantiate(nativeThreadIndex, particle); } //particleEntities.ResizeUninitialized(particles - 1); //NativeArray<Entity> temp = particleEntities; //EntityManager.Instantiate(particle, temp); } }).ScheduleParallel();
protected unsafe override void OnUpdate() { var _ecb = m_EntityCommandBufferSystem.CreateCommandBuffer(); var _ecbo = m_EntityCommandBufferSystemo.CreateCommandBuffer(); var _ecbEndSimilation = m_endSimulationEntityCommandBufferSystem.CreateCommandBuffer(); var _ecbBeginPresentation = m_beginPresentationEntityCommandBufferSystem.CreateCommandBuffer(); var _physicsWorldSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystem <Unity.Physics.Systems.BuildPhysicsWorld>(); CollisionWorld _collisionWorld = _physicsWorldSystem.PhysicsWorld.CollisionWorld; var _physicsWorld = _physicsWorldSystem.PhysicsWorld; float3 _startPosition = ECS_RTSControls.instance._startScreenPosition; float3 _endPosition = ECS_RTSControls.instance._endScreenPosition; float3 _lowerLeftPosition = ECS_RTSControls.instance._lowerLeftScreenPosition; float3 _upperRightPosition = ECS_RTSControls.instance._upperRightScreenPosition; Dependency = JobHandle.CombineDependencies(Dependency, m_EndFramePhysicsSystem.GetOutputDependency()); if (_inputReady) { if (Input_Mouse_0_Up == true && Input_Mouse_0_Up != EntityManager.HasComponent <Input_Mouse_0_Up>(_inputEntity)) { Input_Mouse_0_GetDown = true; Input_Mouse_0_Up = false; } if (Input_Mouse_0_Up == false && (Input_Mouse_0_Up != EntityManager.HasComponent <Input_Mouse_0_Up>(_inputEntity))) { Input_Mouse_0_GetUp = true; Input_Mouse_0_Up = true; } if (Input_Mouse_1_Up == true && (Input_Mouse_1_Up != EntityManager.HasComponent <Input_Mouse_1_Up>(_inputEntity))) { Input_Mouse_1_GetDown = true; Input_Mouse_1_Up = false; } if (Input_Mouse_1_Up == false && (Input_Mouse_1_Up != EntityManager.HasComponent <Input_Mouse_1_Up>(_inputEntity))) { Input_Mouse_1_GetUp = true; Input_Mouse_1_Up = true; } } else { if (_queryInput.CalculateEntityCount() > 0) { _inputEntity = _queryInput.GetSingletonEntity(); _inputReady = true; Input_Mouse_0_Up = EntityManager.HasComponent <Input_Mouse_0_Up>(_inputEntity); Input_Mouse_1_Up = EntityManager.HasComponent <Input_Mouse_1_Up>(_inputEntity); } } if (Time.ElapsedTime > 4) { /*this.Dependency = Entities.WithoutBurst().ForEach((in Translation _translation, in UnitSelected _unitSelected, in Selectable _selectable, in GrisTag _grisTag, in Entity _entity) => * { * var e = _ecbEndSimilation.Instantiate(PrefabConvert._DalleVerte); * _ecbEndSimilation.SetComponent<Translation>(e, _translation); * _ecbEndSimilation.DestroyEntity(_entity); * Debug.Log("Unity3d : 'va te faire foutre'"); * * }).Schedule(this.Dependency);*/ } if (Input_Mouse_0_GetUp == true) { bool selectOnlyOneEntity = false; float selectionAreaMinSize = 10f; float selectionAreaSize = math.distance(_lowerLeftPosition, _upperRightPosition); if (selectionAreaSize < selectionAreaMinSize) { // Selection area too small _lowerLeftPosition += new float3(-1, -1, 0) * (selectionAreaMinSize - selectionAreaSize) * .5f; _upperRightPosition += new float3(+1, +1, 0) * (selectionAreaMinSize - selectionAreaSize) * .5f; selectOnlyOneEntity = true; } // Deselect all selected Entities this.Dependency = Entities.WithAll <UnitSelected>().ForEach((Entity entity) => { _ecb.RemoveComponent <UnitSelected>(entity); }).Schedule(this.Dependency); Unity.Physics.RaycastHit _hit1 = new Unity.Physics.RaycastHit(); Unity.Physics.RaycastHit _hit2 = new Unity.Physics.RaycastHit(); Unity.Physics.RaycastHit _hit3 = new Unity.Physics.RaycastHit(); Unity.Physics.RaycastHit _hit4 = new Unity.Physics.RaycastHit(); Unity.Physics.RaycastHit _hit5 = new Unity.Physics.RaycastHit(); var _ray1 = ECS_RTSControls.instance._ray1; var _ray2 = ECS_RTSControls.instance._ray2; var _ray3 = ECS_RTSControls.instance._ray3; var _ray4 = ECS_RTSControls.instance._ray4; var _ray5 = ECS_RTSControls.instance._ray5; /*RaycastInput _inputo = new RaycastInput() * { * Start = _ray1.origin, * End = _ray1.origin + _ray1.direction * 1000, * Filter = new CollisionFilter() * { * BelongsTo = (uint)10 << 10, * CollidesWith = (uint)7 << 8, * GroupIndex = 8 * } * };*/ GetRaycastHit(_collisionWorld, _ray1, _ray2, _ray3, _ray4, _ray5, out _hit1, out _hit2, out _hit3, out _hit4, out _hit5); var _filter = new CollisionFilter() { BelongsTo = ~1u, CollidesWith = ~1u, // all 1s, so all layers, collide with everything GroupIndex = 0 }; NativeList <ColliderCastHit> _allHits = new NativeList <ColliderCastHit>(Allocator.TempJob); _polygonCollider = Unity.Physics.PolygonCollider.CreateQuad(_hit1.Position, _hit2.Position, _hit3.Position, _hit4.Position, _filter); /*SphereGeometry sphereGeometry = new SphereGeometry() { Center = float3.zero, Radius = 3 }; * _sphereCollider = Unity.Physics.SphereCollider.Create(sphereGeometry, _filter);*/ /* * Unity.Physics.ColliderCastInput colliderCastInput = new ColliderCastInput() * { * Collider = (Unity.Physics.Collider*)_sphereCollider.GetUnsafePtr(), * Orientation = ECS_RTSControls.instance._camera.transform.rotation, * Start = ECS_RTSControls.instance._camera.transform.position, * End = _ray1.origin + _ray1.direction * 1000 * };*/ var _moyPoly = new float3((_hit1.Position.x + _hit2.Position.x + _hit3.Position.x + _hit4.Position.x) / 4, (_hit1.Position.y + _hit2.Position.y + _hit3.Position.y + _hit4.Position.y) / 4, (_hit1.Position.z + _hit2.Position.z + _hit3.Position.z + _hit4.Position.z) / 4); Debug.Log(_moyPoly + "_moyPoly"); //var _pouitCollider = BlobAssetReference<Unity.Physics.Collider>.Create(_polygonCollider.GetUnsafePtr(), 1); /* this.Dependency = Job.WithoutBurst().WithCode(() => * { * var e = _ecb.Instantiate(PrefabConvert._CubeRouge); * _ecb.SetComponent<Translation>(e, new Translation { Value = _hit1.Position + new float3(0, 5, 0) }); * e = _ecb.Instantiate(PrefabConvert._CubeRouge); * _ecb.SetComponent<Translation>(e, new Translation { Value = _hit2.Position + new float3(0, 5, 0) }); * e = _ecb.Instantiate(PrefabConvert._CubeRouge); * _ecb.SetComponent<Translation>(e, new Translation { Value = _hit3.Position + new float3(0, 5, 0) }); * e = _ecb.Instantiate(PrefabConvert._CubeRouge); * _ecb.SetComponent<Translation>(e, new Translation { Value = _hit4.Position + new float3(0, 5, 0) }); * }).Schedule(this.Dependency); * Debug.Log(_dalleSelectedQuery.CalculateEntityCount() + "_dalleSelectedQueryCount"); * Debug.Log(_dalleQuery.CalculateEntityCount() + "_dalleQueryCount"); * * /*Mesh _mesh = new Mesh { } * * RenderMesh huiaef = new RenderMesh { mesh = } * * this.Dependency.Complete();*/ ColliderCastJob _colliderCastJob = new ColliderCastJob(); _colliderCastJob.CollectAllHits = true; _colliderCastJob.Collider = (Unity.Physics.Collider *)_polygonCollider.GetUnsafePtr(); _colliderCastJob.ColliderCastHits = _allHits; _colliderCastJob.End = new float3(0, -2, 0); // _moyPoly; _colliderCastJob.Orientation = quaternion.identity; //ECS_RTSControls.instance._camera.transform.rotation; _colliderCastJob.Start = /*_moyPoly +*/ new float3(0, 5, 0); _colliderCastJob.World = _physicsWorld; Dependency = _colliderCastJob.ScheduleSingle(_query, this.Dependency); //World.GetOrCreateSystem<StepPhysicsWorld>().FinalSimulationJobHandle.Complete(); this.Dependency.Complete(); /*Debug.Log(_query.CalculateEntityCount() + "_queryMovestats"); * Debug.Log(_allHits.Length + "_allHits.Length");*/ this.Dependency = Job.WithoutBurst().WithDisposeOnCompletion(_allHits).WithCode(() => { for (int i = 0; i < _allHits.Length; i++) { _ecbEndSimilation.AddComponent(_allHits[i].Entity, new UnitSelected()); } Debug.Log(_allHits.Length + "entityHits"); }).Schedule(this.Dependency); this.Dependency.Complete(); } if (Input_Mouse_1_Up == false) { if (Time.ElapsedTime > 2) { Debug.Log("yoloZoulou"); this.Dependency = Entities.WithoutBurst().WithAll <PlaneLayer>().WithAll <Player1>().ForEach((Entity entity) => { _ecb.DestroyEntity(entity);//.RemoveComponent<UnitSelected>(entity); }).Schedule(this.Dependency); } //Debug.Log(Input.GetMouseButtonDown(1)); // Right mouse button down float3 targetPosition = UtilsClass.GetMouseWorldPosition(); List <float3> movePositionList = GetPositionListAround(targetPosition, new float[] { 10f, 20f, 30f }, new int[] { 5, 10, 20 }); int positionIndex = 0; Entities.WithAll <UnitSelected>().ForEach((Entity entity, ref MoveStats _moveStats) => { /*moveTo.position = movePositionList[positionIndex]; * positionIndex = (positionIndex + 1) % movePositionList.Count; * moveTo.move = true;*/ }).Schedule(); } //m_EntityCommandBufferSystem.AddJobHandleForProducer(this.Dependency); World.GetOrCreateSystem <StepPhysicsWorld>().FinalSimulationJobHandle.Complete(); this.Dependency.Complete(); m_EntityCommandBufferSystemo.AddJobHandleForProducer(this.Dependency); m_endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(this.Dependency); m_EntityCommandBufferSystemo.AddJobHandleForProducer(this.Dependency); if (_polygonCollider.IsCreated) { _polygonCollider.Dispose(); } if (_sphereCollider.IsCreated) { _sphereCollider.Dispose(); } Input_Mouse_0_GetUp = false; Input_Mouse_0_GetDown = false; }
protected override void OnUpdate() { var nodeOutputs = GetComponentDataFromEntity <NodeOutput>(true); foreach (var depth in ValidDagDepths) { if (depth.Value == 0) { continue; // skip depth-zero nodes; they should all be buttons. } var ecb = _beginPresEcbSystem.CreateCommandBuffer().AsParallelWriter(); Dependency = Entities .WithName("GatePropagateSystem") .WithNativeDisableContainerSafetyRestriction(nodeOutputs) // DAG sort ensures each pass writes to different outputs than it reads .WithSharedComponentFilter(depth) .ForEach((Entity nodeEntity, int entityInQueryIndex, ref NodeOutput output, in DynamicBuffer <NodeInput> inputs, in GateInfo gateInfo) => { float newOutput = 0.0f; switch (gateInfo.Type) { case GateType.And: newOutput = (int)nodeOutputs[inputs[0].InputEntity].Value & (int)nodeOutputs[inputs[1].InputEntity].Value; break; case GateType.Or: newOutput = (int)nodeOutputs[inputs[0].InputEntity].Value | (int)nodeOutputs[inputs[1].InputEntity].Value; break; case GateType.Xor: newOutput = (int)nodeOutputs[inputs[0].InputEntity].Value ^ (int)nodeOutputs[inputs[1].InputEntity].Value; break; case GateType.Not: newOutput = 1 - (int)nodeOutputs[inputs[0].InputEntity].Value; break; case GateType.Sink: newOutput = 1; for (int i = 0; i < inputs.Length; ++i) { if (nodeOutputs[inputs[i].InputEntity].Value == 0) { newOutput = 0; break; } } // Add the tag that begins the "end of level" flow if (newOutput == 1 && output.Value == 0) { ecb.AddComponent <VictoryTag>(entityInQueryIndex, nodeEntity); } break; case GateType.Button: break; // handled in HandleInputSystem, and skipped because dagDepth=0 case GateType.BranchOn: newOutput = nodeOutputs[inputs[0].InputEntity].Value; break; case GateType.BranchOff: newOutput = 0; break; } output.Value = newOutput; }).ScheduleParallel(Dependency);