void FillBuildableLayer() { var count = 0; // fill scene with object layer objects for (var x = 0; x < MapSizeX; x++) { for (var y = 0; y < MapSizeY; y++) { if (MapBuildableLayer[x, y] != null) { var temp = Resources.Load(MapBuildableLayer[x, y].AssetPath, typeof(GameObject)) as GameObject; BuildableSceneObjects[count] = GameObject.Instantiate(temp, new Vector3(x * MapTileSize, 0, y * MapTileSize), Quaternion.identity); var newBuildable = new MapBuildable(); newBuildable.Name = BuildableSceneObjects[count].name; newBuildable.Position = new Vector3(x * MapTileSize, 0, y * MapTileSize); newBuildable.Rotation = Quaternion.identity.eulerAngles; BuildablesInMap[count] = newBuildable; count += 1; } else { BuildableSceneObjects[count] = null; BuildablesInMap[count] = null; } } } }
void UpdateTerrainMapSaveData() { var count = 0; for (var x = 0; x < MapSizeX; x++) { for (var y = 0; y < MapSizeY; y++) { // print (NewMapTerrainLayer[x,y]); if (NewMapTerrainLayer[x, y] == null) { TerrainInMap[count] = null; print("ERROR:" + x + ", " + y); } else { var newTerrainSaveData = new MapBuildable(); newTerrainSaveData.Name = ((NewMapTerrainLayer[x, y].name.Substring(0, NewMapTerrainLayer[x, y].name.Length - 7))); // NewMapTerrainLayer[TileX,TileY].name; newTerrainSaveData.Position = NewMapTerrainLayer[x, y].transform.position; newTerrainSaveData.Rotation = NewMapTerrainLayer[x, y].transform.rotation.eulerAngles; TerrainInMap[count] = newTerrainSaveData; } count += 1; } } }
void LoadMap() { LoadXML(); if (_data.ToString() != "") { // notice how I use a reference to type (UserData) here, you need this // so that the returned object is converted into the correct type myData = (SaveData)DeserializeObject(_data); // set buildablelayer for (var i = 0; i < 400; i++) { if (myData.MapBuildableLayer[i] != null) { BuildablesInMap[i] = myData.MapBuildableLayer[i]; var newAssetPath = ListOfBuildables.FindByName(BuildablesInMap[i].Name).AssetPath; var temp = Resources.Load(newAssetPath, typeof(GameObject)) as GameObject; BuildableSceneObjects[i] = GameObject.Instantiate(temp, BuildablesInMap[i].Position, Quaternion.Euler(BuildablesInMap[i].Rotation)) as GameObject; var newBuildable = new MapBuildable(); newBuildable.Name = BuildablesInMap[i].Name; newBuildable.Position = BuildablesInMap[i].Position; newBuildable.Rotation = BuildablesInMap[i].Rotation; BuildablesInMap[i] = newBuildable; DisableComponentsForEditor(); } else { BuildablesInMap[i] = null; } } // set TerrainLayer for (var i = 0; i < 400; i++) { if (myData.TerrainBuildableLayer[i] != null) { TerrainInMap[i] = myData.TerrainBuildableLayer[i]; var newAssetPath = ListOfBuildables.FindByName(TerrainInMap[i].Name).AssetPath; var temp = Resources.Load(newAssetPath, typeof(GameObject)) as GameObject; var TileX = (int)(i / MapSizeX); var TileY = (int)((i % MapSizeY)); // print ("x = " + TileX + " y = " + TileY); NewMapTerrainLayer[TileX, TileY] = (GameObject)Instantiate(temp, TerrainInMap[i].Position, Quaternion.Euler(TerrainInMap[i].Rotation)); } } } }
void LoadMapFromPlayerBlobManager() { var PlayerBlob = GameObject.Find("PlayerBlobManager_Prefab"); PlayerBlob.GetComponent <PlayerBlobManager>().LoadPlayerData(); myData.MapBuildableLayer = PlayerBlob.GetComponent <PlayerBlobManager>().BuildablesInMap; for (var i = 0; i < 400; i++) { if (myData.MapBuildableLayer[i] != null) { BuildablesInMap[i] = myData.MapBuildableLayer[i]; var newAssetPath = ListOfBuildables.FindByName(BuildablesInMap[i].Name).AssetPath; var temp = Resources.Load(newAssetPath, typeof(GameObject)) as GameObject; BuildableSceneObjects[i] = GameObject.Instantiate(temp, BuildablesInMap[i].Position, Quaternion.Euler(BuildablesInMap[i].Rotation)) as GameObject; var newBuildable = new MapBuildable(); newBuildable.Name = BuildablesInMap[i].Name; newBuildable.Position = BuildablesInMap[i].Position; newBuildable.Rotation = BuildablesInMap[i].Rotation; BuildablesInMap[i] = newBuildable; // DisableComponentsForEditor(); } } myData.TerrainBuildableLayer = PlayerBlob.GetComponent <PlayerBlobManager>().TerrainInMap; for (var i = 0; i < 400; i++) { if (myData.TerrainBuildableLayer[i] != null) { TerrainInMap[i] = myData.TerrainBuildableLayer[i]; var newAssetPath = ListOfBuildables.FindByName(TerrainInMap[i].Name).AssetPath; var temp = Resources.Load(newAssetPath, typeof(GameObject)) as GameObject; var TileX = (int)(i / MapSizeX); var TileY = (int)((i % MapSizeY)); // print ("x = " + TileX + " y = " + TileY); NewMapTerrainLayer[TileX, TileY] = (GameObject)Instantiate(temp, TerrainInMap[i].Position, Quaternion.Euler(TerrainInMap[i].Rotation)); } } }
void SetMapLayerObject(Vector3 myPos, Quaternion myRot, Buildable myObj) { var tileX = (int)(myPos.x / 2); var tileY = (int)(myPos.z / 2); PlayerMapObject.GetComponent <PlayerMap>().MapBuildableLayer[tileX, tileY] = myObj; var newBuildable = new MapBuildable(); // var count = (tileX * (PlayerMapObject.GetComponent<PlayerMap>().MapSizeX -1)) + tileY; var count = (tileX * (PlayerMapObject.GetComponent <PlayerMap>().MapSizeX)) + tileY; newBuildable.Name = myObj.Name; // newBuildable.Position = myPos; newBuildable.Position = FindTerrainCollisionPointYAxis(myPos); newBuildable.Rotation = myRot.eulerAngles; PlayerMapObject.GetComponent <PlayerMap>().BuildablesInMap[count] = newBuildable; PlayerMapObject.GetComponent <PlayerMap>().SaveMap(); }