// Post spawn fixups (ewwwww........) public void PostSpawnFixups() { Debug.Log("[Kopernicus]: Post-Spawn"); // Fix the flight globals index of each body and patch it's SOI int counter = 0; foreach (CelestialBody body in FlightGlobals.Bodies) { // Patch the flightGlobalsIndex body.flightGlobalsIndex = counter++; // Finalize the Orbit if (Templates.finalizeBodies.Contains(body.transform.name)) { OrbitLoader.FinalizeOrbit(body); } // Patch the SOI if (Templates.sphereOfInfluence.ContainsKey(body.transform.name)) { body.sphereOfInfluence = Templates.sphereOfInfluence[body.transform.name]; } // Patch the Hill Sphere if (Templates.hillSphere.ContainsKey(body.transform.name)) { body.hillSphere = Templates.hillSphere[body.transform.name]; } // Make the Body a barycenter if (Templates.barycenters.Contains(body.transform.name)) { body.scaledBody.SetActive(false); } Logger.Default.Log("Found Body: " + body.bodyName + ":" + body.flightGlobalsIndex + " -> SOI = " + body.sphereOfInfluence + ", Hill Sphere = " + body.hillSphere); } // Fix the maximum viewing distance of the map view camera (get the farthest away something can be from the root object) PSystemBody rootBody = PSystemManager.Instance.systemPrefab.rootBody; double maximumDistance = 1000d; // rootBody.children.Max(b => (b.orbitDriver != null) ? b.orbitDriver.orbit.semiMajorAxis * (1 + b.orbitDriver.orbit.eccentricity) : 0); if (rootBody != null) { maximumDistance = rootBody.celestialBody.Radius * 100d; if (rootBody.children != null && rootBody.children.Count > 0) { foreach (PSystemBody body in rootBody.children) { if (body.orbitDriver != null) { maximumDistance = Math.Max(maximumDistance, body.orbitDriver.orbit.semiMajorAxis * (1d + body.orbitDriver.orbit.eccentricity)); } else { Debug.Log("[Kopernicus]: Body " + body.name + " has no orbitdriver!"); } } } else { Debug.Log("[Kopernicus]: Root body children null or 0"); } } else { Debug.Log("[Kopernicus]: Root body null!"); } if (Templates.maxViewDistance >= 0) { maximumDistance = Templates.maxViewDistance; Debug.Log("Found max distance override " + maximumDistance); } else { Debug.Log("Found max distance " + maximumDistance); } PlanetariumCamera.fetch.maxDistance = ((float)maximumDistance * 3.0f) / ScaledSpace.Instance.scaleFactor; // Select the closest star to home StarLightSwitcher.HomeStar().SetAsActive(); // Flush the logger Logger.Default.Flush(); // Fixups complete, time to surrender to fate Destroy(this); }
// Post spawn fixups (ewwwww........) public void PostSpawnFixups() { // Wrap this in a try - catch block so we can display a warning if Kopernicus fails to load for some reason try { // Log Debug.Log("[Kopernicus]: Post-Spawn"); // Fire Event Events.OnPreFixing.Fire(); // Fix the SpaceCenter SpaceCenter.Instance = PSystemManager.Instance.localBodies.First(cb => cb.isHomeWorld).GetComponentsInChildren <SpaceCenter>(true).FirstOrDefault(); SpaceCenter.Instance.Start(); // Fix the flight globals index of each body and patch it's SOI Int32 counter = 0; foreach (CelestialBody body in FlightGlobals.Bodies) { // Event Events.OnPreBodyFixing.Fire(body); // Patch the flightGlobalsIndex body.flightGlobalsIndex = counter++; // Finalize the Orbit if (body.Get("finalizeBody", false)) { OrbitLoader.FinalizeOrbit(body); } // Set Custom OrbitalPeriod if (body.Has("customOrbitalPeriod")) { OrbitLoader.OrbitalPeriod(body); } // Patch the SOI if (body.Has("sphereOfInfluence")) { body.sphereOfInfluence = body.Get <Double>("sphereOfInfluence"); } // Patch the Hill Sphere if (body.Has("hillSphere")) { body.hillSphere = body.Get <Double>("hillSphere"); } // Make the Body a barycenter if (body.Get("barycenter", false)) { body.scaledBody.SetActive(false); } // Make the bodies scaled space invisible if (body.Get("invisibleScaledSpace", false)) { foreach (Renderer renderer in body.scaledBody.GetComponentsInChildren <Renderer>(true)) { renderer.enabled = false; } } // Event Events.OnPostBodyFixing.Fire(body); // Log Logger.Default.Log("Found Body: " + body.bodyName + ":" + body.flightGlobalsIndex + " -> SOI = " + body.sphereOfInfluence + ", Hill Sphere = " + body.hillSphere); } // Fix the maximum viewing distance of the map view camera (get the farthest away something can be from the root object) PSystemBody rootBody = PSystemManager.Instance.systemPrefab.rootBody; Double maximumDistance = 1000d; // rootBody.children.Max(b => (b.orbitDriver != null) ? b.orbitDriver.orbit.semiMajorAxis * (1 + b.orbitDriver.orbit.eccentricity) : 0); if (rootBody != null) { maximumDistance = rootBody.celestialBody.Radius * 100d; if (rootBody.children != null && rootBody.children.Count > 0) { foreach (PSystemBody body in rootBody.children) { if (body.orbitDriver != null) { maximumDistance = Math.Max(maximumDistance, body.orbitDriver.orbit.semiMajorAxis * (1d + body.orbitDriver.orbit.eccentricity)); } else { Debug.Log("[Kopernicus]: Body " + body.name + " has no orbitdriver!"); } } } else { Debug.Log("[Kopernicus]: Root body children null or 0"); } } else { Debug.Log("[Kopernicus]: Root body null!"); } if (Templates.maxViewDistance >= 0) { maximumDistance = Templates.maxViewDistance; Debug.Log("Found max distance override " + maximumDistance); } else { Debug.Log("Found max distance " + maximumDistance); } PlanetariumCamera.fetch.maxDistance = ((Single)maximumDistance * 3.0f) / ScaledSpace.Instance.scaleFactor; // Call the event Events.OnPostFixing.Fire(); // Flush the logger Logger.Default.Flush(); // Fixups complete, time to surrender to fate Destroy(this); } catch (Exception e) { // Log the exception Debug.LogException(e); // Open the Warning popup DisplayWarning(); } }