private void GeneratePresetLevelCave() { var levelObj = new GameObject("Level").transform; var caveParent = new GameObject("Caves"); _caveBody = caveParent.AddComponent <Rigidbody2D>(); _caveBody.isKinematic = true; caveParent.transform.SetParent(levelObj); for (int i = 0; i < _levelCaveList.Length; i++) { LevelContainer.CaveType cave = _levelCaveList[i]; GameObject caveTop; // TODO should probably build a factory for this if (cave.TopIndex == Toolbox.CaveStartIndex) { caveTop = (GameObject)Instantiate(Resources.Load("Caves/CaveEntrance"), caveParent.transform); caveTop.name = "CaveEntrance"; } else if (cave.TopIndex == Toolbox.CaveEndIndex) { caveTop = (GameObject)Instantiate(Resources.Load("Caves/CaveExit"), caveParent.transform); caveTop.name = "CaveExit"; } else if (cave.TopIndex == Toolbox.CaveGnomeEndIndex) { _bGnomeEnd = true; caveTop = (GameObject)Instantiate(Resources.Load("Caves/CaveGnomeEnd"), caveParent.transform); caveTop.name = "CaveGnomeEnd"; } else { string caveBottomName = "CaveBottom" + (cave.bBottomSecretPath ? "Exit" : "") + (cave.BottomIndex + 1); string caveTopName = "CaveTop" + (cave.bTopSecretPath ? "Exit" : "") + (cave.TopIndex + 1); GameObject caveBottom = (GameObject)Instantiate(Resources.Load("Caves/" + caveBottomName), caveParent.transform); caveTop = (GameObject)Instantiate(Resources.Load("Caves/" + caveTopName), caveParent.transform); caveBottom.name = caveBottomName; caveTop.name = caveTopName; caveBottom.transform.position = new Vector3(_tileSizeX * i, 0f, _caveZ); } caveTop.transform.position = new Vector3(_tileSizeX * i, 0f, _caveZ); } }
private void SetLevelObjects() { if (_levelObj == null) { Debug.Log("Lost level"); _levelObj = new GameObject("Level"); } GameObject stals = new GameObject("Stalactites"); GameObject shrooms = new GameObject("Mushrooms"); GameObject moths = new GameObject("Moths"); GameObject spiders = new GameObject("Spiders"); GameObject webs = new GameObject("Webs"); GameObject triggers = new GameObject("Triggers"); GameObject caves = _caveParent.gameObject; _mothParent = moths.transform; _stalParent = stals.transform; _shroomParent = shrooms.transform; _webParent = webs.transform; _spiderParent = spiders.transform; _triggerParent = triggers.transform; _npcParent = new GameObject("Npcs").transform; _stalParent.SetParent(_levelObj.transform); _shroomParent.SetParent(_levelObj.transform); _mothParent.SetParent(_levelObj.transform); _spiderParent.SetParent(_levelObj.transform); _webParent.SetParent(_levelObj.transform); _triggerParent.SetParent(_levelObj.transform); _npcParent.SetParent(_levelObj.transform); //GameObject Clumsy = (GameObject)Instantiate(Resources.Load("ClumsyLevelEditor"), _levelObj.transform); //Clumsy.name = "Clumsy"; //Clumsy.transform.position = new Vector3(Level.Clumsy.Pos.x, Level.Clumsy.Pos.y, _clumsyZ); //Clumsy.transform.localRotation = Level.Clumsy.Rotation; //Clumsy.transform.localScale = Level.Clumsy.Scale; for (int i = 0; i < Level.Caves.Length; i++) { LevelContainer.CaveType cave = Level.Caves[i]; GameObject caveTop; if (cave.TopIndex == Toolbox.CaveStartIndex) { caveTop = (GameObject)Instantiate(Resources.Load("Caves/CaveEntrance"), caves.transform); caveTop.name = "CaveEntrance"; } else if (cave.TopIndex == Toolbox.CaveEndIndex) { caveTop = (GameObject)Instantiate(Resources.Load("Caves/CaveExit"), caves.transform); caveTop.name = "CaveExit"; } else if (cave.TopIndex == Toolbox.CaveGnomeEndIndex) { caveTop = (GameObject)Instantiate(Resources.Load("Caves/CaveGnomeEnd"), caves.transform); caveTop.name = "CaveGnomeEnd"; } else { string caveBottomName = "CaveBottom" + (cave.bBottomSecretPath ? "Exit" : "") + (cave.BottomIndex + 1).ToString(); string caveTopName = "CaveTop" + (cave.bTopSecretPath ? "Exit" : "") + (cave.TopIndex + 1).ToString(); var caveBottom = (GameObject)Instantiate(Resources.Load("Caves/" + caveBottomName), caves.transform); caveTop = (GameObject)Instantiate(Resources.Load("Caves/" + caveTopName), caves.transform); caveBottom.name = caveBottomName; caveTop.name = caveTopName; caveBottom.transform.position = new Vector3(_tileSizeX * i, 0f, _caveZ); } caveTop.transform.position = new Vector3(_tileSizeX * i, 0f, _caveZ); SetStalactites(stals, cave.Stals, i); SetMushrooms(shrooms, cave.Shrooms, i); SetMoths(moths, cave.Moths, i); SetSpiders(spiders, cave.Spiders, i); SetWebs(webs, cave.Webs, i); SetTriggers(triggers, cave.Triggers, i); SetNpcs(cave.Npcs, i); } }