예제 #1
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        EntityCommandBuffer.Concurrent commandBuffer = m_EntityCommandBuffer.CreateCommandBuffer().ToConcurrent();

        JobHandle savePos = Entities.ForEach((Entity entity, int entityInQueryIndex, in Translation translation, in C_HoldComponentData holdData, in DirectionData directionData) =>
        {
            commandBuffer.SetComponent(entityInQueryIndex, holdData.Item, new C_SetPositionComponentData
            {
                Position = translation.Value,
            });
        }).Schedule(inputDeps);
        public static void PlayAnimForcedJobs(Entity entity, int index, EntityCommandBuffer.Concurrent entityCommandBuffer, ECS_UnitAnimType.TypeEnum ecsUnitAnimTypeEnum, UnitAnim.AnimDir animDir, Skeleton_Anim_OnComplete onComplete)
        {
            Skeleton_Data skeletonData = GetSkeletonData(ecsUnitAnimTypeEnum, animDir, onComplete);

            entityCommandBuffer.SetComponent(index, entity, skeletonData);

            if (skeletonData.frameRate <= 0)
            {
                Debug.LogError("#################### FRAMERATE ZERO!");
            }
        }
예제 #3
0
        public static Entity Instantiate(EntityCommandBuffer.Concurrent ecb, int jobIndex, float3 pos)
        {
            var entity = ecb.Instantiate(jobIndex, _prefabEntity);

            ecb.SetComponent(jobIndex, entity, new AlivePeriod {
                StartTime = (float)Time.GetCurrent(), Period = 1f,
            });

            var rot = quaternion.identity;
            var mat = new float4x4(rot, pos);

            mat.c0.w = Time.GetCurrent();
            var rotZ = _random.NextFloat() * math.PI * 2f;

            mat.c1.w = rotZ;
            ecb.SetComponent(jobIndex, entity, new ExplosionComponent {
                Matrix = mat,
            });
            return(entity);
        }
예제 #4
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var chunkProjectileEntityReference = chunk.GetNativeArray(ProjectileEntityReference);
            var chunkShootTrigger = chunk.GetNativeArray(ShootTrigger);
            var chunkLocalToWorld = chunk.GetNativeArray(LocalToWorld);

            for (var i = 0; i < chunk.Count; i++)
            {
                if (!chunkShootTrigger[i].Value)
                {
                    continue;
                }

                Entity projectile = InstantiateEntityAtLocalToWorld(chunkIndex, chunkProjectileEntityReference[i], chunkLocalToWorld[i]);
                EntityCommandBuffer.SetComponent(chunkIndex, projectile, new MovementDirection()
                {
                    Value = chunkLocalToWorld[i].Forward
                });
            }
        }
예제 #5
0
        public void Execute(Entity entity, int index, [ReadOnly] ref Translation translation, [ReadOnly] ref GridPosition gridPosition, ref T1 originComponent, [ReadOnly] ref T2 counterComponent)
        {
            originComponent.Value = originComponent.Value + counterComponent.Value * multiplier;

            bool shouldMorph = originComponent.Value <= 0;

            if (shouldMorph)
            {
                CommandBuffer.DestroyEntity(index, entity);

                Entity targetPrefab = spawner.GetEntityForType(targetEntityType);
                Entity newEntity    = CommandBuffer.Instantiate(index, targetPrefab);
                CommandBuffer.SetComponent(index, newEntity, new Translation {
                    Value = translation.Value
                });
                CommandBuffer.SetComponent(index, newEntity, new GridPosition {
                    Value = gridPosition.Value
                });
            }
        }
예제 #6
0
        private static void ApplyRandomPositionOnCircle(ref EntityCommandBuffer.Concurrent commandBuffer,
                                                        ref AroundCenterCyclicSpawner spawner, ref Random randomGenerator, int entityInQueryIndex,
                                                        Entity spawnedEntity)
        {
            float3      randomPosition = GetRandomPositionOnCircle(ref randomGenerator, spawner.SpawnDistance);
            Translation translation    = new Translation {
                Value = randomPosition
            };

            commandBuffer.SetComponent(entityInQueryIndex, spawnedEntity, translation);
        }
