// Overloaded behavior required to load a scene (through LevelManager) correctly void OnLevelWasLoaded() { // Finish loading the level generation stuff LevelGen.ParseScene(); LevelManager_Scenery[] SceneryElements = LevelGen.GetScenery(); // All all content from level generator for(int i = 0; i < SceneryElements.Length; i++) if(SceneryElements[i].IsMineral) SceneManager.AddMineral(SceneryElements[i].Pos, SceneryElements[i].Radius, SceneryElements[i].MineralCount); // Load the queue of enemy spawn timings and groups EnemyGroups = new Queue<LevelManager_SpawnGroup>(LevelGen.GetSpawnList()); // Load the win state logic WinLogic = LevelGen.GetWinLogic(); // All loaded! LevelLoaded = true; }
// This function MUST be called once the level data, through the scene, has been loaded // It is essentially "MonoBehavior.OnLevelWasLoaded()" public void ParseScene() { // Alloc our lists as needed SceneryList = new List<LevelManager_Scenery>(); SpawnList = new Queue<LevelManager_SpawnGroup>(); // For each new LevelEntity.. UnityEngine.Object[] LevelEntities = GameObject.FindSceneObjectsOfType(typeof(LevelEntity)); foreach(UnityEngine.Object _Entity in LevelEntities) { // Cast over to LevelEntity type LevelEntity Entity = _Entity as LevelEntity; Vector2 EntityPos = new Vector2(Entity.transform.position.x, Entity.transform.position.y); // If mineral... if(Entity.EntityType == 0) { // Change the depth of the mineral Entity.transform.position = new Vector3(Entity.transform.position.x, Entity.transform.position.y, Globals.MineralsDepth); // Create the internal mineral object LevelManager_Scenery Scenery = new LevelManager_Scenery(); Scenery.IsMineral = true; Scenery.Pos = new Vector2(Entity.transform.position.x, Entity.transform.position.y); Scenery.Radius = (Entity.transform.localScale.x + Entity.transform.localScale.y) / 8.0f; Scenery.MineralCount = Entity.MineralCount; SceneryList.Add(Scenery); } // If junk... else if(Entity.EntityType == 1) { // Do nothing, let Unity3D manage our junk scenery Entity.transform.position = new Vector3(Entity.transform.position.x, Entity.transform.position.y, Globals.JunkDepth); } // If enemy... else if(Entity.EntityType == 2) { // Randomize the unit composition LevelManager_SpawnGroup Group = new LevelManager_SpawnGroup(); Group.SpawnTime = Entity.EnemySpawnTime; Group.SpawnPos = EntityPos; Group.Class0Count = Entity.EnemyType0Count; Group.Class1Count = Entity.EnemyType1Count; Group.Class2Count = Entity.EnemyType2Count; // Add to queue SpawnList.Enqueue(Group); } // If text event... else if(Entity.EntityType == 3) { // Todo... } // If win condition... else if(Entity.EntityType == 4) { // Check for duplicate... if(WinLogic != null) Debug.LogError("Duplicate win-logic entity defined in same scene!"); WinLogic = new LevelManager_WinningState(); WinLogic.IfWinTime = Entity.IfWinTime; WinLogic.WinTime = Entity.WinTime; WinLogic.IfWinKillAll = Entity.IfWinKillAll; WinLogic.IfWinResources = Entity.IfWinResources; } } }