void SpawnEnemy() { var state = m_State.S[0]; var oldState = Random.state; Random.state = state.RandomState; float2 spawnPosition = ComputeSpawnLocation(); state.SpawnedEnemyCount++; PostUpdateCommands.CreateEntity(TwoStickBootstrap.BasicEnemyArchetype); PostUpdateCommands.SetComponent(new Position2D { Value = spawnPosition }); PostUpdateCommands.SetComponent(new Heading2D { Value = new float2(0.0f, -1.0f) }); PostUpdateCommands.SetComponent(default(Enemy)); PostUpdateCommands.SetComponent(new Health { Value = TwoStickBootstrap.Settings.enemyInitialHealth }); PostUpdateCommands.SetComponent(new EnemyShootState { Cooldown = 0.5f }); PostUpdateCommands.SetComponent(new MoveSpeed { speed = TwoStickBootstrap.Settings.enemySpeed }); PostUpdateCommands.AddSharedComponent(TwoStickBootstrap.EnemyLook); state.RandomState = Random.state; m_State.S[0] = state; Random.state = oldState; }
void SpawnEnemy() { var state = m_State.S[0]; var oldState = UnityEngine.Random.state; UnityEngine.Random.state = state.RandomState; float3 spawnPosition = ComputeSpawnLocation(); state.SpawnedEnemyCount++; PostUpdateCommands.CreateEntity(TwoStickBootstrap.BasicEnemyArchetype); PostUpdateCommands.SetComponent(new Position { Value = spawnPosition }); PostUpdateCommands.SetComponent(new Rotation { Value = quaternion.LookRotation(new float3(0.0f, 0.0f, -1.0f), math.up()) }); PostUpdateCommands.SetComponent(new Health { Value = TwoStickBootstrap.Settings.enemyInitialHealth }); PostUpdateCommands.SetComponent(new EnemyShootState { Cooldown = 0.5f }); PostUpdateCommands.SetComponent(new MoveSpeed { speed = TwoStickBootstrap.Settings.enemySpeed }); PostUpdateCommands.AddSharedComponent(TwoStickBootstrap.EnemyLook); state.RandomState = UnityEngine.Random.state; m_State.S[0] = state; UnityEngine.Random.state = oldState; }
void SpawnIsland() { var state = islandStateGroup.islandSpawnState[0]; PostUpdateCommands.CreateEntity(Bootstrap.islandArchetype); var spawnLocation = state.islandCount == 0 ? new float3(0f, -2.9392f, 0f) : state.lastPosition + GetSpawnLocation(); PostUpdateCommands.SetComponent(new Position() { Value = spawnLocation }); var randomScale = GetRandomScale(); PostUpdateCommands.SetComponent(new Scale() { Value = randomScale }); PostUpdateCommands.SetComponent(new Island()); PostUpdateCommands.AddSharedComponent(Bootstrap.islandLook); state.islandCount++; state.lastPosition = spawnLocation; state.lastSize = randomScale; islandStateGroup.islandSpawnState[0] = state; }
void SpawnEnemy() { var wave = m_WaveSpawnState.Wave[0]; var oldState = Random.state; Random.state = wave.RandomState; wave.SpawnedEnemyCount++; float3 spawnPosition = GetSpawnLocation(); spawnPosition += new float3(0.0f, 1.0f, 0.0f); var trs = Matrix4x4.TRS(spawnPosition, Quaternion.identity, Vector3.one); PostUpdateCommands.CreateEntity(Bootstrap.Enemy1Archetype); PostUpdateCommands.SetComponent(new TransformMatrix { Value = trs }); PostUpdateCommands.SetComponent(new Position { Value = spawnPosition }); PostUpdateCommands.SetComponent(new Rotation { Value = quaternion.identity }); PostUpdateCommands.SetComponent(new Enemy { Speed = 3.7f, Health = wave.SpawnedWaveCount * (wave.SpawnedWaveCount / 2) + 1 }); PostUpdateCommands.AddSharedComponent(Bootstrap.Enemy1BodyLook); wave.RandomState = Random.state; m_WaveSpawnState.Wave[0] = wave; Random.state = oldState; }
protected override void OnUpdate() { var customRendererEntityArray = _customRendererGroup.ToEntityArray(Allocator.TempJob); for (int i = 0; i < customRendererEntityArray.Length; i++) { var customRendererEntity = customRendererEntityArray[i]; var rootRendererData = EntityManager.GetComponentObject <RootRendererData>(customRendererEntity); var groupData = RegisterRendererInGroup(customRendererEntity); var rootRenderId = groupData.RootRenderId; rootRendererData.SetIndex(rootRenderId); PostUpdateCommands.AddSharedComponent(customRendererEntity, new RemoveRenderer { CustomRendererIndex = rootRenderId, }); PostUpdateCommands.SetComponent(customRendererEntity, new RendererRoot() { RenderEntityListId = rootRenderId, }); } customRendererEntityArray.Dispose(); }
// 敵の生成 void SpawnEnemy(ref EnemySpawnSystemData data, ref EnemySpawnSystemSettings spawnSettings) { ++data.SpawnedEnemyCount; var type = UnityEngine.Random.Range(0, spawnSettings.MaxBarrageType); var pos = spawnSettings.RandomArea(); PostUpdateCommands.CreateEntity(MainECS_Manager.CommonEnemyArchetype); PostUpdateCommands.SetComponent(new Position2D { Value = pos }); PostUpdateCommands.SetComponent(new EnemyData { }); PostUpdateCommands.AddSharedComponent(MainECS_Manager.EnemyLook); PostUpdateCommands.AddSharedComponent(MainECS_Manager.EnemyCollision); switch ((BarrageType)type) { case BarrageType.CircularBullet: { PostUpdateCommands.AddSharedComponent(MainECS_Manager.BarrageSettings_CircularBullet); } break; case BarrageType.DirectionBullet: { PostUpdateCommands.AddSharedComponent(MainECS_Manager.BarrageSettings_DirectionBullet); } break; } }
void SpawnFood() { var state = m_State.State[0]; var oldState = Random.state; Random.state = state.RandomState; float3 spawnPosition = ComputeSpawnLocation(); state.SpawnedFoodCount++; PostUpdateCommands.CreateEntity(SnakeBootstrap.FoodArchetype); PostUpdateCommands.SetComponent(new Position { Value = spawnPosition }); PostUpdateCommands.SetComponent(new Heading { Value = new float3(0.0f, 0f, -1.0f) }); PostUpdateCommands.SetComponent(new Health { Value = SnakeBootstrap.Settings.enemyInitialHealth }); PostUpdateCommands.SetComponent(new Food { type = FoodType.Normal, timeToLive = 15f }); PostUpdateCommands.AddSharedComponent(SnakeBootstrap.FoodLook); state.RandomState = Random.state; m_State.State[0] = state; Random.state = oldState; }
void SpawnOne() { SpawnerState state = _state.CurrentState[0]; float3 spawnPosition = GetRandomPosition(); state.CurrentCount++; Debug.Log($"spawn new enemy at {spawnPosition}"); PostUpdateCommands.CreateEntity(Bootloader.EnemyArchveType); PostUpdateCommands.SetComponent(new Position { Value = spawnPosition }); PostUpdateCommands.SetComponent(new Rotation { Value = quaternion.LookRotation(new float3(0.0f, 0.0f, -1.0f), math.up()) }); PostUpdateCommands.SetComponent(new MoveSpeed { Speed = GameSettings.ENEMY_SPEED }); PostUpdateCommands.SetComponent(new Health { Value = GameSettings.ENEMY_HP }); PostUpdateCommands.AddSharedComponent(Bootloader.EnemyPrefab); // PostUpdateCommands.AddSharedComponent(Bootloader.EnemyPrefab); _state.CurrentState[0] = state; }
protected override void OnUpdate() { Entities.WithNone <ViewState>().ForEach((Entity entity, ref Ship ship) => { ShipViewData shipViewData; if (m_AssetManager.ShipViewDataMap.TryGetValue(ship.ID, out shipViewData)) { RenderMesh renderMesh; if (!m_ShipRenderMeshMap.TryGetValue(ship.ID, out renderMesh)) { Debug.Log("New render mesh"); renderMesh = new RenderMesh() { castShadows = UnityEngine.Rendering.ShadowCastingMode.Off, layer = shipViewData.Mesh.sortingLayerID, material = shipViewData.Mesh.sharedMaterial, mesh = shipViewData.Filter.sharedMesh, receiveShadows = false, subMesh = shipViewData.Mesh.subMeshStartIndex }; m_ShipRenderMeshMap.Add(ship.ID, renderMesh); } PostUpdateCommands.AddSharedComponent(entity, renderMesh); PostUpdateCommands.AddComponent(entity, default(ViewState)); //var go = Object.Instantiate(shipViewData.ViewPrefab, m_ViewContainer, false); //go.name = $"Ship{ship.InstanceID}"; //var viewSync = go.AddComponent<ViewSync>(); //EntityManager.AddComponentObject(entity, viewSync); } }); }
protected override void OnUpdate() { for (int i = 0; i < _sourceGroup.Length; i++) { Entity entity = _sourceGroup.Entities[i]; AudioSource audioSource = _sourceGroup.Sources[i]; if (_audioClip.Exists(entity)) { audioSource.clip = AudioService.GetAudioClip(_audioClip[entity].ID); } if (_audioSpatialBlend.Exists(entity)) { audioSource.spatialBlend = _audioSpatialBlend[entity].Blend; } if (_audioLoop.Exists(entity)) { audioSource.loop = true; } else { audioSource.loop = false; } //... PostUpdateCommands.AddSharedComponent(entity, new ReadToPlay()); } }
private void SpawnBomb(int i, Entity bombEntity, BombSpawnRequest bombSpawn) { BombAsset bombAsset = BombariaBootstrap.BombManager.GetBombAsset(bombSpawn.Bomb.Type); PostUpdateCommands.RemoveComponent <BombSpawnRequest>(bombEntity); PostUpdateCommands.AddComponent( bombEntity, bombSpawn.Bomb); PostUpdateCommands.AddComponent( bombEntity, bombSpawn.Position); PostUpdateCommands.AddComponent( bombEntity, bombSpawn.Heading); PostUpdateCommands.AddComponent( bombEntity, new BombBlink(bombAsset.TimeBeforeIgnition)); PostUpdateCommands.AddComponent( bombEntity, default(TransformMatrix)); PostUpdateCommands.AddSharedComponent( bombEntity, bombAsset.IdleLook); }
void SpawnEnemy() { var state = m_State.EnemySpawnState[0]; var settings = AsteroidsArcadeBootstrap.Settings; var spawnData = ComputeSpawnLocationAndHeading(settings); var speed = GetRandom(AsteroidsArcadeBootstrap.Settings.enemyMinSpeed, AsteroidsArcadeBootstrap.Settings.enemyMaxSpeed); PostUpdateCommands.CreateEntity(AsteroidsArcadeBootstrap.EnemyAsteroidArchetype); PostUpdateCommands.SetComponent(new EnemySubdivide { Value = 2 }); PostUpdateCommands.SetComponent(new Position2D { Value = spawnData.pos }); PostUpdateCommands.SetComponent(new Health { Value = settings.enemyHealth }); PostUpdateCommands.SetComponent(new Heading2D { Value = spawnData.heading }); PostUpdateCommands.SetComponent(default(Enemy)); PostUpdateCommands.SetComponent(new MoveSpeed { speed = speed }); PostUpdateCommands.AddSharedComponent(AsteroidsArcadeBootstrap.EnemyAsteroidBigLook); m_State.EnemySpawnState[0] = state; }
protected override void OnUpdate() { Settings settings = Bootstrap.Settings; int quantityToSpawn = settings.FoodCount - m_Data.Length; for (int i = 0; i < quantityToSpawn; i++) { PostUpdateCommands.CreateEntity(Bootstrap.FoodArchetype); float possibleSize = settings.ArenaSize * 10 * 0.9f; PostUpdateCommands.SetComponent(new Position { Value = new float3( Random.Range(-possibleSize / 2.0f, possibleSize / 2.0f), Random.Range(-possibleSize / 2.0f, possibleSize / 2.0f), 0.0f ) }); PostUpdateCommands.SetComponent(new Scale { Value = new float3(1.0f, 1.0f, 1.0f) }); PostUpdateCommands.SetComponent(new Size { Value = settings.FoodSize }); PostUpdateCommands.SetComponent( new Scale { Value = new float3(settings.FoodSize, settings.FoodSize, settings.FoodSize) } ); PostUpdateCommands.AddSharedComponent(Bootstrap.FoodLook); } }
protected override void OnUpdate() { for (int i = 0; i < data.Length; ++i) { Entity spawnedEntity = data.Entities[i]; PizzaSpawnData spawnData = data.SpawnData[i]; PostUpdateCommands.RemoveComponent <PizzaSpawnData>(spawnedEntity); PostUpdateCommands.AddSharedComponent(spawnedEntity, spawnData.PizzaGroup); PostUpdateCommands.AddComponent(spawnedEntity, spawnData.Position); IngredientList ingredientList = new IngredientList { Value = generatePizzaIngredients() }; PostUpdateCommands.AddSharedComponent(spawnedEntity, ingredientList); PostUpdateCommands.AddComponent(spawnedEntity, new Pizza { }); PostUpdateCommands.AddComponent(spawnedEntity, new Heading2D { Value = new float2(0, -1) }); PostUpdateCommands.AddComponent(spawnedEntity, default(TransformMatrix)); PostUpdateCommands.AddSharedComponent(spawnedEntity, BootStrap.PizzaLook); PostUpdateCommands.AddComponent(spawnedEntity, getPizzaCost(ingredientList)); BootStrap.SetPizzaOrderUIIngredients(ingredientList.Value, spawnData.PizzaGroup.PizzaId); } }
protected override void OnUpdate() { EntityManager manager = World.Active.GetOrCreateManager <EntityManager>(); for (int turretIdx = 0; turretIdx < m_turretData.Length; ++turretIdx) { if (m_turretData.State[turretIdx].TimeSinceLastFire >= 1.0f && m_turretData.State[turretIdx].CanFire == 1) { ComponentTypes.TurretHeadState stateCopy = m_turretData.State[turretIdx]; Entity body = m_turretData.Parent[turretIdx].Value; Position bodyPosition = manager.GetComponentData <Position>(body); PostUpdateCommands.CreateEntity(Bootstrap.MissileArchetype); PostUpdateCommands.SetComponent(new Position { Value = new Vector3(bodyPosition.Value.x, bodyPosition.Value.y, bodyPosition.Value.z) + new Vector3(m_turretData.Positions[turretIdx].Value.x, m_turretData.Positions[turretIdx].Value.y, m_turretData.Positions[turretIdx].Value.z) }); PostUpdateCommands.SetComponent(new MoveSpeed { speed = 10.0f }); PostUpdateCommands.SetComponent(new Rotation { Value = Quaternion.Euler(0.0f, stateCopy.Angle, 0.0f) }); PostUpdateCommands.SetComponent(new ComponentTypes.MissileState { BirthTime = Time.time }); PostUpdateCommands.AddSharedComponent(Bootstrap.MissileLook); stateCopy.TimeSinceLastFire = 0.0f; m_turretData.State[turretIdx] = stateCopy; } } }
protected override void OnUpdate() { Entities.ForEach((Entity entity, ref AIRootInitializer initializer, ref AIRoot root, ref Address address) => { if (initializer.TreeId != root.TreeId) { PostUpdateCommands.RemoveComponent <AIRootInitializer>(entity); return; } var nodes = AIRootProxy.AINodePrototypes[root.TreeId]; root.TreeId = address.Id; foreach (EditorNode node in nodes) { node.UpdateParentId(nodes); } foreach (EditorNode node in nodes) { node.CreateEntity(PostUpdateCommands, address.Id); } PostUpdateCommands.RemoveComponent <AIRootInitializer>(entity); PostUpdateCommands.AddSharedComponent <TreeId>(entity, new TreeId { Id = root.TreeId }); }); }
protected override void OnUpdate() { for (int i = 0; i < tagGroup.Length; i++) { PostUpdateCommands.AddSharedComponent(tagGroup.entities[i], BootstrapperParticles.particleLook); PostUpdateCommands.RemoveComponent <NeedsMeshInstanceRendererTag>(tagGroup.entities[i]); } }
protected override void OnUpdate() { for (int i = 0; i < ingredientData.Length; i++) { PostUpdateCommands.RemoveComponent <IngredientJustSpawn>(ingredientData.entities[i]); PostUpdateCommands.AddSharedComponent(ingredientData.entities[i], GetIngredientLook(ingredientData.ingredients[i].IngredientType)); //PostUpdateCommands.AddSharedComponent(ingredientData.entities[i], BootStrap.IngredientDefaultLook); } }
protected override void OnUpdate() { float deltaTime = Time.deltaTime; for (int i = 0; i < this._group.Length; ++i) { var playerSettings = this._group.PlayerSettings[i]; var pos = this._group.Position[i].Value; var input = this._group.Input[i]; var movable = playerSettings.MovableAreaInstance; pos = new float2(MainECS_Manager.WorldMousePosision.x, MainECS_Manager.WorldMousePosision.z); if (pos.x <= movable.xMin) { pos.x = movable.xMin; } else if (pos.x > movable.xMax) { pos.x = movable.xMax; } if (pos.y <= movable.yMin) { pos.y = movable.yMin; } else if (pos.y > movable.yMax) { pos.y = movable.yMax; } var retPos = new Position2D { Value = pos }; if (input.Fire == 1) { input.FireCooldown = playerSettings.ShootSettingsInstance.FireCooldown; PostUpdateCommands.CreateEntity(MainECS_Manager.PlayerBulletArchetype); PostUpdateCommands.SetComponent(retPos); PostUpdateCommands.SetComponent( new BulletData { ShotSpeed = playerSettings.ShootSettingsInstance.ShotSpeed, // 上方向固定で発射 ShotAngle = 90, Lifespan = playerSettings.ShootSettingsInstance.Lifespan }); PostUpdateCommands.AddSharedComponent(MainECS_Manager.PlayerBulletLook); PostUpdateCommands.AddSharedComponent(MainECS_Manager.BulletCollision); } this._group.Position[i] = retPos; this._group.Input[i] = input; } }
private void HandleBlinking(int i, float dt, Entity bombEntity, Bomb bomb, BombBlink bombBlink, MeshInstanceRenderer bombLook) { BombAsset bombAsset = BombariaBootstrap.BombManager.GetBombAsset(bomb.Type); bombBlink.OverallTimer += dt; bombBlink.BlinkPeriodTimer += dt; if (bombBlink.OverallTimer < bombBlink.Duration025) { bombBlink.Period = bombBlink.Duration; } else if (bombBlink.OverallTimer >= bombBlink.Duration025 && bombBlink.OverallTimer < bombBlink.Duration05) { bombBlink.Period = bombBlink.DurationDiv4; } else if (bombBlink.OverallTimer >= bombBlink.Duration05 && bombBlink.OverallTimer < bombBlink.Duration075) { bombBlink.Period = bombBlink.DurationDiv8; } else if (bombBlink.OverallTimer >= bombBlink.Duration075 && bombBlink.OverallTimer < bombBlink.Duration) { bombBlink.Period = bombBlink.DurationDiv16; } else if (bombBlink.OverallTimer >= bombBlink.Duration) { return; } if (bombBlink.BlinkPeriodTimer >= bombBlink.Period) { bombBlink.BlinkPeriodTimer = 0; MeshInstanceRenderer newLook; if (bombLook.Equals(bombAsset.IdleLook)) { newLook = bombAsset.BlinkLook; } else if (bombLook.Equals(bombAsset.BlinkLook)) { newLook = bombAsset.IdleLook; } else { throw new System.Exception("Undefined blinking behavior occurred"); } PostUpdateCommands.RemoveComponent <MeshInstanceRenderer>(bombEntity); PostUpdateCommands.AddSharedComponent(bombEntity, newLook); } bombBlinkData.BombBlink[i] = bombBlink; }
protected override void OnUpdate() { float3 playerPosition = float3.zero; // initialization // player will always be found, he is never destroyed even upon death he is just marked as dead Entities.With(_playerQuery).ForEach((Entity entity, ref Translation translation) => playerPosition = translation.Value); Entities.With(_respawingQuery).ForEach((Entity entity, ref TimeToRespawnData timeToRespawn) => { timeToRespawn.Time -= Time.deltaTime; if (timeToRespawn.Time <= 0) { PostUpdateCommands.RemoveComponent(entity, typeof(TimeToRespawnData)); float3 spawnLocation = new float3(FindSpawningLocation(playerPosition), 3f); PostUpdateCommands.AddSharedComponent( entity, new RenderMesh { mesh = Instance.AsteroidMesh, material = Instance.AsteroidMaterial }); PostUpdateCommands.SetComponent(entity, new Translation { Value = spawnLocation }); PostUpdateCommands.SetComponent(entity, new Scale { Value = AsteroidScale }); PostUpdateCommands.SetComponent( entity, new MoveSpeedData { DirectionX = UnityEngine.Random.Range(-1f, 1f), DirectionY = UnityEngine.Random.Range(-1f, 1f), MoveSpeed = UnityEngine.Random.Range(0.05f, 0.2f), RotationSpeed = new float3( UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)) }); PostUpdateCommands.SetComponent(entity, new Rotation { Value = UnityEngine.Random.rotation }); } }); }
private void createNewPizza(int pizzaIndex) { PizzaGroup pizzaGroup = pizzaData.PizzaGroup[pizzaIndex]; Position2D pizzaPosition = pizzaData.Position[pizzaIndex]; PostUpdateCommands.CreateEntity(); PostUpdateCommands.AddSharedComponent(new PizzaSpawnData { PizzaGroup = pizzaGroup, Position = pizzaPosition }); }
private void handleIngredientHitPizza(int ingredientIndex, int pizzaIndex) { // Note: This component acts as state for if it's on the pizza. // Refactor. PostUpdateCommands.RemoveComponent <MoveSpeed>( ingredientData.entities[ingredientIndex]); PostUpdateCommands.RemoveComponent <TimedLife>( ingredientData.entities[ingredientIndex]); PostUpdateCommands.AddSharedComponent( ingredientData.entities[ingredientIndex], pizzaData.pizzaGroups[pizzaIndex]); PizzaCheckSystem.runPizzaCheck = true; }
// 敵の生成 void SpawnBullet(ref Position2D pos, ref BarrageSettings_CircularBullet settings) { for (int i = 0; i < settings.BulletCount; ++i) { PostUpdateCommands.CreateEntity(MainECS_Manager.EnemyBulletArchetype); PostUpdateCommands.SetComponent(pos); PostUpdateCommands.SetComponent( new BulletData { ShotSpeed = settings.CommonBarrageSettings.ShotSpeed, ShotAngle = (i / (float)settings.BulletCount) * 360f, Lifespan = settings.CommonBarrageSettings.Lifespan }); PostUpdateCommands.AddSharedComponent(MainECS_Manager.EnemyBulletLook); PostUpdateCommands.AddSharedComponent(MainECS_Manager.BulletCollision); } }
private void handlePizzaComplete(int pizzaIndex) { Entity pizzaEntity = pizzaData.Entities[pizzaIndex]; PizzaGroup pizzaGroup = pizzaData.PizzaGroup[pizzaIndex]; Position2D pizzaPosition = pizzaData.Position[pizzaIndex]; PizzaCost pizzaCost = pizzaData.PizzaCost[pizzaIndex]; // Pizza is done. Debug.Log("PIZZA DONE - " + pizzaGroup.PizzaId + ": " + pizzaCost.OrderCost + " | " + pizzaCost.ActualCost); // Update global score. PostUpdateCommands.CreateEntity(); PostUpdateCommands.AddComponent(new DeductScore { Value = pizzaCost.ActualCost }); PostUpdateCommands.AddSharedComponent(new ScoringGroup { GroupId = 0 }); // Delete this Pizza. MoveSpeed toWindow = new MoveSpeed { speed = BootStrap.GameSettings.ArrowSpeed }; TimedLife timedLife = new TimedLife { TimeToLive = 10.0f }; PostUpdateCommands.AddComponent(pizzaEntity, toWindow); PostUpdateCommands.AddComponent(pizzaEntity, timedLife); PostUpdateCommands.RemoveComponent <PizzaGroup>(pizzaEntity); // TODO: While ingredients are flying off with the pizza, arrows could hit them. for (int i = 0; i < IngredientData.CalculateLength(); i++) { Entity ingredientEntity = IngredientData.GetEntityArray()[i]; //PostUpdateCommands.AddComponent(ingredientEntity, toWindow); //PostUpdateCommands.AddComponent(ingredientEntity, timedLife); //PostUpdateCommands.RemoveComponent<PizzaGroup>(ingredientEntity); PostUpdateCommands.DestroyEntity(ingredientEntity); } // Create new Pizza. createNewPizza(pizzaIndex); }
// 敵の生成 void SpawnBullet(ref Position2D pos, ref BarrageSettings_DirectionBullet settings) { if (this._playerGroup.Position.Length <= 0) { return; } PostUpdateCommands.CreateEntity(MainECS_Manager.EnemyBulletArchetype); PostUpdateCommands.SetComponent(pos); PostUpdateCommands.SetComponent( new BulletData { ShotSpeed = settings.CommonBarrageSettings.ShotSpeed, ShotAngle = this.Aiming(pos.Value, this._playerGroup.Position[0].Value), Lifespan = settings.CommonBarrageSettings.Lifespan }); PostUpdateCommands.AddSharedComponent(MainECS_Manager.EnemyBulletLook); PostUpdateCommands.AddSharedComponent(MainECS_Manager.BulletCollision); }
void SpawnEnemy() { var state = m_State.S[0]; var oldState = Random.state; Random.state = state.RandomState; float2 spawnPosition = ComputeSpawnLocation(); float2 spawnHeading = ComputeSpawnHeading(); int spawnRank = ComputeRank(); state.SpawnedEnemyCount++; PostUpdateCommands.CreateEntity(AsteroidsBootstrap.BasicEnemyArchetype); PostUpdateCommands.SetComponent(new Position2D { Value = spawnPosition }); PostUpdateCommands.SetComponent(new Heading2D { Value = spawnHeading }); PostUpdateCommands.SetComponent(default(Enemy)); PostUpdateCommands.SetComponent(new EnemyRank { Value = spawnRank }); PostUpdateCommands.SetComponent(new Health { Value = 1.0f }); PostUpdateCommands.SetComponent(new MoveSpeed { speed = AsteroidsBootstrap.Settings.enemySpeed }); PostUpdateCommands.SetComponent(new EnemyShot()); PostUpdateCommands.SetComponent(new Shot { TimeToLive = 40f, Energy = 1.0f, }); PostUpdateCommands.AddSharedComponent(AsteroidsBootstrap.EnemyLook); state.RandomState = Random.state; m_State.S[0] = state; Random.state = oldState; }
protected override void OnUpdate() { Entities.ForEach((Entity e, EmitterProperties emitter, ref Spawner spawner, ref LocalToWorld localToWorld) => { var particleSpawnCount = spawner.particleCount; var spawnPositions = new NativeArray <float3>(particleSpawnCount, Allocator.TempJob); GeneratePoints.RandomPointsInUnitSphere(spawnPositions); // Calling Instantiate once per spawned Entity is rather slow, and not recommended // This code is placeholder until we add the ability to bulk-instantiate many entities from an ECB var entities = new NativeArray <Entity>(particleSpawnCount, Allocator.Temp); for (int i = 0; i < particleSpawnCount; ++i) { entities[i] = PostUpdateCommands.Instantiate(spawner.particlePrefab); } for (int i = 0; i < particleSpawnCount; i++) { PostUpdateCommands.SetComponent(entities[i], new LocalToWorld { Value = float4x4.TRS( localToWorld.Position + (spawnPositions[i] * spawner.spawnRadius), quaternion.LookRotationSafe(spawnPositions[i], math.up()), new float3(1.0f, 1.0f, 1.0f)) }); PostUpdateCommands.RemoveComponent <Translation>(entities[i]); PostUpdateCommands.RemoveComponent <Rotation>(entities[i]); PostUpdateCommands.AddSharedComponent(entities[i], emitter); } PostUpdateCommands.RemoveComponent <Spawner>(e); spawnPositions.Dispose(); entities.Dispose(); }); }
private void CreateChunk(int i) { var spiralChunkPosition = Common.SpiralChunkPosition(i); var meshData = new MeshData( TerrainSettings.Resolution, spiralChunkPosition, TerrainSettings.NoiseSettings ); var position = _data.Position[i]; position.Value = new float3(spiralChunkPosition.x, 0f, spiralChunkPosition.y); _data.Position[i] = position; PostUpdateCommands.AddSharedComponent(_data.EntityArray[i], new RenderMesh { mesh = CreateMesh(meshData), castShadows = _renderMesh.castShadows, material = _renderMesh.material, receiveShadows = _renderMesh.receiveShadows, subMesh = _renderMesh.subMesh }); }
protected override void OnUpdate() { for (int i = 0; i < Collisions.Length; ++i) { CollisionComponent data = Collisions.Data[i]; if (EntityManager.Exists(data.source) && !EntityManager.HasComponent <Destroy>(data.source) && EntityManager.HasComponent <Stats>(data.source) && EntityManager.Exists(data.target) && !EntityManager.HasComponent <Destroy>(data.target) && EntityManager.HasComponent <Stats>(data.target) && !EntityManager.HasComponent <Parent>(data.source) && !EntityManager.HasComponent <Parent>(data.target)) { Stats sourceStats = EntityManager.GetComponentData <Stats>(data.source); Stats targetStats = EntityManager.GetComponentData <Stats>(data.target); // Debug.Log("CAN MATE: " + canMate(sourceStats, targetStats)); if (canMate(sourceStats, targetStats)) { Net sourceNet = EntityManager.GetComponentObject <Net>(data.source); Net targetNet = EntityManager.GetComponentObject <Net>(data.target); // Debug.Log("WITH CHILD: " + data.source.Index); // Create a child PostUpdateCommands.AddSharedComponent <Embryo>(data.source, new Embryo { netdata = mate(sourceNet, targetNet).ToArray() }); // Update Parent (source pays the price) sourceStats.Health -= sourceStats.MatingCost; PostUpdateCommands.SetComponent <Stats>(data.source, sourceStats); PostUpdateCommands.AddComponent <Parent>(data.source, new Parent { CoolDown = sourceStats.MatingCoolDown }); } } } }