public void AddPassable(float[] tPos, int[] tColRow, ushort fakeType, ushort fakeId) { GameObject tObj; tileManager.GetTile(3, 7, out tObj, new Vector3(tPos[0], tPos[1], 0.0f)); Tile_PassableGlitch tTile = new Tile_PassableGlitch(); tTile.type = 3; tTile.id = 7; tTile.SetPosition(new Vector2(tPos[0], tPos[1])); tTile.fakeType = fakeType; tTile.fakeId = fakeId; serializedData.objectList[tColRow[0]][tColRow[1]].Add(tTile); tTile.Deserialize(ref tObj, tileManager); tObj.transform.parent = mapContainer.transform; levelData.objectList[tColRow[0]][tColRow[1]].Add(tObj); if (tObj.tag == "Connectable") { _tileConnector.SetSprite(ref tObj); } _tileConnector.RefreshZone(tObj.transform.position); }
//Transform the serialized level data list into playable gameobjects ( fills the level data list ). public void DeserializeLevelData() { //Create a new GameObject to contain the level objects. levelData = new LevelData(); doorList = new List <GameObject>(); CreateMapContainer(); GameObject tPrefab; theme = serializedData.theme; Camera.main.GetComponent <CameraController>().scrollerSpeed = serializedData.scrollerSpeed; SetParallax(); //Update the color scheme of all enemies. for (int i = 0; i < serializedData.colorScheme[0].Length; i++) { levelData.colorScheme[i][0] = serializedData.colorScheme[i][0].GetColor(); levelData.colorScheme[i][1] = serializedData.colorScheme[i][1].GetColor(); } //Fill the object list. for (int i = 0; i < serializedData.objectList.Count; i++) { for (int j = 0; j < serializedData.objectList[i].Count; j++) { for (int k = 0; k < serializedData.objectList[i][j].Count; k++) { //Return the matching prefab ( using current serialized object's type and id ). tileManager.GetTile(serializedData.objectList[i][j][k].type, serializedData.objectList[i][j][k].id, out tPrefab, serializedData.objectList[i][j][k].GetPosition()); Vector3 tRot = tPrefab.transform.localEulerAngles; tRot.z = serializedData.objectList[i][j][k].rotation; tPrefab.transform.localEulerAngles = tRot; Vector3 tScale = tPrefab.transform.localScale; tScale.x = serializedData.objectList[i][j][k].horizontalMirror ? -1 : 1; tPrefab.transform.localScale = tScale; //Update the unique object list. _uniqueObjects.CheckUniqueObject(new int[2] { i, j }, tPrefab, UniqueObjects.Mode.Add, newCheckPointSet); //If the serialized tile type is extended ( has special attributes ), deserialize the extra attributes. if (serializedData.objectList[i][j][k].isExtended) { if (serializedData.objectList[i][j][k].GetType() == typeof(Tile_PassableGlitch)) { GameObject tObj2 = tPrefab; Tile_PassableGlitch tTile = serializedData.objectList[i][j][k] as Tile_PassableGlitch; tTile.Deserialize(ref tObj2, tileManager); } //Create a copy of the previously created gameobject ( needed to pass the object as a reference ). GameObject tObj = tPrefab; //Deserialize the object's extra attributes and modify the temporary gameobject. serializedData.objectList[i][j][k].Deserialize(ref tObj); //Replace the actual gameobject with the temporary one. tPrefab = tObj; } if (tPrefab.gameObject.name.Contains("Door")) { doorList.Add(tPrefab.gameObject); } //Instantiate the prefab with the serialized object's position and links it to the map container. levelData.objectList[i][j].Add(tPrefab); levelData.objectList[i][j][k].transform.SetParent(mapContainer.transform); } } } for (int i = 0; i < serializedData.objectList.Count; i++) { for (int j = 0; j < serializedData.objectList[i].Count; j++) { for (int k = 0; k < serializedData.objectList[i][j].Count; k++) { if (levelData.objectList[i][j][k].tag == "Connectable") { GameObject go = levelData.objectList[i][j][k]; _tileConnector.SetSprite(ref go); levelData.objectList[i][j][k] = go; } } } } }