public void LoadChunk(string fileName) { terrainArray = XMLVoxelFileWriter.LoadChunkFromXML(16, fileName); CreateTerrain(); voxelGen.UpdateMesh(); }
public void StartEverything() { Time.timeScale = 1f; //make sure this is 1! if (!traversing) { Stack <Vector3> path = BreadthFirstSearch(startPosition, endPosition, voxelChunk); if (path.Count > 0) { StartCoroutine(LerpAlongPath(path)); } } Vector3 s, e; if (XMLVoxelFileWriter.ReadStartAndEndPosition(out s, out e, "AssessmentChunk1")) { startPosition = s; print("Start = " + startPosition); endPosition = e; print("End = " + endPosition); } Stack <Vector3> path2 = Djikstras(startPosition, endPosition, voxelChunk); if (path2.Count > 0) { StartCoroutine(LerpAlongPath(path2)); } }
public void SaveChunkToXMLFile() { if (loadSaveGO.activeSelf) { XMLVoxelFileWriter.SaveChunkToXMLFile(terrainArray, inputField.text); //VoxelChunk } else { Debug.Log("Input field inactive"); } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.F1)) { XMLVoxelFileWriter.SaveChunkToXML(terrainArray, "VoxelChunk"); } if (Input.GetKeyDown(KeyCode.F2)) { } }
public void LoadChunkFromXMLFile() { if (loadSaveGO.activeSelf) { terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, inputField.text); CreateTerrain(); voxelGenerator.UpdateMesh(); } else { Debug.Log("Input field inactive"); } }
// Use this for initialization void Start() { voxelGenerator = GetComponent <VoxelGenerator>(); terrainArray = new int[chunkSize, chunkSize, chunkSize]; voxelGenerator.Initialise(); InitialiseTerrain(); terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, "AssessmentChunk1"); CreateTerrain(); voxelGenerator.UpdateMesh(); }
public override void OnInspectorGUI() { VoxelChunk myTarget = (VoxelChunk)target; fileName = EditorGUILayout.TextField(fileName); if (GUILayout.Button("Load from XML")) { myTarget.LoadChunk(fileName); } if (GUILayout.Button("Save to XML")) { XMLVoxelFileWriter.SaveChunkToXML(myTarget.terrainArray, "VoxelChunk"); } if (GUILayout.Button("Clear Terrain")) { myTarget.GetComponent <VoxelGen>().ClearPrevData(); } }
public void LoadButtonPressed() { string playerFileName = loadFileName.text; terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, playerFileName); if (terrainArray != null) { // Draw the correct faces CreateTerrain(); // Update mesh info voxelGenerator.UpdateMesh(); LockCursor(); loadPanel.SetActive(false); panelOpen = false; } else { Debug.Log("No file found."); } }
void Update() { if (Input.GetKeyDown(KeyCode.F1)) { XMLVoxelFileWriter.SaveChunkToXMLFile(terrainArray, "Save", player.transform.position); } if (Input.GetKeyDown(KeyCode.F2)) { if (!panelOpen) { loadPanel.SetActive(true); UnlockCursor(); panelOpen = true; } else { loadPanel.SetActive(false); LockCursor(); panelOpen = false; } } }
void Update() { if (!traversing) { if (Input.GetKeyDown(KeyCode.O)) { Stack <Vector3> path = BreadthFirstSearch(startPosition, endPosition, voxelChunk); if (path.Count > 0) { StartCoroutine(LerpAlongPath(path)); } } if (Input.GetKeyDown(KeyCode.L)) { Stack <Vector3> path = Djikstras(startPosition, endPosition, voxelChunk); if (path.Count > 0) { StartCoroutine(LerpAlongPath(path)); } } } if (Input.GetKeyDown(KeyCode.P)) { Vector3 s, e; if (XMLVoxelFileWriter.ReadStartAndEndPosition(out s, out e, "AssessmentChunk1")) { startPosition = s; print("Start = " + startPosition); endPosition = e; print("End = " + endPosition); } } }
//buttons that allow user to changing the map, start and end position or start the pathfinding********************************************************************* void OnGUI() { if (GUI.Button(new Rect(50, 50, 150, 50), "AssessmentChunk1")) { XMLVoxelFileWriter.ReadStartAndEndPosition(out startPosition, out endPosition, "AssessmentChunk1"); //get terrainArray from xml voxelChunk.terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, "AssessmentChunk1"); //draw the correct faces voxelChunk.CreateTerrain(); //Update mesh info voxelGenerator.UpdateMesh(); } if (GUI.Button(new Rect(50, 120, 150, 50), "AssessmentChunk2")) { XMLVoxelFileWriter.ReadStartAndEndPosition(out startPosition, out endPosition, "AssessmentChunk2"); //get terrainArray from xml voxelChunk.terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, "AssessmentChunk2"); //draw the correct faces voxelChunk.CreateTerrain(); //Update mesh info voxelGenerator.UpdateMesh(); } if (!traversing) { if (GUI.Button(new Rect(50, 190, 150, 50), "Start")) { Stack <Vector3> path = Dijkstra(startPosition, endPosition, voxelChunk); if (path.Count > 0) { //Debug.Log (path.Count); StartCoroutine(LerpAlongPath(path)); } } } }
//Initialise the terrain***************************************************************************************************************************************************** void Start() { Pathfinder.traversalBegin += CantSetBlocks; Pathfinder.traversalEnd += CanSetBlocks; voxelGenerator = GetComponent <VoxelGenerator>(); terrainArray = new int[chunkSize, chunkSize, chunkSize]; voxelGenerator.Initialise(); InitialiseTerrain(); //get terrainArray from xml terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, "AssessmentChunk2"); CreateTerrain(); voxelGenerator.UpdateMesh(); wayPointList = new List <Vector3>(); for (int x = 0; x < terrainArray.GetLength(0); x++) { for (int y = 0; y < terrainArray.GetLength(1); y++) { for (int z = 0; z < terrainArray.GetLength(2); z++) { if (terrainArray[x, y, z] == 3) { wayPointList.Add(new Vector3(x + 0.5f, y + 1.5f, z + 0.5f)); } } } } }
public void SaveChunk(string filename) { XMLVoxelFileWriter.SaveChunkToXMLFile(terrainArray, "VoxelChunk", player.transform.position); }
// Use this for initialization void Start() { //load the second assessment start and end position by default**************************************************************************************************** XMLVoxelFileWriter.ReadStartAndEndPosition(out startPosition, out endPosition, "AssessmentChunk2"); }
void OnGUI() { GUI.Box(new Rect(0, Screen.height - 30, 250, 30), "Press F1 to save, F2 to load"); GUI.Box(new Rect(0, Screen.height - 60, 250, 30), "Press i to open or close inventory"); GUI.Box(new Rect(0, Screen.height - 90, 250, 30), "Press 1-4 to select blocks"); //just act as a crosshair************************************************************************************************************************** GUI.Label(new Rect(Screen.width / 2 - 10, Screen.height / 2 - 10, 20, 20), "+"); //choose different blocks by pressing 1,2,3 or 4 key*********************************************************************************************** //changing the alpha level based on which block is chosen, so other blocks will not be as visable as the chosen block****************************** Color colorHolder = GUI.color; GUI.Box(new Rect(Screen.width / 4, Screen.height / 1.2f, Screen.width / 2, Screen.height / 8), ""); GUI.color = new Color(1, 1, 1, alphaLevel1); GUI.DrawTexture(new Rect(Screen.width / 3.9f, Screen.height / 1.2f, Screen.width / 10, Screen.height / 8), selectionTextures [0]); GUI.color = new Color(1, 1, 1, alphaLevel2); GUI.DrawTexture(new Rect(Screen.width / 2.65f, Screen.height / 1.2f, Screen.width / 10, Screen.height / 8), selectionTextures [1]); GUI.color = new Color(1, 1, 1, alphaLevel3); GUI.DrawTexture(new Rect(Screen.width / 1.98f, Screen.height / 1.2f, Screen.width / 10, Screen.height / 8), selectionTextures [2]); GUI.color = new Color(1, 1, 1, alphaLevel4); GUI.DrawTexture(new Rect(Screen.width / 1.58f, Screen.height / 1.2f, Screen.width / 10, Screen.height / 8), selectionTextures [3]); GUI.color = colorHolder; if (Input.GetKeyDown("1")) { selectBlockType = 1; alphaLevel1 = 1f; alphaLevel2 = 0.4f; alphaLevel3 = 0.4f; alphaLevel4 = 0.4f; } else if (Input.GetKeyDown("2")) { selectBlockType = 2; alphaLevel1 = 0.4f; alphaLevel2 = 1f; alphaLevel3 = 0.4f; alphaLevel4 = 0.4f; } else if (Input.GetKeyDown("3")) { selectBlockType = 3; alphaLevel1 = 0.4f; alphaLevel2 = 0.4f; alphaLevel3 = 1f; alphaLevel4 = 0.4f; } else if (Input.GetKeyDown("4")) { selectBlockType = 4; alphaLevel1 = 0.4f; alphaLevel2 = 0.4f; alphaLevel3 = 0.4f; alphaLevel4 = 1f; } //On pressing the F1 key, a prompt will show up and ask user to type in a file name************************************************************* //and SAVE the terrain, player position and angle in to that xml file*************************************************************************** //camera and controller rotation are disable during this process******************************************************************************** if (Input.GetKeyDown(KeyCode.F1)) { F1Trigger = true; } if (F1Trigger == true) { foreach (MouseLook n in lockRotation) { n.enabled = false; } GUI.Label(new Rect(Screen.width / 3, Screen.height / 2.5f, 300, 40), "Please type in a file name to save"); inputName = GUI.TextField(new Rect(Screen.width / 3, Screen.height / 2, 300, 40), inputName, 30); if (GUI.Button(new Rect(Screen.width / 1.5f, Screen.height / 1.5f, 100, 50), "Confirm")) { foreach (MouseLook n in lockRotation) { n.enabled = true; } float PosX = this.gameObject.transform.position.x; float PosY = this.gameObject.transform.position.y; float PosZ = this.gameObject.transform.position.z; float RotX = this.gameObject.transform.eulerAngles.x; float RotY = this.gameObject.transform.eulerAngles.y; float RotZ = this.gameObject.transform.eulerAngles.z; XMLVoxelFileWriter.SaveChunkToXMLFile(voxelChunk.terrainArray, PosX, PosY, PosZ, RotX, RotY, RotZ, inputName); // playerPosTrigger=true; F1Trigger = false; } } //On pressing the F2 key, a prompt will show up and ask user to type in a file name************************************************************* //and LOAD the terrain, player position and angle from that xml file**************************************************************************** //camera and controller rotation are disable during this process******************************************************************************** //Start and end position for pathfinding will also read from here if it exist(removed as its not necessary)************************************* if (Input.GetKeyDown(KeyCode.F2)) { F2Trigger = true; } if (F2Trigger == true) { foreach (MouseLook n in lockRotation) { //lockRotationX.enabled=false; n.enabled = false; } GUI.Label(new Rect(Screen.width / 3, Screen.height / 2.5f, 300, 40), "Please type in a file name to load"); inputName = GUI.TextField(new Rect(Screen.width / 3, Screen.height / 2, 300, 40), inputName, 30); if (GUI.Button(new Rect(Screen.width / 1.5f, Screen.height / 1.5f, 100, 50), "Confirm")) { //lockRotationX.enabled=true; //lockRotationY.enabled=true; foreach (MouseLook n in lockRotation) { n.enabled = true; } if (System.IO.File.Exists(inputName + ".xml")) { this.gameObject.transform.position = XMLVoxelFileWriter.LoadPosFromXMLFile(inputName); this.gameObject.transform.rotation = XMLVoxelFileWriter.LoadRotFromXMLFile(inputName); // XMLVoxelFileWriter.ReadStartAndEndPosition(out pathfinder.startPosition, out pathfinder.endPosition,inputName); // { // //Debug.Log (s); // pathfinder.startPosition=s; // pathfinder.endPosition=e; // } //get terrainArray from xml voxelChunk.terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, inputName); //draw the correct faces voxelChunk.CreateTerrain(); //Update mesh info voxelGenerator.UpdateMesh(); F2Trigger = false; } } } }
public void LoadPathfindingChunk() { terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, "AssessmentChunk1"); CreateTerrain(); voxelGenerator.UpdateMesh(); }
public void LoadingA2() { // Get terrainArray from XML file terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, "AssessmentChunk2"); Loading(); }
public void LoadingMain() { // Get terrainArray from XML file terrainArray = XMLVoxelFileWriter.LoadChunkFromXMLFile(16, saveFileText); Loading(); }