Exemple #1
0
            public void Execute(Entity entity, int index, [ReadOnly] ref LifeCell c0, ref Translation position)
            {
                // Because entities can move around in chunks we can't use the 'index' to look
                // up their details, instead we need to use their grid position
                // to get the correct index in to the correct bit which represents the cell state
                // in the grid

                int idx = ConvertToTileIndex(c0.gridPosition);

                // Load in the cells
                var oldState = oldCellState[idx];
                var newState = newCellState[idx];

                var mask = 1 << GetBitForCell(c0.gridPosition);

                if ((oldState & mask) != (newState & mask))
                {
                    var newPosition = position.Value;
                    if ((newState & mask) > 0)
                    {
                        newPosition.y = 1;
                        CommandBuffer.SetSharedComponent <RenderMesh>(index, entity, LifeUpdateSystem.aliveRenderMesh);
                    }
                    else
                    {
                        newPosition.y = 0;
                        CommandBuffer.SetSharedComponent <RenderMesh>(index, entity, LifeUpdateSystem.deadRenderMesh);
                    }
                    position.Value = newPosition;
                }
            }
 private void spawn_internal(EntityCommandBuffer.Concurrent entity_command_buffer,
                             float current_time,
                             Entity target_entity,
                             Material mat)
 {
     // Develop.print("yes");
     entity_command_buffer.CreateEntity(arche_type_);
     entity_command_buffer.SetComponent(new AlivePeriod {
         start_time_ = current_time, period_ = 0.3f,
     });
     entity_command_buffer.SetComponent(new StartTime {
         value_ = current_time,
     });
     entity_command_buffer.SetComponent(new Sight {
         target_entity_ = target_entity,
     });
     entity_command_buffer.SetSharedComponent(new CustomMeshInstanceRenderer {
         // entity_command_buffer.SetSharedComponent(new MeshInstanceRenderer {
         mesh           = mesh_,
         material       = mat,
         castShadows    = UnityEngine.Rendering.ShadowCastingMode.Off,
         receiveShadows = false,
         layer          = 9 /* final */,
     });
 }
Exemple #3
0
 public void Execute(int index)
 {
     commandBuffer.AddComponent(Infectee[index], new InfectedTag {
         Cooldown = ECSBootstrapper.infectionKillingDay
     });
     commandBuffer.SetSharedComponent(Infectee[index], ECSBootstrapper.humanSickRenderer);
 }
Exemple #4
0
        private void spawn_internal(EntityCommandBuffer.Concurrent entity_command_buffer,
                                    float current_time,
                                    ref float3 position,
                                    float rotation1)
        {
            entity_command_buffer.CreateEntity(arche_type_);
            entity_command_buffer.SetComponent(new Position {
                Value = position,
            });
            entity_command_buffer.SetComponent(new Rotation {
                Value = quaternion.axisAngle(new float3(0f, 0f, 1f), rotation1),
            });
            entity_command_buffer.SetComponent(new AlivePeriod {
                start_time_ = current_time,
                period_     = 0.8f,
            });
            entity_command_buffer.SetComponent(new StartTime {
                value_ = current_time,
            });
            var renderer = new MeshInstanceRenderer {
                mesh           = mesh_,
                material       = material_,
                subMesh        = 0,
                castShadows    = UnityEngine.Rendering.ShadowCastingMode.Off,
                receiveShadows = true,
            };

            entity_command_buffer.SetSharedComponent(renderer);
        }
