void EditPlanet(MenuObject info, GameObject scene) { // If info is null generate a default one info = info ?? new MenuObject("Kerbin"); // Find the Planet GameObject GameObject planet = scene.GetChild("Kerbin"); if (!info.enabled) { planet.GetComponent <Renderer>().enabled = false; Debug.Log("EditPlanet", "Disabled Kerbin Renderer"); return; } Debug.Log("EditPlanet", "Kerbin position = " + (Vector3d)planet.transform.position); Debug.Log("EditPlanet", "Kerbin rotation = " + (Vector3d)planet.transform.eulerAngles); Debug.Log("EditPlanet", "Kerbin scale = " + (Vector3d)planet.transform.localScale); Debug.Log("EditPlanet", "Kerbin rotatoSpeed = " + planet?.GetComponent <Rotato>()?.speed); // Edit Visual Parameters Renderer renderer = planet.GetComponent <Renderer>(); CelestialBody cb = FlightGlobals.Bodies?.FirstOrDefault(b => b.transform.name == info.name); GameObject template = cb?.scaledBody; if (template != null) { // OnDemand if (KopernicusFixer.detect) { OnDemandFixer.LoadTextures(template); } // Material renderer.material = template?.GetComponent <Renderer>()?.material ?? renderer.material; renderer.material.SetTexture(info.texture1); renderer.material.SetNormal(info.normal1); renderer.material.SetColor(info.color1); // Mesh MeshFilter meshFilter = planet.GetComponent <MeshFilter>(); meshFilter.mesh = template?.GetComponent <MeshFilter>()?.mesh ?? meshFilter.mesh; } info.ApplyTo(planet, 1.4987610578537f); }
void EditMoons(MenuObject[] moons, GameObject scene) { if (!(moons?.Length > 0)) { CelestialBody defaultMoon = FlightGlobals.Bodies?.Where(b => b?.referenceBody?.transform?.name == "Kerbin")?.OrderBy(b => b?.Radius)?.LastOrDefault(); moons = new MenuObject[] { new MenuObject(defaultMoon?.name ?? "Mun", defaultMoon != null) }; } // Get Stock Body GameObject mun = scene.GetChild("Mun"); GameObject clone = Instantiate(mun); Debug.Log("EditMoons", "Mun position = " + (Vector3d)mun.transform.position); Debug.Log("EditMoons", "Mun rotation = " + (Vector3d)mun.transform.eulerAngles); Debug.Log("EditMoons", "Mun scale = " + (Vector3d)mun.transform.localScale); Debug.Log("EditMoons", "Mun rotatoSpeed = " + mun?.GetComponent <Rotato>()?.speed); for (int i = 0; i < moons.Length; i++) { MenuObject info = moons[i]; GameObject body; // Clone or Select Stock Body if (i > 0 && info.enabled) { if (string.IsNullOrEmpty(info.name)) { continue; } body = Instantiate(clone); body.name = "NewMoon_" + info.name; } else if (i == 0) { body = mun; body.SetActive(info.enabled); if (!info.enabled) { continue; } } else { continue; } // Edit Visual Parameters Renderer renderer = body.GetComponent <Renderer>(); CelestialBody cb = FlightGlobals.Bodies?.FirstOrDefault(b => b.transform.name == info.name); GameObject template = cb?.scaledBody; if (template != null) { // OnDemand if (KopernicusFixer.detect) { OnDemandFixer.LoadTextures(template); } // Material renderer.material = template?.GetComponent <Renderer>()?.material ?? renderer.material; // Mesh MeshFilter meshFilter = body.GetComponent <MeshFilter>(); meshFilter.mesh = template?.GetComponent <MeshFilter>()?.mesh ?? meshFilter.mesh; } // Edit Textures renderer.material.SetTexture(info.texture1); renderer.material.SetNormal(info.normal1); renderer.material.SetColor(info.color1); // Edit Physical Parameters info.scale = info.scale ?? Vector3.one; float mult = (float)((cb?.Radius ?? 200000) / 200000); info.ApplyTo(body, 0.209560245275497f * mult); } // CleanUp Object.DestroyImmediate(clone); }
void EditBodies(MenuObject[] bodies, GameObject scene) { if (!(bodies?.Length > 0)) { bodies = new MenuObject[] { new MenuObject("Kerbin") }; } // Get Stock Body GameObject kerbin = scene.GetChild("Kerbin"); GameObject clone = Instantiate(kerbin); Debug.Log("EditBodies", "Kerbin position = " + (Vector3d)kerbin.transform.position); Debug.Log("EditBodies", "Kerbin rotation = " + (Vector3d)kerbin.transform.eulerAngles); Debug.Log("EditBodies", "Kerbin scale = " + (Vector3d)kerbin.transform.localScale); Debug.Log("EditBodies", "Kerbin rotatoSpeed = " + kerbin?.GetComponent <Rotato>()?.speed); for (int i = 0; i < bodies.Length; i++) { MenuObject info = bodies[i]; GameObject body; // Clone or Select Stock Body if (i > 0 && info.enabled) { if (string.IsNullOrEmpty(info.name)) { continue; } body = Instantiate(clone); body.name = "NewBody_" + info.name; } else if (i == 0) { body = kerbin; body.SetActive(info.enabled); if (!info.enabled) { continue; } } else { continue; } // Edit Visual Parameters Renderer renderer = body.GetComponent <Renderer>(); CelestialBody cb = FlightGlobals.Bodies?.FirstOrDefault(b => b.transform.name == info.name); GameObject template = cb?.scaledBody; if (template != null) { // OnDemand if (KopernicusFixer.detect) { OnDemandFixer.LoadTextures(template); } // Material renderer.material = template?.GetComponent <Renderer>()?.material ?? renderer.material; renderer.material.SetTexture(info.texture1); renderer.material.SetNormal(info.normal1); renderer.material.SetColor(info.color1); // Mesh MeshFilter meshFilter = body.GetComponent <MeshFilter>(); meshFilter.mesh = template?.GetComponent <MeshFilter>()?.mesh ?? meshFilter.mesh; } // Edit Physical Parameters info.scale = info.scale ?? Vector3.one; float mult = (float)((cb?.Radius ?? 600000) / 600000); info.ApplyTo(body, 0.188336193561554f * mult); // Add Atmospheric Haze if (haze != null) { renderer.materials = new Material[] { renderer.material, new Material(Shader.Find("KSP/Scenery/Unlit/Transparent")) }; renderer.materials[1].color = (Color)haze; } // CleanUp Object.Destroy(clone); } }