public GameObject loadStarSystem(OrbitalDetails orbitalDetails) { GameObject centreMass = Instantiate(systemCentreMass, new Vector3(0, 0, 0), Quaternion.identity); centreMass.name = "CentreMass"; CelestialBody centreMassBody = ((CelestialBody)centreMass.GetComponent(typeof(CelestialBody))); centreMassBody.loadDetails(orbitalDetails.getRadius(), orbitalDetails.getMass()); for (int i = 0; i < orbitalDetails.getOrbitingBodies().Count; i++) { GameObject planet = Instantiate(planetPrefab, centreMass.transform); planet.name = "Planet-" + i; OrbitingBody planetBody = ((OrbitingBody)planet.GetComponent(typeof(OrbitingBody))); planetBody.loadDetails(orbitalDetails.getOrbitingBodies()[i]); //moon generation for current planet for (int j = 0; j < orbitalDetails.getOrbitingBodies()[i].getOrbitingBodies().Count; j++) { GameObject moon = Instantiate(moonPrefab, planet.transform); moon.name = "Planet-" + i + "-Moon-" + j; OrbitingBody moonBody = ((OrbitingBody)moon.GetComponent(typeof(OrbitingBody))); moonBody.loadDetails(orbitalDetails.getOrbitingBodies()[i].getOrbitingBodies()[j]); } } return(centreMass); }
public static void saveStarSystem(OrbitalDetails orbitalDetails) { BinaryFormatter bf = new BinaryFormatter(); FileStream stream = new FileStream(Application.persistentDataPath + "/orbitalDetails.sav", FileMode.Create); SerializableOrbitDetails serializableOrbitDetails = new SerializableOrbitDetails(orbitalDetails); bf.Serialize(stream, serializableOrbitDetails); stream.Close(); }
public OrbitalDetails getOrbitalDetails(GameObject baseObject) { CelestialBody centreMassBody = ((CelestialBody)baseObject.GetComponent(typeof(CelestialBody))); OrbitalDetails orbitalDetails = new OrbitalDetails(centreMassBody.radius, centreMassBody.mass, new List <OrbitalDetails>()); foreach (Transform transform in baseObject.transform) { OrbitingBody planetBody = ((OrbitingBody)transform.gameObject.GetComponent(typeof(OrbitingBody))); OrbitalDetails planetOrbitalDetails = new OrbitalDetails(planetBody.radius, planetBody.mass, planetBody.getSemiMinorAxis(), planetBody.getSemiMajorAxis(), planetBody.getEccentricity(), planetBody.getFoci1(), planetBody.getFoci2(), planetBody.getCentre(), planetBody.getLocalCentreVector(), planetBody.getCurrentTheta(), planetBody.getCosineEllipseRotation(), planetBody.getSineEllipseRotation(), planetBody.getDistanceFromFoci(), new List <OrbitalDetails>()); foreach (Transform subTransform in transform) { OrbitingBody moonBody = ((OrbitingBody)subTransform.gameObject.GetComponent(typeof(OrbitingBody))); OrbitalDetails moonOrbitalDetails = new OrbitalDetails(moonBody.radius, moonBody.mass, moonBody.getSemiMinorAxis(), moonBody.getSemiMajorAxis(), moonBody.getEccentricity(), moonBody.getFoci1(), moonBody.getFoci2(), moonBody.getCentre(), moonBody.getLocalCentreVector(), moonBody.getCurrentTheta(), moonBody.getCosineEllipseRotation(), moonBody.getSineEllipseRotation(), moonBody.getDistanceFromFoci(), new List <OrbitalDetails>()); planetOrbitalDetails.addOrbitingBody(moonOrbitalDetails); } orbitalDetails.addOrbitingBody(planetOrbitalDetails); } return(orbitalDetails); }
public static OrbitalDetails loadStarSystem() { if (File.Exists(Application.persistentDataPath + "/orbitalDetails.sav")) { BinaryFormatter bf = new BinaryFormatter(); FileStream stream = new FileStream(Application.persistentDataPath + "/orbitalDetails.sav", FileMode.Open); SerializableOrbitDetails serializableOrbitDetails = (SerializableOrbitDetails)bf.Deserialize(stream); OrbitalDetails orbitalDetails = deserializeOrbitDetails(serializableOrbitDetails); stream.Close(); return(orbitalDetails); } return(null); }
public void loadDetails(OrbitalDetails orbitalDetails) { base.loadDetails(orbitalDetails.getRadius(), orbitalDetails.getMass()); semiMinorAxis = orbitalDetails.getSemiMinorAxis(); semiMajorAxis = orbitalDetails.getSemiMajorAxis(); eccentricity = orbitalDetails.getEccentricity(); foci1 = new Vector3(orbitalDetails.getFoci1()[0], orbitalDetails.getFoci1()[1], orbitalDetails.getFoci1()[2]); foci2 = new Vector3(orbitalDetails.getFoci2()[0], orbitalDetails.getFoci2()[1], orbitalDetails.getFoci2()[2]); centre = new Vector3(orbitalDetails.getCentre()[0], orbitalDetails.getCentre()[1], orbitalDetails.getCentre()[2]); localCentreVector = new Vector3(orbitalDetails.getLocalCentreVector()[0], orbitalDetails.getLocalCentreVector()[1], orbitalDetails.getLocalCentreVector()[2]); currentTheta = orbitalDetails.getCurrentTheta(); cosineEllipseRotation = orbitalDetails.getCosineEllipseRotation(); sineEllipseRotation = orbitalDetails.getSineEllipseRotation(); distanceFromFoci = orbitalDetails.getDistanceFromFoci(); gameObject.transform.localPosition = getPositionInOrbit(currentTheta); }
void Start() { OrbitalDetails orbitalDetails = SaveLoadManager.loadStarSystem(); GameObject centreMass; //generate orbits if (orbitalDetails == null) { centreMass = starSystemGenerator.generateStarSystem(gameObject); SaveLoadManager.saveStarSystem(getOrbitalDetails(centreMass)); } else { centreMass = starSystemGenerator.loadStarSystem(orbitalDetails); } waypoints.setCentreMass(centreMass.transform); }
public SerializableOrbitDetails(OrbitalDetails orbitalDetails) { radius = orbitalDetails.getRadius(); mass = orbitalDetails.getMass(); semiMinorAxis = orbitalDetails.getSemiMinorAxis(); semiMajorAxis = orbitalDetails.getSemiMajorAxis(); eccentricity = orbitalDetails.getEccentricity(); foci1 = orbitalDetails.getFoci1(); foci2 = orbitalDetails.getFoci2(); centre = orbitalDetails.getCentre(); localCentreVector = orbitalDetails.getLocalCentreVector(); currentTheta = orbitalDetails.getCurrentTheta(); cosineEllipseRotation = orbitalDetails.getCosineEllipseRotation(); sineEllipseRotation = orbitalDetails.getSineEllipseRotation(); distanceFromFoci = orbitalDetails.getDistanceFromFoci(); List <SerializableOrbitDetails> children = new List <SerializableOrbitDetails>(); foreach (OrbitalDetails currentOrbitalDetails in orbitalDetails.getOrbitingBodies()) { children.Add(new SerializableOrbitDetails(currentOrbitalDetails)); } orbitingBodies = children; }
public void addOrbitingBody(OrbitalDetails orbitalDetails) { orbitingBodies.Add(orbitalDetails); }