Exemple #5
0
 private void spawn_internal(EntityCommandBuffer.Concurrent entity_command_buffer,
                             float current_time,
                             ref float3 pos,
                             Material mat)
 {
     entity_command_buffer.CreateEntity(arche_type_);
     entity_command_buffer.SetComponent(new Position {
         Value = pos,
     });
     entity_command_buffer.SetComponent(new Rotation {
         Value = quaternion.identity,
     });
     entity_command_buffer.SetComponent(new AlivePeriod {
         start_time_ = current_time, period_ = 1f,
     });
     entity_command_buffer.SetComponent(new StartTime {
         value_ = current_time,
     });
     entity_command_buffer.SetSharedComponent(new MeshInstanceRenderer {
         mesh           = mesh_,
         material       = mat,
         castShadows    = UnityEngine.Rendering.ShadowCastingMode.Off,
         receiveShadows = false,
     });
 }
            public void Execute(Entity entity, int index, [ReadOnly] ref LifeCell c0, [ReadOnly] ref Translation position)
            {
                // Grab the buffer associated with this entity...
                var buffer = adjacency[entity];
                // ... and figure out how many cells around us are alive this frame.
                int aliveCount = 0;

                foreach (var neighbour in buffer)
                {
                    if (aliveCells.Exists(neighbour))
                    {
                        aliveCount++;
                    }
                }

                // If we aren't alive any more then remove our alive flag
                if (!(aliveCount == 2 || aliveCount == 3))
                {
                    // Untag the entity so that next frame we treat it as dead
                    CommandBuffer.RemoveComponent <AliveCell>(index, entity);
                    // and then do a couple of flips of data so that the rendering is in sync
                    var newPosition = position.Value;
                    newPosition.y = 0;
                    CommandBuffer.SetComponent(index, entity, new Translation {
                        Value = newPosition
                    });
                    CommandBuffer.SetSharedComponent <RenderMesh>(index, entity,
                                                                  LifeUpdateSystem.deadRenderMesh);
                }
            }
            public void Execute(Entity entity, int index, [ReadOnly] ref LifeCell c0, [ReadOnly] ref Translation position)
            {
                // Grab the buffer associated with this entity...
                var buffer = adjacency[entity];

                // ... and figure out how many cells around us are alive this frame.
                int aliveCount = 0;

                foreach (var neighbour in buffer)
                {
                    if (aliveCells.Exists(neighbour))
                    {
                        aliveCount++;
                    }
                }

                // If 3 alive cells are around us, then we live!
                if (aliveCount == 3)
                {
                    // So we tag this entity as being alive
                    CommandBuffer.AddComponent(index, entity, new AliveCell {
                    });
                    // and then do a couple of flips of data so that the rendering is in sync
                    var newPosition = position.Value;
                    newPosition.y = 1;
                    CommandBuffer.SetComponent(index, entity, new Translation {
                        Value = newPosition
                    });
                    CommandBuffer.SetSharedComponent <RenderMesh>(index, entity,
                                                                  LifeUpdateSystem.aliveRenderMesh);
                }
            }
Exemple #8
0
            // [ReadOnly]
            // public RenderMeshTypesData renderMeshTypes ;

            public void Execute(Entity highlightEntity, int jobIndex, [ReadOnly] ref MeshTypeData meshType)
            {
                // renderer
                RenderMesh renderMesh = Bootstrap._SelectRenderMesh(MeshType.Highlight);

                ecb.SetSharedComponent <RenderMesh> (jobIndex, highlightEntity, renderMesh);    // replace renderer with material and mesh

                ecb.RemoveComponent <SetHighlightTag> (jobIndex, highlightEntity);
            }
Exemple #9
0
        public void Execute(ArchetypeChunk ac, int i)
        {
            var na = ac.GetNativeArray(entiType);

            //Debug.Log($"Cleaning {na.Length} {typeof(T).Name}");
            for (int j = 0; j < na.Length; j++)
            {
                ecb.SetSharedComponent <T>(i, na[j], default);
            }
        }
        public void Execute(Entity entity, int index, [ReadOnly] ref ColorChangeComponent colorChangeComponent, [ReadOnly] ref ColorComponent colorComponent)
        {
            var mesh = Highway.GetRenderMeshes()[colorComponent.Value];

            CommandBuffer.SetSharedComponent(index, entity, new RenderMesh()
            {
                mesh = mesh.mesh, material = mesh.material
            });
            CommandBuffer.RemoveComponent <ColorChangeComponent>(index, entity);
        }