예제 #7
0
 public void Execute(Entity entity, int index, ref Translation translation, ref GridPosition gridPosition, [ReadOnly] ref Movable movable)
 {
     if (movable.direction == Direction.NONE)
     {
         //Entity is static
         return;
     }
     
     //Spawn follow juice
     Entity newJuiceEntity = CommandBuffer.Instantiate(index, spawner.prefabFollowJuice);
     int layer = Root.ConfigManager.LayersConfig.LayerForEntity(EntityType.FOLLOW_JUICE);
     int2 juiceGridPosition = gridPosition.Value;
     float3 juiceTranslation = GridConfig.PositionForCoordinates(juiceGridPosition.x, juiceGridPosition.y, layer);
     CommandBuffer.SetComponent(index, newJuiceEntity, new GridPosition { Value = juiceGridPosition, layer = layer});
     CommandBuffer.SetComponent(index, newJuiceEntity, new Translation() { Value = juiceTranslation});
     
     
     int2 offset = GridHelpers.DirectionToInt2(movable.direction);
     //Wrap around the grid
     int wrappedX = gridPosition.Value.x + offset.x;
     int wrappedY = gridPosition.Value.y + offset.y;
     if (gridPosition.Value.x < 0)
     {
         wrappedX = GridConfig.width - 1;
     }
     else if (GridConfig.width <= gridPosition.Value.x)
     {
         wrappedX = 0;
     } 
     else if (gridPosition.Value.y < 0)
     {
         wrappedY = GridConfig.height - 1;
     }
     else if (GridConfig.height <= gridPosition.Value.y)
     {
         wrappedY = 0;
     } 
     
     gridPosition.Value = new int2(wrappedX, wrappedY);
     translation.Value = GridConfig.PositionForCoordinates(wrappedX, wrappedY, gridPosition.layer);
 }
예제 #8
0
        private void DoSpawn(int index, float3 translation, quaternion rotation, ref Entity entityType, int direction, float speed, bool isCat)
        {
            var instance = CommandBuffer.Instantiate(index, entityType);

            CommandBuffer.SetComponent(index, instance, new Translation {
                Value = translation
            });
            CommandBuffer.SetComponent(index, instance, new Rotation {
                Value = rotation
            });

            CommandBuffer.AddComponent <LbRotationSpeed>(index, instance);
            CommandBuffer.AddComponent(index, instance, new LbMovementSpeed {
                Value = speed
            });
            CommandBuffer.AddComponent(index, instance, new LbMovementTarget()
            {
                From = translation, To = translation
            });
            CommandBuffer.AddComponent(index, instance, new LbDistanceToTarget {
                Value = 1.0f
            });

            CommandBuffer.AddComponent(index, instance, new LbDirection()
            {
                Value = (byte)direction
            });

            if (isCat)
            {
                CommandBuffer.AddComponent <LbCat>(index, instance);
                CommandBuffer.AddComponent(index, instance, new LbLifetime()
                {
                    Value = 30.0f
                });
            }
            else
            {
                CommandBuffer.AddComponent <LbRat>(index, instance);
            }
        }
        public static Entity Instantiate(EntityCommandBuffer.Concurrent ecb, int jobIndex, float3 pos, Entity prefab, float time)
        {
            var entity = ecb.Instantiate(jobIndex, prefab);

            ecb.SetComponent(jobIndex, entity, new AlivePeriod {
                StartTime = time, Period = 1f,
            });

            var rot = quaternion.identity;
            var mat = new float4x4(rot, pos);

            mat.c0.w = time;
            var random = new Random((uint)pos.GetHashCode());
            var rotZ   = random.NextFloat() * math.PI * 2f;

            mat.c1.w = rotZ;
            ecb.SetComponent(jobIndex, entity, new ExplosionComponent {
                Matrix = mat,
            });
            return(entity);
        }
