void Start() { Texture2D mip = new Texture2D(tileTex.width, tileTex.height, TextureFormat.ARGB32, true, false); { tileTex.filterMode = FilterMode.Point; var pdata = tileTex.GetPixels32(0); mip.SetPixels32(pdata, 0); mip.Apply(true); } int width = tileTex.width; int layer = 0; while (width > tileSplit) { width /= 2; layer++; Debug.Log("p layer:" + layer); Texture2D m = new Texture2D(width, width, TextureFormat.ARGB32, false, true); m.filterMode = FilterMode.Point; var d = mip.GetPixels32(layer); m.SetPixels32(d, 0); m.Apply(); mipTileTex.Add(m); } GameObject.Destroy(mip); wordData = new worldData[srcTex.width * srcTex.height]; scale = srcTex.width; }
//This loads a world based on there id public void LoadWorld(int id) { if (world.ContainsKey(id)) { ProjectAurora.Diagnostics.Debug.task("Entering world directory"); //We set the universal save path to the worlds path WorldSavePath = Application.persistentDataPath + "/" + "world/" + "world" + id.ToString(); ProjectAurora.Diagnostics.Debug.task("Loading world data"); //We load the data of the world with the id worldData wd = loadSystem.load <worldData>("worldData", Application.persistentDataPath + "/" + "world/" + "world" + id.ToString(), dm.SaveType); ///We set the universal id. ID = wd.ID; ProjectAurora.Diagnostics.Debug.task("Seting world size"); x = wd.x; y = wd.y; ProjectAurora.Diagnostics.Debug.task("Loading world Tiles"); LoadWorldTile(id, wd.x, wd.y, wd.Path + "/Tiles/"); //Debug.Log("World-" + ID.ToString() + " Was loaded from the path: " + WorldSavePath); } else { throw new WorldNotFoundException(); } }
void Start() { Texture2D mip = new Texture2D(tileTex.width, tileTex.height, TextureFormat.ARGB32, true, false); { tileTex.filterMode = FilterMode.Point; var pdata = tileTex.GetPixels32(0); mip.SetPixels32(pdata, 0); mip.Apply(true); } int width = tileTex.width; int layer = 0; while (width > tileSplit) { width /= 2; layer++; Debug.Log("p layer:" + layer); Texture2D m = new Texture2D(width, width, TextureFormat.ARGB32, false, true); m.filterMode = FilterMode.Point; var d = mip.GetPixels32(layer); m.SetPixels32(d, 0); m.Apply(); mipTileTex.Add(m); } GameObject.Destroy(mip); wordData = new worldData[srcTex.width * srcTex.height]; scale = srcTex.width; }
void LoadWorldData(int wldIdx) { //As custom level is wldIdx 6, allWorldData will be out of bounds if this check is not in place if (wldIdx <= allWorldData.Length) { allRoundData = allWorldData[wldIdx-1]; } }
// Using random rolls and a percentage chance of different materials, build a material dictionary for the grid void MapGrid() { GameObject getData = GameObject.Find("WorldData"); worldData getWorldData = getData.GetComponent <worldData> (); int totalGridSquares = getWorldData.worldSize * getWorldData.worldSize; gridMap = new Dictionary <string, string> (totalGridSquares); for (int i = 0; i < totalGridSquares; i++) { gridSqrRef = "Grid" + (i + 1); int materialRange = Random.Range(1, 100); if (materialRange >= 1 && materialRange <= 55) { materialRef = "dirt"; } if (materialRange > 55 && materialRange <= 75) { materialRef = "stone"; } if (materialRange > 75 && materialRange <= 85) { materialRef = "coal"; } if (materialRange > 85 && materialRange <= 95) { materialRef = "iron"; } if (materialRange > 95 && materialRange <= 99) { materialRef = "gold"; } if (materialRange == 100) { materialRef = "gems"; } gridMap.Add(gridSqrRef, materialRef); } }
// Build Material Mesh Vectors Dictionary void BuildVectors() { // Reference Object where Grid vector data is stored GameObject getData = GameObject.Find ("worldData"); worldData WorldData = getData.GetComponent<worldData>(); materialMapVectors = new Dictionary<string, List<Vector3>>(); // Loop to compile materials Vector List for (int i = 0; i < this.blockNumbersLength; i++) { // Grid Square reference Name string gridRef = “Grid” + this.blockNumbers[i]; // Create new Dictionary Entry. // May have to add exception handler after blockMap changing takes effect This.materialMapVectors.Add(gridRef, New List<Vector3>(8)); // If Grid Vector dictionary contains this grid square “Which it should”, pull info and map Vectors to // this material mesh vectors vectorList<vector3> = new list <vector3>(); if (worldData.gridSqrVectors.ContainsKey(gridRef, out vectorList) { this.materialMapVectors[gridRef].Add(worldData.gridSqrVectors[gridRef](vectorList[0]); this.materialMapVectors[gridRef].Add(worldData.gridSqrVectors[gridRef](vectorList[1]); this.materialMapVectors[gridRef].Add(worldData.gridSqrVectors[gridRef](vectorList[2]); this.materialMapVectors[gridRef].Add(worldData.gridSqrVectors[gridRef](vectorList[3]); this.materialMapVectors[gridRef].Add(worldData.gridSqrVectors[gridRef](vectorList[4]); this.materialMapVectors[gridRef].Add(worldData.gridSqrVectors[gridRef](vectorList[5]); this.materialMapVectors[gridRef].Add(worldData.gridSqrVectors[gridRef](vectorList[6]); this.materialMapVectors[gridRef].Add(worldData.gridSqrVectors[gridRef](vectorList[7]); } } This.TriangleMapping(); // Call tri mapping method This.OtherElementsMapping(); // Call tangent and UV mapping methods }
public void Save (){ ContextMenuManager.ToggleMenu(); DirectoryInfo d = new DirectoryInfo (Application.persistentDataPath + @"\Data\"); foreach (FileInfo file in d.GetFiles()) { file.Delete (); } for (int i = 0; i < blockCount; i++) { blocks = GameObject.FindGameObjectsWithTag ("buildBlock"); BinaryFormatter bf = new BinaryFormatter (); Directory.CreateDirectory (Application.persistentDataPath + @"\Data\"); FileStream file = File.Create (Application.persistentDataPath + @"\Data\block-" + i + ".dat"); worldData data = new worldData (); data._name = blocks [i].name; data._tag = blocks [i].tag; data.x = blocks [i].transform.position.x; data.y = blocks [i].transform.position.y; data.z = blocks [i].transform.position.z; data.bType = blocks [i].GetComponent<GlobalValues> ().i; bf.Serialize (file, data); file.Close (); } }
//This creates a new world for the player to play in. public void NewWorld() { ProjectAurora.Diagnostics.Debug.task("Generating a new World id"); //We create the id of the world id = RandomizeWorldid(); //We check to see the id is in use if (world.ContainsKey(id)) { //If a world with this id exists we Re-randomize the id id = RandomizeWorldid(); } ProjectAurora.Diagnostics.Debug.log(id); //We chekc to see if the world exists worldExists(id); ProjectAurora.Diagnostics.Debug.task("Creating save Directories"); //We create the save folder of the world Directory.CreateDirectory(Application.persistentDataPath + "/" + "world/" + "world" + id.ToString()); ProjectAurora.Diagnostics.Debug.log(Application.persistentDataPath + "/" + "world/" + "world" + id.ToString()); //We set the universal save path and world id WorldSavePath = Application.persistentDataPath + "/" + "world/" + "world" + id.ToString(); ID = id; if (!Directory.Exists(WorldSavePath + "/Tiles")) { Directory.CreateDirectory(WorldSavePath + "/Tiles"); } if (!Directory.Exists(WorldSavePath + "/Tiles/Ground")) { Directory.CreateDirectory(WorldSavePath + "/Tiles/Ground"); } if (!Directory.Exists(WorldSavePath + "/Tiles/Ores")) { Directory.CreateDirectory(WorldSavePath + "/Tiles/Ores"); } if (!Directory.Exists(WorldSavePath + "/Tiles/Trees")) { Directory.CreateDirectory(WorldSavePath + "/Tiles/Trees"); } world.Add(id, Application.persistentDataPath + "/" + "world/" + "world" + id.ToString()); ProjectAurora.Diagnostics.Debug.task("Saving Directories"); saveSystem.save("world", dm.worldsdataPath, dm.SaveType, false, world); //Debug.Log("Worlds in data base: " + world.Count); ProjectAurora.Diagnostics.Debug.task("Generating world Surface"); GenerateWorldSurface(); ProjectAurora.Diagnostics.Debug.task("Creating new world"); ProjectAurora.Diagnostics.Debug.task("Saving world data"); worldData w = new worldData(id, WorldSavePath, Name, x, y); saveSystem.save("worldData", WorldSavePath, dm.SaveType, false, w); ProjectAurora.Diagnostics.Debug.task("Entering world"); }
//This gets the world data of the chose world public static worldData GetWorldData(int id) { worldData wd = loadSystem.load <worldData>("worldData", Application.persistentDataPath + "/" + "world/" + "world" + id.ToString(), "pa"); return(wd); }