// public Dictionary <int, LevelChunk> createLevelChunks() { Dictionary <int, LevelChunk> chunks = new Dictionary <int, LevelChunk> (); int i; for (i = 0; i < _numLevels; ++i) { LevelStruct level = _levelByIndex [i]; GameObject gameObject = AssetFactory.Instance.createLevelContainerClone(); gameObject.name = "LevelChunk_" + level.id.ToString(); Vector3 chunkPos = new Vector3(level.x * Globals.LEVEL_WIDTH, -level.y * Globals.LEVEL_HEIGHT, level.z * Globals.LEVEL_DEPTH); gameObject.transform.position = chunkPos; LevelChunk chunk = gameObject.AddComponent <LevelChunk> (); chunk.init(chunkPos); chunk.setLevelData(level); chunks.Add(level.id, chunk); } return(chunks); }
void Awake() { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; _isInitialised = false; _levelChunks = new Dictionary <int, LevelChunk> (); _curLevelChunk = null; //gameObject.AddComponent<World> (); //_World = World.Instance; _aTextures = new List <Texture> (); _aMaterials = new List <Material> (); _aDictMaterials = new Dictionary <string, Material> (); int i, len = Globals.materials.Length; for (i = 0; i < len; ++i) { _aTextures.Add(Resources.Load <Texture> ("Textures/Cubes/" + Globals.materials [i])); _aMaterials.Add(Resources.Load <Material> ("Materials/Cubes/" + Globals.materials [i])); _aDictMaterials.Add(Globals.materials [i], _aMaterials[_aMaterials.Count - 1]); } _undoActions = new List <undoAction> (); _goCurProp = null; _selectedObjects = new List <GameObject> (); _activeCam = editCam; _nextDistanceUpdate = 0; _fRockSize = 0.5f; _cubesPerQuadrant = 2; _fQuadrantSize = (float)_cubesPerQuadrant * _fRockSize; // Instantiate app controller singleton if (GameObject.Find(Globals.appContainerName) == null) { GameObject goAppController = new GameObject(Globals.appContainerName); DontDestroyOnLoad(goAppController); goAppController.AddComponent <AppController> (); } if (GameObject.Find(Globals.netContainerName) == null) { GameObject goNetManager = new GameObject(Globals.netContainerName); DontDestroyOnLoad(goNetManager); goNetManager.AddComponent <NetManager> (); } }
// public void teleportToLevelWithId(int levelId) { if (_curLevelChunk != null) { _curLevelChunk.activate(false); } _curLevelChunk = _levelChunks [levelId]; _curLevelChunk.activate(true); FlyCam.Instance.setNewInitialPosition(_curLevelChunk.getStartPos(), _curLevelChunk.getStartRotation()); resetCamToStartPos(); checkLevelChunkDistances(); }
// public void initOfflineMode() { if (_isInitialised) { return; } PropsManager.Instance.init(); _curLevelChunk = LevelManager.Instance.createOfflineLevelChunk(); _curLevelChunk.createOfflineLevel(); _curLevelChunk.activate(true, true); _isInitialised = true; launch(); }
// public void createLevelChunkWithIndex(int levelId, int levelIndex) { _curLevelChunk = _levelChunks [levelId]; LevelManager.Instance.loadLevelByIndex(levelIndex); _curLevelChunk.activate(false, true); }
// private void createLevel(LevelFile levelFile) { if (levelFile.fileFormatVersion != Globals.levelSaveFormatVersion) { AppController.Instance.showPopup(PopupMode.Notification, "Warning", Globals.warningObsoleteFileFormat); return; } currentLevelId = levelFile.levelId; MainMenu.Instance.setLevelNameText(levelFile.levelName); lastLevelName = levelFile.levelName; LevelEditor levelEditor = LevelEditor.Instance; PropsManager propsManager = PropsManager.Instance; //World world = World.Instance; LevelChunk levelChunk = levelEditor.curLevelChunk; levelEditor.resetAll(); Vector3 savedPos = new Vector3(levelFile.playerPosition.x, levelFile.playerPosition.y, levelFile.playerPosition.z); Vector3 savedRot = new Vector3(levelFile.playerEuler.x, levelFile.playerEuler.y, levelFile.playerEuler.z); levelChunk.setStartPos(savedPos, savedRot); FlyCam.Instance.setNewInitialPosition(savedPos, savedRot); FlyCam.Instance.reset(); GameObject goQuadrant; Transform trfmContainer; GameObject container; Vector3 pos = Vector3.zero; int quadLen = levelEditor.cubesPerQuadrant; float fRockSize = levelEditor.fRockSize; int i, len = levelFile.levelQuadrants.Count; for (i = 0; i < len; ++i) { pos.x = (int)levelFile.levelQuadrants[i].position.x; pos.y = (int)levelFile.levelQuadrants[i].position.y; pos.z = (int)levelFile.levelQuadrants[i].position.z; string quadrantId = (int)pos.x + "_" + (int)pos.y + "_" + (int)pos.z; goQuadrant = levelChunk.createQuadrant(pos, quadrantId); if (goQuadrant == null) { continue; } trfmContainer = goQuadrant.transform.Find(Globals.cubesContainerName); if (trfmContainer == null) { continue; } container = trfmContainer.gameObject; Transform trfmCube; GameObject cube; //Vector3 pos2 = Vector3.zero; string materialName; Material material; bool isEdge = false; int j, len2 = levelFile.levelQuadrants [i].levelObjects.Count; for (j = 0; j < len2; ++j) { trfmCube = trfmContainer.Find(j.ToString()); if (trfmCube == null) { continue; } cube = trfmCube.gameObject; if (levelFile.levelQuadrants [i].levelObjects [j].isActive == 0) { cube.SetActive(false); levelChunk.numCubes--; } else { /*if (levelFile.levelQuadrants [i].isEdge == 1) { * material = levelEditor.materialEdge; * isEdge = true; * } else {*/ materialName = Globals.materials[levelFile.levelQuadrants [i].levelObjects [j].materialId]; material = levelEditor.aDictMaterials [materialName]; isEdge = false; //} levelChunk.setCube(cube, material, isEdge); } } } Debug.Log("Level id " + levelFile.levelId.ToString() + " - quadrants: " + len.ToString()); Debug.Log("Level id " + levelFile.levelId.ToString() + " - cubes: " + levelChunk.numCubes.ToString()); MainMenu.Instance.setCubeCountText(levelChunk.numCubes); if (levelFile.levelProps != null) { LevelProp levelProp; GameObject goProp; Quaternion rotation = Quaternion.identity; propDef prop; string name; len = levelFile.levelProps.Count; for (i = 0; i < len; ++i) { levelProp = levelFile.levelProps [i]; pos.x = levelProp.position.x; pos.y = levelProp.position.y; pos.z = levelProp.position.z; prop = propsManager.getPropDefForId(levelProp.id); if (prop.id != -1) { name = prop.name + "_" + levelChunk.trfmProps.childCount; goProp = propsManager.createProp(prop, pos, name, levelChunk.trfmProps, prop.useCollider, prop.useGravity); rotation.w = levelProp.rotation.w; rotation.x = levelProp.rotation.x; rotation.y = levelProp.rotation.y; rotation.z = levelProp.rotation.z; goProp.transform.rotation = rotation; levelChunk.addWorldProp(prop.id, goProp); } } } }