예제 #10
0
        public void Execute(Entity entity, int index, ref Spawner spawner, [ReadOnly] ref LocalToWorld localToWorld)
        {
            Entity instance = entityCommandBuffer.Instantiate(index, spawner.prefab);

            entityCommandBuffer.SetComponent(index, instance, new Translation
            {
                Value = new unityMath.float3(
                    random.NextFloat(-spawner.randomRange, spawner.randomRange),
                    1,
                    random.NextFloat(-spawner.randomRange, spawner.randomRange))
            });
        }
예제 #11
0
        public void Execute(Entity e, int jobIndex, [ReadOnly] ref Translation translation, [ReadOnly] ref LauncherComponent launcher, [ReadOnly] ref QuadrantEntityComponent quadData)
        {
            //detect if on cooldown
            if (CooldownData.Exists(e))
            {
                return;
            }
            // if not on cooldown, spawn a projectile in a random forward direction (velocity component assignment)
            // x and y values are allowed to be slightly random for the velocity direction
            Entity projectile = CommandBuffer.Instantiate(jobIndex, launcher.projectileEntity);

            CommandBuffer.SetComponent(jobIndex, projectile, new Translation {
                Value = translation.Value
            });
            CommandBuffer.SetComponent(jobIndex, projectile, new VelocityComponent {
                Value = new float3(Randomizer.NextFloat(-1.5f, 1.5f), Randomizer.NextFloat(0.25f, 0.8f), Randomizer.NextFloat(3f, 6f)) * (quadData.type == QuadEntityType.Archer ? 15f : 23f)
            });
            CommandBuffer.AddComponent(jobIndex, e, new CooldownComponent {
                waitTime = Randomizer.NextFloat(0.5f, 2f)
            });
        }
예제 #12
0
            public void Execute(Entity entity, int index, ref BoundingVolume vol, ref HealthModifier healthMod)
            {
                if (vol.volume.Intersects(playerBounds))
                {
                    // there was a collision, modify the player's health
                    Utils.ModifyHealth(ref playerHealth, healthMod.value);
                    commandBuffer.SetComponent <Health>(index, player, playerHealth);

                    // get rid of the damager
                    commandBuffer.DestroyEntity(index, entity);
                }
            }
예제 #13
0
        public void Execute(Entity entity, int index, ref SphereSpawner sphereSpawner)
        {
            sphereSpawner.SecondsUntilSpawn -= deltaTime;
            if (0 < sphereSpawner.SecondsUntilSpawn)
            {
                return;
            }

            sphereSpawner.SecondsUntilSpawn = sphereSpawner.Delay;

            Entity icosphereEntity = ecb.Instantiate(index, sphereSpawner.Prefab);
            var    position        = new float3(0, positionY, 0);

            ecb.SetComponent(index, icosphereEntity, new Translation {
                Value = position
            });
            ecb.SetComponent(index, icosphereEntity, new MaterialId {
                currentMaterialId = materialType
            });
            ecb.AddComponent <UpdateMaterialTag>(index, icosphereEntity);
        }
예제 #14
0
        public void Execute(Entity entity, int index, ref Spawner_FromEntity spawnerData, ref LocalToWorld location)
        {
            if (spawnerData.time <= 0)
            {
                spawnerData.time = 5;
                Debug.Log("创建一个cube");
                var instance = commandBuffer.Instantiate(index, spawnerData.Prefab);
                commandBuffer.SetComponent(index, instance, new Translation {
                    Value = position
                });
                commandBuffer.SetComponent <Spawner_FromEntity>(index, instance, new Spawner_FromEntity {
                    time = 5, Prefab = spawnerData.Prefab
                });
            }
            else
            {
                spawnerData.time -= delatime;
            }

            //commandBuffer.DestroyEntity(index, entity);
        }
