IEnumerator Load(string name) { main.isGenerating = true; main.generationStatusString = "Loading Project\nPlease wait...\n\nLoading: Project Settings"; string fileName = name + ".rsgg"; main.ResetAll(); var sr = File.OpenText(fileName); string filetext = sr.ReadToEnd(); var N = JSON.Parse(filetext); try { if (N["galaxy"]["version"].Value != main.version) { main.Log("Warning: Project version is " + N["galaxy"]["version"].Value); main.Log("Your RSGG version is " + main.version); } main.galaxyname = N["galaxy"]["name"]; main.autogenHyperlines = bool.Parse(N["galaxy"]["random_hyperlanes"]); main.galaxysize = int.Parse(N["galaxy"]["size"].Value); main.genhlradius = int.Parse(N["galaxy"]["hl_radius"].Value); main.genhlmaxlines = int.Parse(N["galaxy"]["hl_maxPerSys"].Value); main.generationseed = int.Parse(N["galaxy"]["seed"].Value); main.starstogen = float.Parse(N["galaxy"]["stars"].Value); main.nscale = float.Parse(N["galaxy"]["pnoise_scale"].Value); main.nfreq = float.Parse(N["galaxy"]["pnoise_freq"].Value); main.npers = float.Parse(N["galaxy"]["pnoise_pers"].Value); main.pngmultiplier = float.Parse(N["galaxy"]["png_multiplier"].Value); main.pngrandomizer = float.Parse(N["galaxy"]["png_randomizer"].Value); main.pngreducer = float.Parse(N["galaxy"]["png_reducer"].Value); main.usePerlin = bool.Parse(N["galaxy"]["pnoise"]); main.refreshGalaxySizeLines(int.Parse(N["galaxy"]["size"].Value)); if (float.Parse(N["galaxy"]["version"].Value) >= 0.9f) { main.minDist = int.Parse(N["galaxy"]["minimalSystemDistance"].Value); } else { main.minDist = 12; } // int[] d = new int[N["galaxy"]["systems"].Count*2]; // for(int x = 0; x < N["galaxy"]["systems"].Count; x++) // { // d[x] = int.Parse(N["galaxy"]["systems"][x]["position"]["x"].Value); // d[N["galaxy"]["systems"].Count+x] = int.Parse(N["galaxy"]["systems"][x]["position"]["y"].Value); // } // main.galaxysize = Mathf.Max(d); } catch { // yield return new WaitForSeconds(0.001f); main.isGenerating = false; main.Log("Error while loading project"); } main.generationStatusString = "Loading Project\nPlease wait...\n\nLoading: Galaxy Systems"; yield return(new WaitForSeconds(0.001f)); List <system> TsysList = new List <system>(); try { // Systems for (int x = 0; x < N["galaxy"]["systems"].Count; x++) { GameObject g = (GameObject)Instantiate(system_prefab, new Vector3(float.Parse(N["galaxy"]["systems"][x]["position"]["x"]), 0, float.Parse(N["galaxy"]["systems"][x]["position"]["y"])), Quaternion.identity); g.transform.SetParent(main.GalaxyEditor.transform, true); system sys = g.GetComponent <system>(); if (N["galaxy"]["systems"][x]["name"].Value != "null") { sys.systemName = N["galaxy"]["systems"][x]["name"].Value; } if (N["galaxy"]["systems"][x]["initializer"].Value != "null") { sys.initializer = N["galaxy"]["systems"][x]["initializer"].Value; } sys.prevent = bool.Parse(N["galaxy"]["systems"][x]["prevent_hyperlane"].Value); sys.systemid = int.Parse(N["galaxy"]["systems"][x]["id"].Value); if (bool.Parse(N["galaxy"]["systems"][x]["spawn"].Value)) { sys.setSpawn(true); } int xx = x; while (TsysList.Count <= sys.systemid) { TsysList.Add(sys); xx++; } // TsysList.Insert(sys.systemid, sys); } } catch { main.isGenerating = false; main.Log("Error while loading project"); } main.generationStatusString = "Loading Project\nPlease wait...\n\nLoading: Galaxy Nebulas"; yield return(new WaitForSeconds(0.001f)); try { //Nebulas for (int x = 0; x < N["galaxy"]["nebulas"].Count; x++) { GameObject g = (GameObject)Instantiate(nebula_prefab, new Vector3(float.Parse(N["galaxy"]["nebulas"][x]["position"]["x"]), 0, float.Parse(N["galaxy"]["nebulas"][x]["position"]["y"])), Quaternion.identity); g.transform.SetParent(main.GalaxyEditor.transform, true); nebula neb = g.GetComponent <nebula>(); if (N["galaxy"]["nebulas"][x]["name"].Value != "null") { neb.nebulaName = N["galaxy"]["nebulas"][x]["name"].Value; } neb.nebulaRadius = int.Parse(N["galaxy"]["nebulas"][x]["radius"].Value); } } catch { // yield return new WaitForSeconds(0.001f); main.isGenerating = false; main.Log("Error while loading project"); } if (loadHyperlanes) { main.generationStatusString = "Loading Project\nPlease wait...\n\nLoading: Galaxy Hyperlanes"; yield return(new WaitForSeconds(0.001f)); try { //Hyperlanes for (int x = 0; x < N["galaxy"]["hyperlanes"].Count; x++) { GameObject g = (GameObject)Instantiate(hyperlane_prefab, new Vector3(0, 0, 0), Quaternion.identity); g.transform.SetParent(main.GalaxyEditor.transform, true); hyperlane hl = g.GetComponent <hyperlane>(); hl.link0 = TsysList[int.Parse(N["galaxy"]["hyperlanes"][x]["from"].Value)]; hl.link1 = TsysList[int.Parse(N["galaxy"]["hyperlanes"][x]["to"].Value)]; if (N["galaxy"]["hyperlanes"][x]["mode"].Value == "add") { hl.prevent = false; } else if (N["galaxy"]["hyperlanes"][x]["mode"].Value == "prevent") { hl.prevent = true; } } } catch { // yield return new WaitForSeconds(0.001f); main.isGenerating = false; main.Log("Error while loading project"); } } main.generationStatusString = "Loading Project\nPlease wait...\n\nLoading: Custom Systems"; yield return(new WaitForSeconds(0.001f)); try { //Custom Systems for (int x = 0; x < N["customSystems"].Count; x++) { GameObject g = (GameObject)Instantiate(systemeditor_prefab, new Vector3(0, 0, 0), Quaternion.identity); systemeditor se = g.GetComponent <systemeditor>(); main.systemEditors.Add(g); system s = TsysList[int.Parse(N["customSystems"][x]["systemID"].Value)]; se.SetForSys(s); se.systemName = N["customSystems"][x]["name"]; se.starType = N["customSystems"][x]["starType"]; se.centerStarSize = int.Parse(N["customSystems"][x]["starSize"].Value); se.centerStarDisabled = bool.Parse(N["customSystems"][x]["disableCenterStar"].Value); se.asteroidBelt = bool.Parse(N["customSystems"][x]["asteroidBelt"].Value); se.asteroidBeltRadius = int.Parse(N["customSystems"][x]["asteroidBeltRadius"].Value); for (int y = 0; y < N["customSystems"][x]["planets"].Count; y++) { GameObject planetGO = (GameObject)Instantiate(planet_prefab, new Vector3(float.Parse(N["customSystems"][x]["planets"][y]["position"]["x"]), 0, float.Parse(N["customSystems"][x]["planets"][y]["position"]["y"])), Quaternion.identity); planetGO.transform.SetParent(g.transform, true); planet p = planetGO.GetComponent <planet>(); planetGO.name = "planet_" + se.thisSystem.systemid; p.ownerSystem = se.thisSystem.systemid; if (N["customSystems"][x]["planets"][y]["name"].Value != "null") { p.planetName = N["customSystems"][x]["planets"][y]["name"].Value; } p.planetClass = N["customSystems"][x]["planets"][y]["class"].Value; p.planetSize = int.Parse(N["customSystems"][x]["planets"][y]["size"].Value); p.orbitDistance = int.Parse(N["customSystems"][x]["planets"][y]["orbitDistance"].Value); p.orbitAngle = int.Parse(N["customSystems"][x]["planets"][y]["orbitAngle"].Value); p.isHome = bool.Parse(N["customSystems"][x]["planets"][y]["home"].Value); if (p.isHome) { p.planetSize = 16; p.planetClass = "ideal_planet_class"; } if (float.Parse(N["galaxy"]["version"].Value) >= 0.8f) { p.hasRing = bool.Parse(N["customSystems"][x]["planets"][y]["ringed"].Value); } else { p.hasRing = false; } if (float.Parse(N["galaxy"]["version"].Value) >= 0.9f) { p.noAnomaly = bool.Parse(N["customSystems"][x]["planets"][y]["no_anomaly"].Value); p.noResources = bool.Parse(N["customSystems"][x]["planets"][y]["no_resources"].Value); p.planetModifier = N["customSystems"][x]["planets"][y]["modifier"].Value; } g.GetComponent <systemeditor>().planets.Add(planetGO); for (int z = 0; z < N["customSystems"][x]["planets"][y]["moons"].Count; z++) { GameObject planetmGO = (GameObject)Instantiate(planet_prefab, new Vector3(float.Parse(N["customSystems"][x]["planets"][y]["moons"][z]["position"]["x"]), 0, float.Parse(N["customSystems"][x]["planets"][y]["moons"][z]["position"]["y"])), Quaternion.identity); planetmGO.transform.SetParent(g.transform, true); planet pm = planetmGO.GetComponent <planet>(); planetmGO.name = "moon_" + se.thisSystem.systemid; pm.ownerSystem = se.thisSystem.systemid; pm.ownerPlanet = p; if (N["customSystems"][x]["planets"][y]["moons"][z]["name"].Value != "null") { pm.planetName = N["customSystems"][x]["planets"][y]["moons"][z]["name"].Value; } pm.planetClass = N["customSystems"][x]["planets"][y]["moons"][z]["class"].Value; pm.planetSize = int.Parse(N["customSystems"][x]["planets"][y]["moons"][z]["size"].Value); pm.orbitDistance = int.Parse(N["customSystems"][x]["planets"][y]["moons"][z]["orbitDistance"].Value); pm.orbitAngle = int.Parse(N["customSystems"][x]["planets"][y]["moons"][z]["orbitAngle"].Value); pm.isHome = bool.Parse(N["customSystems"][x]["planets"][y]["moons"][z]["home"].Value); if (pm.isHome) { pm.planetSize = 16; pm.planetClass = "ideal_planet_class"; } if (float.Parse(N["galaxy"]["version"].Value) >= 0.8f) { pm.hasRing = bool.Parse(N["customSystems"][x]["planets"][y]["moons"][z]["ringed"].Value); } else { pm.hasRing = false; } if (float.Parse(N["galaxy"]["version"].Value) >= 0.9f) { pm.noAnomaly = bool.Parse(N["customSystems"][x]["planets"][y]["moons"][z]["no_anomaly"].Value); pm.noResources = bool.Parse(N["customSystems"][x]["planets"][y]["moons"][z]["no_resources"].Value); pm.planetModifier = N["customSystems"][x]["planets"][y]["moons"][z]["modifier"].Value; } g.GetComponent <systemeditor>().planets.Add(planetmGO); } } g.SetActive(false); } } catch { // yield return new WaitForSeconds(0.001f); main.isGenerating = false; main.Log("Error while loading project"); } main.isGenerating = false; main.Log("Project Loaded"); }
// Update is called once per frame void Update() { if (Camera.main.fieldOfView <= 5) { Camera.main.fieldOfView = 5; } if (Input.GetKey(KeyCode.UpArrow)) { CameraAxe.position = new Vector3(CameraAxe.position.x, CameraAxe.position.y, CameraAxe.position.z - 10); } if (Input.GetKey(KeyCode.DownArrow)) { CameraAxe.position = new Vector3(CameraAxe.position.x, CameraAxe.position.y, CameraAxe.position.z + 10); } if (Input.GetKey(KeyCode.LeftArrow)) { CameraAxe.position = new Vector3(CameraAxe.position.x + 10, CameraAxe.position.y, CameraAxe.position.z); } if (Input.GetKey(KeyCode.RightArrow)) { CameraAxe.position = new Vector3(CameraAxe.position.x - 10, CameraAxe.position.y, CameraAxe.position.z); } if (Input.GetKey(KeyCode.Escape)) { if (currentMode == 0 && editorMode == 0) { if (selectedSystem) { selectedSystem.select(false); selectedSystem = null; } if (selectedNebula) { selectedNebula.select(false); selectedNebula = null; } if (prevSelectedSystem) { prevSelectedSystem.select(false); prevSelectedSystem = null; } if (prevSelectedNebula) { prevSelectedNebula.select(false); prevSelectedNebula = null; } if (prevSelectedHyperlane) { prevSelectedHyperlane = null; } } else { currentMode = 0; } } if (Input.GetKey(KeyCode.Delete)) { if (editorMode == 0) { if (selectedSystem) { Destroy(selectedSystem.gameObject); } if (selectedNebula) { Destroy(selectedNebula.gameObject); } } } if (Input.GetKeyDown(KeyCode.F1)) { showTexts = !showTexts; } if (GUIUtility.hotControl == 0) { if (!scrollerRect.Contains(Input.mousePosition)) { if (Input.GetAxis("Mouse ScrollWheel") < 0) { // Debug.Log(GUIUtility.hotControl); Camera.main.fieldOfView += 5; } if (Input.GetAxis("Mouse ScrollWheel") > 0) { Camera.main.fieldOfView -= 5; } } if (Input.GetKeyDown(KeyCode.Mouse0) && editorMode == 0) { switch (main.currentMode) { case 3: Vector3 poss = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 460)); GameObject g = (GameObject)Instantiate(system_prefab, new Vector3(poss.x, 0, poss.z), Quaternion.identity); g.transform.SetParent(GalaxyEditor.transform, true); break; case 5: Vector3 posn = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 460)); GameObject g2 = (GameObject)Instantiate(nebula_prefab, new Vector3(posn.x, 0, posn.z), Quaternion.identity); g2.transform.SetParent(GalaxyEditor.transform, true); break; } } } }