Exemple #11
0
        public void spawn_internal(EntityCommandBuffer.Concurrent command_buffer,
                                   ref LockTarget lt,
                                   ref float3 position,
                                   ref quaternion rotation,
                                   ref RandomLocal random,
                                   int index,
                                   Entity target,
                                   float arrive_period,
                                   int job_index)
        {
            command_buffer.CreateEntity(job_index, archetype_);
            command_buffer.SetComponent(job_index, new Position {
                Value = position,
            });
            command_buffer.SetComponent(job_index, new LaserData {
                end_time_      = CV.MaxValue,
                target_entity_ = target,
                arrive_period_ = arrive_period,
                lock_target_   = lt,
            });
            var         rb            = new RigidbodyPosition(0f /* damper */);
            const float FIRE_VEL      = 8f;
            var         fire_velocity = new float3(index % 2 == 0 ? FIRE_VEL * 2f : -FIRE_VEL * 2f,
                                                   random.range(-FIRE_VEL, FIRE_VEL),
                                                   random.range(-FIRE_VEL, FIRE_VEL));

            rb.velocity_ = math.mul(rotation, fire_velocity);
            command_buffer.SetComponent(job_index, rb);
            var td = new TrailData {
                color_type_ = (int)TrailManager.ColorType.Green,
            };

            command_buffer.SetComponent(job_index, td);

            {
                var buffer = command_buffer.SetBuffer <TrailPoint>(job_index);
                for (var i = 0; i < buffer.Capacity; ++i)
                {
                    buffer.Add(new TrailPoint {
                        position_ = position, normal_ = new float3(0f, 0f, 1f),
                    });
                }
            }

            var material = TrailManager.Instance.getMaterial();
            var renderer = new TrailRenderer {
                material_ = material,
            };

            command_buffer.SetSharedComponent <TrailRenderer>(job_index, renderer);
        }
    protected override void OnUpdate()
    {
        timer -= Time.DeltaTime;

        while (timer <= 0)
        {
            //Create parallel writer
            NativeQueue <AnimationInfo> .ParallelWriter events = EventsHolder.AnimationEvents.AsParallelWriter();

            //Create ECB
            EntityCommandBuffer.Concurrent ecb = entityCommandBuffer.CreateCommandBuffer().ToConcurrent();

            //For each entity, swap frame to next one
            Entities.WithoutBurst().WithSharedComponentFilter(new AnimationBatch {
                BatchId = BatchIdToUpdate
            }).ForEach(
                (Entity e, int entityInQueryIndex, ref AnimationData animation, in StateComponent state,
                 in TypeData type) =>
            {
                //Make sure animation exists for this type/state
                if (!AnimationHolder.Animations.ContainsKey(type.Value) ||
                    !AnimationHolder.Animations[type.Value].ContainsKey(state.CurrentAnimationState))
                {
                    return;
                }

                //Increment frame at
                animation.MeshIndexAt++;
                short animationLength = (short)AnimationHolder.Animations[type.Value][state.CurrentAnimationState].Frames.Length;

                //If reached end of animation -> Create Event
                if (animation.MeshIndexAt == animationLength)
                {
                    events.Enqueue(new AnimationInfo
                    {
                        Entity   = e,
                        Type     = AnimationInfo.EventType.OnAnimationEnd,
                        NewState = state.CurrentAnimationState
                    });

                    if (state.CurrentAnimationState == State.Dying)
                    {
                        animation.MeshIndexAt--;
                    }
                }

                //Clamp frame at
                animation.MeshIndexAt %= animationLength;

                ecb.SetSharedComponent(entityInQueryIndex, e, AnimationHolder.Animations[type.Value][state.CurrentAnimationState].Frames[animation.MeshIndexAt]);
            }).ScheduleParallel(Dependency).Complete();
Exemple #13
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var entities = chunk.GetNativeArray(entityType);
            var randoms  = chunk.GetNativeArray(randomType);


            for (int i = 0; i < chunk.Count; ++i)
            {
                if (randoms[i].Generator.NextFloat(0, 1) < Aggression && Enemies.Length > 0)
                {
                    C_Target target;
                    target.Value = Enemies[randoms[i].Generator.NextInt(0, Enemies.Length)];

                    C_TargetType targetType;
                    targetType.Type = TargetTypes.Enemy;

                    ecb.AddComponent(chunkIndex, entities[i], target);
                    ecb.SetSharedComponent(chunkIndex, entities[i], targetType);
                }
                else if (Resources.Length > 0)
                {
                    C_Target target;
                    target.Value = Resources[randoms[i].Generator.NextInt(0, Resources.Length)];

                    C_TargetType targetType;
                    targetType.Type = TargetTypes.Resource;

                    C_GridIndex grid        = GridType[target.Value];
                    C_Stack     stack       = StackType[target.Value];
                    int         stackHeight = StackHeights[GridIndex(grid.x, grid.y)];
                    if (stack.index == stackHeight - 1)
                    {
                        ecb.AddComponent(chunkIndex, entities[i], target);
                        ecb.SetSharedComponent(chunkIndex, entities[i], targetType);
                    }
                }
            }
        }
            public void Execute(Entity entity, int index, [ReadOnly] ref LifeCell c0, ref Translation position)
            {
                // Because entities can move around in chunks we can't use the 'index' to look
                // up their details, instead we need to use their grid position
                // to get the correct index in to the cell state grid
                int idx = ConvertToIndex(c0.gridPosition);

                if (oldCellState[idx] != newCellState[idx])
                {
                    var newPosition = position.Value;
                    if (newCellState[idx])
                    {
                        newPosition.y = 1;
                        CommandBuffer.SetSharedComponent <RenderMesh>(index, entity, LifeUpdateSystem.aliveRenderMesh);
                    }
                    else
                    {
                        newPosition.y = 0;
                        CommandBuffer.SetSharedComponent <RenderMesh>(index, entity, LifeUpdateSystem.deadRenderMesh);
                    }
                    position.Value = newPosition;
                }
            }
Exemple #15
0
 public void Execute(Entity entity, int index, ref HealthComponent health)
 {
     if (health.healthValue == 1 && health.currColor == 0)
     {
         entityCommandBuffer.SetComponent(index, entity, new HealthComponent()
         {
             healthValue = 1, currColor = 1
         });
         entityCommandBuffer.SetSharedComponent <RenderMesh>(index, entity, hurtRenderMesh);
     }
     else if (health.healthValue == 2 && health.currColor == 1)
     {
         entityCommandBuffer.SetComponent(index, entity, new HealthComponent()
         {
             healthValue = 2, currColor = 0
         });
         entityCommandBuffer.SetSharedComponent <RenderMesh>(index, entity, normalRenderMesh);
     }
     else if (health.healthValue <= 0)
     {
         entityCommandBuffer.DestroyEntity(index, entity);
     }
 }
            public void Execute(int index)
            {
                //Create bullet from archetype
                EntityCommandBuffer.CreateEntity(index, Bootstrap.BulletArchetype);

                //Set renderer of bullet
                switch (Weapons[index].Kind)
                {
                case WeaponKind.Player:
                    EntityCommandBuffer.SetSharedComponent(index, Bootstrap.PlayerBulletData.Renderer);
                    break;

                case WeaponKind.Turret:
                    EntityCommandBuffer.SetSharedComponent(index, Bootstrap.TurretBulletData.Renderer);
                    break;
                }

                //Set bullet
                EntityCommandBuffer.SetComponent(index, new Bullet {
                    LifeTime = Weapons[index].BulletLifeTime
                });
                //Set position
                EntityCommandBuffer.SetComponent(index, Positions[index]);
                //Set rotation
                EntityCommandBuffer.SetComponent(index, Rotations[index]);
                //Set scale
                EntityCommandBuffer.SetComponent(index, new Scale {
                    Value = new float3(0.1f)
                });
                //Set move forward
                EntityCommandBuffer.SetSharedComponent(index, new MoveForward());
                //Set move speed
                EntityCommandBuffer.SetComponent(index, new MoveSpeed {
                    Speed = Weapons[index].FireSpeed
                });
            }
Exemple #17
0
            public void Execute(int index)
            {
                ToSpawn.BeginForEachIndex(index);
                var n = ToSpawn.RemainingItemCount;

                for (var i = 0; i < n; ++i)
                {
                    var data   = ToSpawn.Read <JobEntityProxy>();
                    var entity = Buffer.CreateEntity(index, Job);
                    Buffer.SetComponent(index, entity, data.id);
                    Buffer.SetComponent(index, entity, data.created);
                    Buffer.SetComponent(index, entity, data.origin);
                    Buffer.SetComponent(index, entity, data.destination);
                    Buffer.SetComponent(index, entity, data.costFunction);
                    Buffer.SetSharedComponent(index, entity, data.hub);
                }
                ToSpawn.EndForEachIndex();
            }
    public void Execute(int index)
    {
        commandBuffer.CreateEntity(index, playfieldCellArchetype);
        commandBuffer.SetComponent(index, new Scale {
            Value = new float3(1.0f, 1.0f, 1.0f)
        });

        playfieldIndex.TryGetValue(positions[index].position.x, out int playfield);

        commandBuffer.SetComponent(index, new Position { // should consider the playfield origin, spacing between grid tiles, etc
            Value = new float3(positions[index].position.x, positions[index].position.y, positions[index].position.z),
        });

        commandBuffer.SetComponent(index, new PlayfieldCell {
            playfieldPosition = new int4(positions[index].position.x, positions[index].position.y, positions[index].position.z, playfield)
        });

        commandBuffer.SetSharedComponent(index, playfieldArray[playfield].look);
    }
 private void spawn_internal(EntityCommandBuffer.Concurrent entity_command_buffer,
                             float time,
                             ref float3 pos,
                             ref float3 vel,
                             Material mat,
                             EntityArchetype arche_type)
 {
     entity_command_buffer.CreateEntity(arche_type);
     entity_command_buffer.SetComponent(new Position {
         Value = pos,
     });
     entity_command_buffer.SetComponent(new Rotation {
         Value = quaternion.lookRotation(vel, new float3(0f, 1f, 0f)),
     });
     entity_command_buffer.SetComponent(new RigidbodyPosition {
         velocity_ = vel,
     });
     entity_command_buffer.SetComponent(new SphereCollider {
         offset_position_ = new float3(0f, 0f, 0f),
         radius_          = 0.5f,
     });
     entity_command_buffer.SetComponent(new SphereCollider {
         radius_ = 1f,
     });
     entity_command_buffer.SetComponent(new AlivePeriod {
         start_time_ = time, period_ = 3f,
     });
     entity_command_buffer.SetComponent(new MeshRenderBounds {
         Center = new float3(0f, 0f, 0f), Radius = 0.01f,
     });
     entity_command_buffer.SetSharedComponent(new MeshInstanceRenderer {
         mesh           = mesh_,
         material       = mat,
         castShadows    = UnityEngine.Rendering.ShadowCastingMode.Off,
         receiveShadows = false,
     });
 }
 public void SetSharedComponent <T>(T component) where T : struct, ISharedComponentData
 {
     _ecb.SetSharedComponent(_jobIndex, _entity, component);
 }
Exemple #21
0
 public void Execute(int index)
 {
     CommandBuffer.SetSharedComponent(Entities[index], new SharedByteState {
         State = States[index]
     });
 }