예제 #15
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var chunkEntities    = chunk.GetNativeArray(EntityType);
                var chunkTranslation = chunk.GetNativeArray(TranslationType);
                var chunkTarget      = chunk.GetNativeArray(AttackTargetType);

                if (chunk.Has(MoveForwardType))
                {
                    for (int i = 0; i < chunk.Count; i++)
                    {
                        Entity target = chunkTarget[i].Target;
                        if (AllTranslation.Exists(target))
                        {
                            float3 targetPos = AllTranslation[target].Value;
                            CommandBuffer.SetComponent(chunkIndex, chunkEntities[i],
                                                       new MoveForwardComponent()
                            {
                                Target = GetStopPosition(chunkTranslation[i].Value, targetPos)
                            });
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < chunk.Count; i++)
                    {
                        Entity target = chunkTarget[i].Target;

                        if (AllTranslation.Exists(target))
                        {
                            float3 targetPos = AllTranslation[target].Value;
                            float3 delta     = chunkTranslation[i].Value - targetPos;
                            if (math.lengthsq(delta) > StoppingDistanceSquare)
                            {
                                CommandBuffer.AddComponent(chunkIndex, chunkEntities[i],
                                                           new MoveForwardComponent()
                                {
                                    Target = GetStopPosition(chunkTranslation[i].Value, targetPos)
                                });
                            }
                        }
                    }
                }

                if (chunk.Has(EnemyType))
                {
                    for (int i = 0; i < chunk.Count; i++)
                    {
                        CommandBuffer.RemoveComponent <FollowWaypointTag>(chunkIndex, chunkEntities[i]);
                        CommandBuffer.AddComponent(chunkIndex, chunkEntities[i], new InAttackRangeTag());
                    }
                }
            }
        public void Execute(int index)
        {
            //a Voice is hooked with a new AudioSource.
            CommandBuffer.AddComponent(PlayRequests[index].VoiceEntity, new RealVoice(PlayRequests[index].VoiceEntity, SourceHandles[index].SourceEntity));
            CommandBuffer.SetComponent(SourceHandles[index].SourceEntity, new AudioSourceHandle(SourceHandles[index].SourceEntity));

            //the vacant AudioSource is now claimed.
            CommandBuffer.AddComponent(SourceHandles[index].SourceEntity, new ClaimedByVoice(PlayRequests[index].VoiceEntity));

            //the voice entity is no longer requiring to obtain a voice.
            CommandBuffer.RemoveComponent <RealVoiceRequest>(PlayRequests[index].VoiceEntity);
        }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var Velocities   = chunk.GetNativeArray(VelocityType);
            var Translations = chunk.GetNativeArray(TranslationType);
            var Targets      = chunk.GetNativeArray(TargetType);
            var Entities     = chunk.GetNativeArray(EntityType);

            for (int i = 0; i < chunk.Count; ++i)
            {
                var Target = Targets[i];

                if (HeldType.Exists(Target.Value))
                {
                    ecb.RemoveComponent(chunkIndex, Entities[i], typeof(C_Target));
                    continue;
                }

                var translation = Translations[i];
                var velocity    = Velocities[i];

                var targetPos = TranslationData[Target.Value].Value;

                var delta           = targetPos - translation.Value;
                var distanceSquared = delta.x * delta.x + delta.y * delta.y + delta.z * delta.z;

                var grid = GridType[Target.Value];

                if (StackType[Target.Value].index < StackHeights[GridIndex(grid.x, grid.y)] - 1)
                {
                    //Not top of stack anymore.
                    ecb.RemoveComponent(chunkIndex, Entities[i], typeof(C_Target));
                    continue;
                }

                if (distanceSquared < GrabDistance * GrabDistance)
                {
                    C_Held held;
                    held.Holder = Entities[i];

                    Tag_IsHeld tag;
                    ecb.SetComponent(chunkIndex, Target.Value, held);
                    ecb.AddComponent(chunkIndex, Target.Value, tag);
                    ecb.RemoveComponent(chunkIndex, Entities[i], typeof(C_Target));
                    C_Holding hold;
                    hold.ent = Target.Value;
                    ecb.AddComponent(chunkIndex, Entities[i], hold);
                    continue;
                }

                velocity.Value += delta * (ChaseForce * dt / sqrt(distanceSquared));
                Velocities[i]   = velocity;
            }
        }
