protected override void OnUpdate() { Entities.WithAll <Shooter, ZoxID, Stats>().ForEach((Entity e, ref Shooter shooter, ref ZoxID zoxID, ref Stats stats) => { if (shooter.isShoot == 1) { shooter.isShoot = 0; //Debug.LogError("Pre Queueing Bullet in ShootCompleterSystem."); //ZoxID stats = World.EntityManager.GetComponentData<Stats>(e); BulletDatam bulletDatam = bulletSpawnSystem.meta[shooter.bulletMetaID]; float3 spawnPosition = shooter.shootPosition + math.mul(shooter.shootRotation, new float3(0, 0, 0.15f)); AudioManager.instance.PlaySound(bulletDatam.spawnSound, spawnPosition); if (bulletDatam.Value.betweenSpread == 0) { bulletSpawnSystem.QueueBullet( shooter.bulletMetaID, spawnPosition, shooter.shootRotation, zoxID.id, zoxID.clanID //shooter.attackDamage, //shooter.attackForce, ); } else { float betweenSpread = bulletDatam.Value.betweenSpread; float2 spreadAmount = bulletDatam.Value.spread; // new float2(15, 30); float2 max = spreadAmount / 2; float2 min = -max; float3 originalRotation = new Quaternion( shooter.shootRotation.value.x, shooter.shootRotation.value.y, shooter.shootRotation.value.z, shooter.shootRotation.value.w).eulerAngles; float3 tempRotation = originalRotation; for (float x = min.x; x <= max.x; x += betweenSpread) { tempRotation.x = (originalRotation.x + x) % 360; for (float y = min.y; y <= max.y; y += betweenSpread) { tempRotation.y = (originalRotation.y + y) % 360; bulletSpawnSystem.QueueBullet( shooter.bulletMetaID, shooter.shootPosition + math.mul(shooter.shootRotation, new float3(0, 0, 0.3f)), Quaternion.Euler(tempRotation), zoxID.id, zoxID.clanID); } } } } }); }
public void UseBullet(Entity entity, ref Bullet bullet) { World.EntityManager.AddComponentData(entity, new BulletShrink { id = World.EntityManager.GetComponentData <ZoxID>(entity).id, timeBorn = UnityEngine.Time.time, lifetime = UnityEngine.Random.Range(bullet.lifetime.x, bullet.lifetime.y) }); World.EntityManager.RemoveComponent <Bullet>(entity); World.EntityManager.RemoveComponent <Body>(entity); World.EntityManager.RemoveComponent <BodyForce>(entity); BulletDatam meta = bulletSpawnSystem.meta[bullet.metaID]; AudioManager.instance.PlaySound(meta.hitSound, World.EntityManager.GetComponentData <Translation>(entity).Value); }
void SpawnTurret(int spawnID, float3 initialPosition, int type, int summonerID) { // Set the default if (turretData[type] == null) { Debug.LogError("Data is null for turret"); return; } //spawnPosition = spawnPosition + new float3(0, -0.5f, 0); initialPosition -= new float3(0, 0.5f, 0); float3 basePosition = initialPosition + turretScale * (new float3(0, turretData[type].baseMesh.bounds.extents.y, 0)); float3 headPosition = basePosition + turretScale * (new float3(0, turretData[type].baseMesh.bounds.extents.y + turretData[type].headMesh.bounds.extents.y, 0)); TurretDatam datam = turretData[type]; TurretData data = datam.Value; BulletDatam bulletDatam = datam.bullet; quaternion spawnRotation = quaternion.identity; Entity entity = World.EntityManager.CreateEntity(turretArchtype); SetOrAddComponent(entity, new ZoxID { id = spawnID, clanID = summonerID }); //SetOrAddComponent(entity, Stats.GenerateBasicStats()); // Rendering SetOrAddComponent(entity, new Translation { Value = headPosition }); SetOrAddComponent(entity, new Rotation { Value = spawnRotation }); SetOrAddComponent(entity, new NonUniformScale { Value = new float3(turretScale, turretScale, turretScale) }); RenderMesh newRenderer = new RenderMesh { material = turretData[type].material, mesh = turretData[type].headMesh, castShadows = UnityEngine.Rendering.ShadowCastingMode.On, receiveShadows = true }; SetOrAddSharedComponent(entity, newRenderer); // Turret parts SetOrAddComponent(entity, new Shooter { attackDamage = data.attackDamage, attackForce = data.attackForce, bulletMetaID = bulletDatam.Value.id }); Unity.Mathematics.Random random = new Unity.Mathematics.Random(); random.InitState((uint)spawnID); SetOrAddComponent(entity, new Aimer { id = spawnID, uniqueness = spawnID, turnSpeed = data.turnSpeed, random = random, targetRotation = spawnRotation, originalPosition = headPosition, offsetZ = turretData[type].headMesh.bounds.extents.z }); //Debug.LogError("Turret offsetZ: " + turretData[type].headMesh.bounds.extents.z); SetOrAddComponent(entity, new Targeter { Value = data.seek }); // Turret Base Entity entityBase = World.EntityManager.CreateEntity(); World.EntityManager.AddComponentData(entityBase, new Translation { Value = basePosition }); World.EntityManager.AddComponentData(entityBase, new Rotation { }); World.EntityManager.AddComponentData(entityBase, new NonUniformScale { Value = new float3(turretScale, turretScale, turretScale) }); RenderMesh baseMesh = new RenderMesh { material = turretData[type].material, mesh = turretData[type].baseMesh, castShadows = UnityEngine.Rendering.ShadowCastingMode.On, receiveShadows = true }; World.EntityManager.AddSharedComponentData(entityBase, baseMesh); World.EntityManager.AddComponent <LocalToWorld>(entityBase); // add things! turrets.Add(spawnID, entity); bases.Add(spawnID, entityBase); statbarSystem.QueueBar(entity);//, 0.5f); AudioManager.instance.PlaySound(datam.spawnSound, basePosition); }