public void loadLevel() { Stream stream = File.Open(Application.dataPath + "/Levels/" + panelUILoad.transform.FindChild("LabelFile").GetComponent<UILabel>().text, FileMode.Open); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Binder = new VersionDeserializationBinder(); Level l = (Level)bformatter.Deserialize(stream); stream.Close(); //purge actualLevel.purge(maxWidth, maxHeight, maxVolume); for(int i=0; i<listUIEnemy.Count; i++) { for(int j=0; j<listUIEnemy.ElementAt(i).Value.Count; j++) { Destroy(listUIEnemy.ElementAt(i).Value.ElementAt(j)); } } listUIEnemy.Clear(); //load actualLevel.loadLevel(l); //Recreate the world var theLevelState = actualLevel.getEntireBlocState(); for(int i=0; i<maxWidth; i++) { for(int j=0; j<maxHeight; j++) { for(int h=0; h<maxVolume; h++) { if(theLevelState[i,j,h] == BLOCSTATE.CUBE) { var go = (GameObject)Instantiate(h == 0 ? cubeBase : cubeBloc, new Vector3(j*2, h*2, i*2), cubeBase.transform.rotation); actualLevel.setCube(i, j, h, go); go.SetActive(true); } if(theLevelState[i,j,h] == BLOCSTATE.SPECIAL) { var go = (GameObject)Instantiate(special, new Vector3(j*2, h*2, i*2), special.transform.rotation); actualLevel.setSpecial(i, j, h, go); go.SetActive(true); } } } } actualLevel.setStartPlayerPosition((int)l.getPlayerSpawn().x, (int)l.getPlayerSpawn().y); actualLevel.setFinishPlayerPosition((int)l.getPlayerFinish().x, (int)l.getPlayerFinish().y); playerSpawnValid.SetActive(true); playerSpawn.transform.position = new Vector3(l.getPlayerSpawn().y*2f, 2f, l.getPlayerSpawn().x*2f); playerFinishValid.SetActive(true); playerFinish.transform.position = new Vector3(l.getPlayerFinish().y*2f, 2f, l.getPlayerFinish().x*2f); //Recréation de la liste d'ennemy listUIEnemy = new Dictionary<Enemy, List<GameObject>>(); for(int i=0; i<l.getEnemies().Count; i++) { var enemy = l.getEnemies().ElementAt(i); var go = (GameObject)Instantiate(enemy.isHelicopter ? enemyHelicoModel : enemyModel, new Vector3(enemy.startY*2, enemy.isHelicopter ? 6f : 2f, enemy.startX*2), enemyModel.transform.rotation); if(enemy.isHelicopter){ actualLevel.setStartEnemyPosition(enemy.startX, enemy.startY, go); }else{ actualLevel.setStartEnemyHelicoPosition(enemy.startX, enemy.startY, go); } go.SetActive(true); go.transform.GetComponent<Enemy>().loadEnemy(enemy); listUIEnemy.Add(go.transform.GetComponent<Enemy>(), new List<GameObject>()); actualEnemyEdit = go.transform.GetComponent<Enemy>(); for(int j=0; j<enemy.ea.Count; j++) { bool isDeplacement = ((int)actualEnemyEdit.getLastAction() <= 3); actualEnemyEdit.addAction(enemy.ea.ElementAt(j).state, enemy.ea.ElementAt(j).timeWait); if((int)enemy.ea.ElementAt(j).state <= 3) { actualNumberAction = actualEnemyEdit.getNumberOfAction(); placeUIWay(enemy.ea.ElementAt(j).state, actualEnemyEdit.isHelico()); }else{ if(isDeplacement) { placeUIAction(actualEnemyEdit.getLastPosition(), actualEnemyEdit.isHelico()); } } listUIEnemy[actualEnemyEdit].Last().SetActive(false); } } for(int i=0; i<l.getObjects().Count; i++) { var theObj = l.getObjects().ElementAt(i); if(theObj.isCanon) { var go = (GameObject)Instantiate(canonModel, new Vector3(theObj.positionY*2f, 2.2f, theObj.positionX*2f), canonModel.transform.rotation); actualLevel.setCanon((int)theObj.positionX, (int)theObj.positionY, go); go.SetActive(true); go.GetComponent<Canon>().setLook((LOOK)theObj.theLook); switch(theObj.theLook) { case LOOK.DOWN: go.transform.eulerAngles = new Vector3(0f, 0f, 0f); break; case LOOK.UP: go.transform.eulerAngles = new Vector3(0f, 180f, 0f); break; case LOOK.RIGHT: go.transform.eulerAngles = new Vector3(0f, -90f, 0f); break; case LOOK.LEFT: go.transform.eulerAngles = new Vector3(0f, 90f, 0f); break; } }else{ var go = (GameObject)Instantiate(cameraEnModel, new Vector3(theObj.positionY*2f, 4f, theObj.positionX*2f), cameraEnModel.transform.rotation); actualLevel.setCameraEnemy((int)theObj.positionX, (int)theObj.positionY, go); go.GetComponent<CameraEnemy>().rightFirst = theObj.isRightFirst; go.SetActive(true); go.GetComponent<CameraEnemy>().setLook((LOOK)theObj.theLook); switch(theObj.theLook) { case LOOK.DOWN: go.transform.eulerAngles = new Vector3(0f, 90f, 0f); break; case LOOK.UP: go.transform.eulerAngles = new Vector3(0f, -90f, 0f); break; case LOOK.RIGHT: go.transform.eulerAngles = new Vector3(0f, 0f, 0f); break; case LOOK.LEFT: go.transform.eulerAngles = new Vector3(0f, 180f, 0f); break; } } } panelUILoad.SetActive(false); actualMode = EDITMODE.CUBE; oldWidthSelected = -1; oldHeightSelected = -1; }