예제 #18
0
        public void Execute(int index)
        {
            var line = Lines[LineEntities[index]];

            line.Position        = BoundsArray[index].c0;
            line.BoundingBoxSize =
                BoundsArray[index].c1 +
                (LineProfiles.Exists(LineEntities[index])
                     ? LineProfiles[LineEntities[index]].Width * 2
                     : DefaultProfile.Width * 2);
            Ecb.SetComponent(index, LineEntities[index], line);
        }
예제 #19
0
 public void Execute(Entity entity, int index, ref Spawner spawner, [ReadOnly] ref LocalToWorld localToWorld)
 {
     spawner.nextSpawnTime -= deltaTime;
     if (spawner.nextSpawnTime <= 0)
     {
         spawner.nextSpawnTime += spawner.spawnDelay;
         Entity instance = entityCommandBuffer.Instantiate(index, spawner.prefab);
         entityCommandBuffer.SetComponent(index, instance, new Translation {
             Value = localToWorld.Position + random.NextFloat3Direction() * random.NextFloat() * spawner.maxDistanceFromSpawner
         });
     }
 }
예제 #20
0
            //Spawn prefabs then move their Transforms to Random position in the world
            public void Execute(Entity entity, int index, ref Spawner spawner, [ReadOnly] ref LocalToWorld local_to_world)
            {
                spawner.seconds_to_next_spawn -= delta_time;

                if (spawner.seconds_to_next_spawn >= 0) { return; }

                spawner.seconds_to_next_spawn += spawner.seconds_betweens_spawns;

                Entity instance = entity_command_buffer.Instantiate(index, spawner.prefab);

                entity_command_buffer.SetComponent(index, instance, new Translation { Value = local_to_world.Position + random.NextFloat3Direction() * random.NextFloat() * spawner.max_distance_from_spawner });
            }
예제 #21
0
        public void Execute(Entity entity, int index, ref SpawnerData spawnerData, [ReadOnly] ref LocalToWorld localToWorld)
        {
            spawnerData.secondsToNextSpawn -= deltaTime;
            if (spawnerData.secondsToNextSpawn <= 0)
            {
                if (destinations.Exists(entity))
                {
                    Entity instance = InstansiateEntity(index, ref spawnerData, ref localToWorld);
                    entityCommandBuffer.SetComponent(index, instance, destinations[entity]);
                }

                if (inputs.Exists(entity) && inputs[entity].IsFiring)
                {
                    Entity instance = InstansiateEntity(index, ref spawnerData, ref localToWorld);
                    entityCommandBuffer.AddComponent(index, instance, new ChangeDirectionData
                    {
                        newDirection = localToWorld.Forward
                    });
                }
            }
        }
            public void Execute(int index)
            {
                var    road   = Roads[index];
                Entity entity = default;
                DynamicBuffer <LaneVertex> laneVertices = default;

                if (SplitScheme == SplitScheme.Road)
                {
                    entity = CommandBuffer.CreateEntity(index, RoadLaneArchetype);
                    CommandBuffer.SetComponent(index, entity, new RoadLane {
                        Name = road.Name
                    });
                    laneVertices = CommandBuffer.AddBuffer <LaneVertex>(index, entity);
                }

                for (var geometryIdx = road.GeometryStartIndex; geometryIdx < road.GeometryStartIndex + road.GeometryCount; geometryIdx++)
                {
                    var geometry = Geometries[geometryIdx];
                    if (SplitScheme == SplitScheme.Geometry)
                    {
                        entity = CommandBuffer.CreateEntity(index, RoadLaneArchetype);
                        CommandBuffer.SetComponent(index, entity, new RoadLane {
                            Name = new NativeString512($"{road.Name} {geometry.geometryKind}")
                        });
                        laneVertices = CommandBuffer.AddBuffer <LaneVertex>(index, entity);
                    }
                    var samples = GeometrySampling.BuildSamplesFromGeometry(geometry, 3f);
                    foreach (var sample in samples)
                    {
                        // TODO: support elevation
                        //Samples use x/y coordinates. Translate to x/z planar Unity coordinates
                        laneVertices.Add(new LaneVertex
                        {
                            GeometryIndex = geometryIdx - road.GeometryStartIndex,
                            Position      = sample.pose.pos,
                            Orientation   = sample.pose.rot
                        });
                    }
                }
            }
