SpawnEntity[] EditSpawnEntityArray(SpawnEntity[] spawnEntityArray, string[] SpawnDataNameArray) { if(GUILayout.Button("Add SpawnEntity")) { spawnEntityArray = Util.AddToArray<SpawnEntity>(new SpawnEntity(), spawnEntityArray); } for(int i=0; i<spawnEntityArray.Length; i++) { EditorGUILayout.LabelField("------------------------ SpawnEntity:" + spawnEntityArray[i].Name); spawnEntityArray[i].Name = EditorGUILayout.TextField("Name:",spawnEntityArray[i].Name); spawnEntityArray[i].SpawnDataNameArray = EditorCommon.EditStringArray("Use these spawn data:", spawnEntityArray[i].SpawnDataNameArray, SpawnDataNameArray); spawnEntityArray[i].WaitForSpawnedDieOut = EditorGUILayout.Toggle(new GUIContent("Wait for spawned unit die out to spawn next:",""), spawnEntityArray[i].WaitForSpawnedDieOut); if(spawnEntityArray[i].WaitForSpawnedDieOut == false) { spawnEntityArray[i].WaitTime = EditorGUILayout.FloatField(new GUIContent("Wait time to spawn next:",""),spawnEntityArray[i].WaitTime); } if(GUILayout.Button("Remove this SpawnEntity")) { spawnEntityArray = Util.CloneExcept<SpawnEntity>(spawnEntityArray, spawnEntityArray[i]); } EditorGUILayout.Space(); } return spawnEntityArray; }
IEnumerator DoSpawn() { foreach (SpawnEntity spawnEntity in this.spawnEntityArray) { CurrentSpawnEntity = spawnEntity; // if(spawnEntity.SpawnDelay > 0) // { // yield return new WaitForSeconds(spawnEntity.SpawnDelay); // } foreach (string spawnDataName in spawnEntity.SpawnDataNameArray) { SpawnData spawnData = spawnDict [spawnDataName]; GameObject spawnedUnit = Spawn(spawnDict [spawnDataName]); spawnEntity.AddSpawned(spawnedUnit); } if (spawnEntity.WaitForSpawnedDieOut) { //when all spawned unit dies, turn to next SpawnEntity while (spawnEntity.IsSpawnedDieOut() == false) { yield return(new WaitForSeconds(0.3333f)); } } else { yield return(new WaitForSeconds(spawnEntity.WaitTime)); } Debug.Log("SpawnEntity:" + spawnEntity.Name + " has die out!"); } //all entity has completed spawning, if there're events for spawning complete, fire the events. if (Event_At_All_Spawned_Complete != null && Event_At_All_Spawned_Complete.Length > 0) { foreach (GameEvent e in Event_At_All_Spawned_Complete) { LevelManager.OnGameEvent(e, this); } } //if there're evented for spawn die out, while until all unit die out then fire the event if (this.Event_At_All_Spawned_DieOut != null && this.Event_At_All_Spawned_DieOut.Length > 0) { //wait for all spawn eneity die oout while (true) { if (this.spawnEntityArray.Count(x => x.IsSpawnedDieOut() == false) > 0) { yield return(new WaitForSeconds(0.33333f)); } else { break; } } foreach (GameEvent e in Event_At_All_Spawned_DieOut) { LevelManager.OnGameEvent(e, this); } } }
async Task IHandle <SpawnEntity> .Handle(SpawnEntity message) { var pos = message.Position; var bb = BoundingBox.Item(); var box = new Cuboid(new Point3d(pos.X, pos.Z, pos.Y), new Size(bb.X, bb.Y, bb.Z)); await AttachedObject.SetLocalValue(ColliderComponent.ColliderShapeProperty, box); CompleteSpawn(); }
async Task IHandle <SpawnEntity> .Handle(SpawnEntity message) { var pos = message.Position; var bb = BoundingBox.Item(); var box = new Cuboid(new Point3d(pos.X, pos.Z, pos.Y), new Size(bb.X, bb.Y, bb.Z)); await AttachedObject.SetLocalValue(ColliderComponent.ColliderShapeProperty, box); Logger.LogInformation($"Pickup spawn, key: {AttachedObject.GetAddressByPartitionKey()}"); }
public void Pause() { m_running = false; for (int i = m_active.Count - 1; i >= 0; --i) { SpawnEntity current = m_active[i]; current.Pause(); } }
Task IHandle <SpawnEntity> .Handle(SpawnEntity message) { AttachedObject.GetComponent <WorldComponent>().SetWorld(message.World); AttachedObject.GetComponent <EntityWorldPositionComponent>().SetPosition(message.Position); var lookComponent = AttachedObject.GetComponent <EntityLookComponent>(); lookComponent.SetPitch(message.Pitch); lookComponent.SetYaw(message.Yaw); return(Task.CompletedTask); }
async Task IHandle <SpawnEntity> .Handle(SpawnEntity message) { await AttachedObject.GetComponent <WorldComponent>().SetWorld(message.World); await AttachedObject.GetComponent <EntityWorldPositionComponent>().SetPosition(message.Position); var lookComponent = AttachedObject.GetComponent <EntityLookComponent>(); await lookComponent.SetPitch(message.Pitch); await lookComponent.SetYaw(message.Yaw); }
void Start() { m_camera = Camera.main; for (int i = 0; i < m_entityPrefabs.Count; ++i) { SpawnEntity entity = GameObject.Instantiate <SpawnEntity>(m_entityPrefabs[i]); entity.transform.SetParent(transform); m_available.Add(entity); } }
void OnTriggerEnter2D(Collider2D other) { if (m_alive && PlayerScoreEvent != null) { SpawnEntity entity = other.GetComponentInParent <SpawnEntity>(); if (entity != null) { PlayerScoreEvent(entity.GetPoints()); } } }
public void Stop() { m_running = false; while (m_active.Count > 0) { SpawnEntity current = m_active[0]; current.Stop(); m_active.RemoveAt(0); m_available.Add(current); } }
void UpdateEntities() { for (int i = m_active.Count - 1; i >= 0; --i) { SpawnEntity current = m_active[i]; if (current.IsFinished(m_camera)) { current.Stop(); m_active.RemoveAt(i); m_available.Add(current); continue; } } }
void SpawnEntities() { if (m_available.Count <= 0 || Time.time < m_lastSpawnTime + m_spawnFrequency) { return; } int selected = Random.Range(0, m_available.Count); SpawnEntity current = m_available[selected]; m_available.Remove(current); m_active.Add(current); current.Run(m_camera); m_lastSpawnTime = Time.time; }
IEnumerator DoSpawn() { foreach (SpawnEntity spawnEntity in this.spawnEntityArray) { CurrentSpawnEntity = spawnEntity; // if(spawnEntity.SpawnDelay > 0) // { // yield return new WaitForSeconds(spawnEntity.SpawnDelay); // } foreach (string spawnDataName in spawnEntity.SpawnDataNameArray) { SpawnData spawnData = spawnDict [spawnDataName]; GameObject spawnedUnit = Spawn (spawnDict [spawnDataName]); spawnEntity.AddSpawned (spawnedUnit); } if (spawnEntity.WaitForSpawnedDieOut) { //when all spawned unit dies, turn to next SpawnEntity while (spawnEntity.IsSpawnedDieOut() == false) { yield return new WaitForSeconds(0.3333f); } } else { yield return new WaitForSeconds(spawnEntity.WaitTime); } Debug.Log ("SpawnEntity:" + spawnEntity.Name + " has die out!"); } //all entity has completed spawning, if there're events for spawning complete, fire the events. if(Event_At_All_Spawned_Complete != null && Event_At_All_Spawned_Complete.Length > 0){ foreach (GameEvent e in Event_At_All_Spawned_Complete) { LevelManager.OnGameEvent (e, this); } } //if there're evented for spawn die out, while until all unit die out then fire the event if(this.Event_At_All_Spawned_DieOut != null && this.Event_At_All_Spawned_DieOut.Length > 0) { //wait for all spawn eneity die oout while(true) { if(this.spawnEntityArray.Count(x=>x.IsSpawnedDieOut() == false) > 0) { yield return new WaitForSeconds(0.33333f); } else { break; } } foreach (GameEvent e in Event_At_All_Spawned_DieOut) { LevelManager.OnGameEvent (e, this); } } }
Task IHandle <SpawnEntity> .Handle(SpawnEntity message) { CompleteSpawn(); return(Task.CompletedTask); }