// Post spawn fixups (ewwwww........) public void PostSpawnFixups() { // Fix the flight globals index of each body int counter = 0; foreach (CelestialBody body in FlightGlobals.Bodies) { body.flightGlobalsIndex = counter++; Logger.Active.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 = rootBody.children.Max(b => (b.orbitDriver != null) ? b.orbitDriver.orbit.semiMajorAxis * (1 + b.orbitDriver.orbit.eccentricity) : 0); PlanetariumCamera.fetch.maxDistance = ((float)maximumDistance * 3.0f) / ScaledSpace.Instance.scaleFactor; // Select the closest star to home StarLightSwitcher.HomeStar().SetAsActive(); // Fixups complete, time to surrender to fate Destroy(this); }
// 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); }