예제 #23
0
    public void Execute(int index)
    {
        var updatedPowder = Simulate(powders[index], index);

        if (!powders[index].Same(updatedPowder))
        {
            cmdBuffer.SetComponent(entities[index], updatedPowder);
            positions[index] = new Position2D()
            {
                Value = PowderGame.CoordToWorld(powders[index].coord)
            };
        }
    }
예제 #24
0
#pragma warning restore 649

            public void Execute(int jobIndex)
            {
                var   rng         = ThreadRngs[_threadIndex];
                float blockHeight = rng.NextFloat(TerrainHeightMin, TerrainHeightMax);

                ThreadRngs[_threadIndex] = rng;
                int2   blockCoords   = new int2(jobIndex % TerrainSize.x, jobIndex / TerrainSize.x);
                int    blockIndex    = BlockCoordsToIndex(blockCoords, TerrainSize);
                float3 blockPosition = BlockCoordsToPosition(blockCoords, blockHeight, TerrainSize);
                Entity e             = CommandBuffer.Instantiate(jobIndex, BlockPrefab);

                // TODO(@cort): should store e in BlockEntities yet, but it won't be valid (=non-negative) until the command buffer is played back.
                CommandBuffer.SetComponent(jobIndex, e, new BlockPositionXZ {
                    Value = blockPosition.xz
                });
                CommandBuffer.SetComponent(jobIndex, e, new BlockIndex {
                    Value = blockIndex
                });
                CommandBuffer.SetComponent(jobIndex, e, new BlockHeight {
                    Value = blockHeight
                });
            }
예제 #25
0
        static Entity Instantiate(EntityCommandBuffer.Concurrent ecb, int jobIndex, Entity prefab, float3 pos, quaternion rot, float3 vel)
        {
            var entity = ecb.Instantiate(jobIndex, prefab);

            ecb.SetComponent(jobIndex, entity, new Translation {
                Value = pos,
            });
            ecb.SetComponent(jobIndex, entity, new Rotation {
                Value = rot,
            });
            ecb.SetComponent(jobIndex, entity, new PhysicsVelocity()
            {
                Linear = vel,
            });
            ecb.SetComponent(jobIndex, entity, new AlivePeriod {
                StartTime = (float)Time.GetCurrent(), Period = 2f,
            });
            ecb.SetComponent(jobIndex, entity, new CachedBeamMatrix {
                Matrix = new float4x4(rot, pos),
            });
            return(entity);
        }
        public void Execute(Entity entity, int index, [ReadOnly] ref Spawner_FromEntity spawnerFromEntity,
                            [ReadOnly] ref LocalToWorld location)
        {
            for (var x = 0; x < spawnerFromEntity.CountX; x++)
            {
                for (var y = 0; y < spawnerFromEntity.CountY; y++)
                {
                    var instance = CommandBuffer.Instantiate(index, spawnerFromEntity.Prefab);

                    var xPos     = noise.cnoise(new float2(y, x) * 0.21F) * 8;
                    var yPos     = noise.cnoise(new float2(x, y) * 0.21F) * 8;
                    var position = new float3(xPos, yPos, 0);
                    CommandBuffer.SetComponent(index, instance, new Translation {
                        Value = position
                    });
                    CommandBuffer.AddComponent(index, instance, default(TagObstacleComponent));
                    CommandBuffer.AddComponent(index, instance, new BoxColliderComponent(new float2(1, 2)));
                }
            }

            for (var x = 0; x < spawnerFromEntity.CountX; x++)
            {
                for (var y = 0; y < spawnerFromEntity.CountY; y++)
                {
                    var instance = CommandBuffer.Instantiate(index, spawnerFromEntity.Prefab);

                    var xPos     = noise.cnoise(new float2(y, x) * 0.21F) * 8;
                    var yPos     = noise.cnoise(new float2(x, y) * 0.21F) * 8;
                    var position = new float3(xPos, yPos, 0);
                    CommandBuffer.SetComponent(index, instance, new Translation {
                        Value = position
                    });
                    CommandBuffer.AddComponent(index, instance, default(TagAgentComponent));
                    CommandBuffer.AddComponent(index, instance, new BoxColliderComponent(new float2(2, 1)));
                }
            }

            CommandBuffer.DestroyEntity(index, entity);
        }
예제 #27
0
            public unsafe void Execute(Entity entity, int index, ref Translation position, ref Rotation rotation, ref Velocity velocity,
                                       ref ShipStateComponentData state, [ReadOnly] ref PlayerIdComponentData playerIdData)
            {
                var             input = inputFromEntity[entity];
                ShipCommandData inputData;

                if (!input.GetDataAtTick(currentTick, out inputData))
                {
                    inputData.shoot = 0;
                }

                state.State = inputData.thrust;

                if (inputData.left == 1)
                {
                    rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(-displacement * deltaTime)));
                }

                if (inputData.right == 1)
                {
                    rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(displacement * deltaTime)));
                }

                if (inputData.thrust == 1)
                {
                    float3 fwd = new float3(0, playerForce * deltaTime, 0);
                    velocity.Value += math.mul(rotation.Value, fwd).xy;
                }

                position.Value.xy += velocity.Value * deltaTime;

                if (state.WeaponCooldown > 0)
                {
                    --state.WeaponCooldown;
                }
                if (inputData.shoot != 0 && state.WeaponCooldown == 0)
                {
                    var e = commandBuffer.CreateEntity(index, bulletArchetype);

                    commandBuffer.SetComponent(index, e, position);
                    commandBuffer.SetComponent(index, e, rotation);

                    var vel = new Velocity
                    {
                        Value = math.mul(rotation.Value, new float3(0, bulletVelocity, 0)).xy
                    };

                    commandBuffer.SetComponent(index, e, new BulletAgeComponentData(1.5f));
                    commandBuffer.SetComponent(index, e, new PlayerIdComponentData()
                    {
                        PlayerId = playerIdData.PlayerId
                    });
                    commandBuffer.SetComponent(index, e, vel);
                    commandBuffer.SetComponent(index, e,
                                               new CollisionSphereComponentData(bulletRadius));

                    state.WeaponCooldown = k_CoolDownTicksCount;
                }
            }
예제 #28
0
        private void SetVelocity(int index)
        {
            float2 position = new float2(Positions[index].Value.x, Positions[index].Value.y);
            float2 target   = Targets[index].Value;

            VelocityData data = new VelocityData();

            data.Velocity = math.normalize(target - position);
            data.MaxSpeed = MaxSpeed;

            // Velocities[index] = data;
            EntityBuffer.SetComponent(index, EntityArray[index], data);
        }
        public Entity CreateBullet(int index, [ReadOnly] ref Translation position,
                                   [ReadOnly] ref Rotation rotation, Entity bullet, float angle)
        {
            Entity entity = commandBuffer.Instantiate(index, bullet);

            commandBuffer.SetComponent(index, entity,
                                       new Translation {
                Value = new float3(
                    position.Value.x,
                    position.Value.y,
                    bulletHeight)
            });
            commandBuffer.SetComponent(index, entity,
                                       new Rotation {
                Value = math.mul(
                    math.normalize(rotation.Value),
                    quaternion.AxisAngle(
                        math.forward(rotation.Value),
                        angle))
            });
            return(entity);
        }
예제 #30
0
            public void Execute(Entity entity, int index, [ReadOnly] ref PotionData potionData, ref StatData statData)
            {
                EntityCommandBuffer.RemoveComponent <ResolveCardInteractionData>(index, entity);
                EntityCommandBuffer.AddComponent(index, entity, new DirtyData());
                var e = EntityCommandBuffer.CreateEntity(index, HealPlayerArchetype);

                EntityCommandBuffer.SetComponent(index, e, new HealPlayerData
                {
                    Amount = statData.Value
                });

                EntityCommandBuffer.CreateEntity(index, PostResolveCardArchetype);
            }