Beispiel #1
0
    private static Vessel LoadVessel(GameSaving.VesselSave vesselToLoad)
    {
        List <Part> list = new List <Part>(GameSaving.LoadParts(vesselToLoad));

        Part[] loadedParts = list.ToArray();
        GameSaving.LoadPartsData(vesselToLoad, loadedParts);
        list.Remove(null);
        Orientation.ApplyOrientation(list[0].transform, list[0].orientation);
        Vessel vessel = Vessel.CreateVessel(list[0].GetComponent <Part>(), Vector2.zero, vesselToLoad.angularVelocity, vesselToLoad.throttle, vesselToLoad.vesselArchivments, Ref.map.mapRefs[Ref.GetPlanetByName(vesselToLoad.adress)].holder);

        for (int i = 0; i < vessel.partsManager.parts.Count; i++)
        {
            if (vessel.partsManager.parts[i] != null)
            {
                vessel.partsManager.parts[i].UpdateConnected();
            }
        }
        vessel.partsManager.UpdateCenterOfMass();
        vessel.partsManager.ReCenter();
        vessel.transform.position    = (vesselToLoad.globalPosition - Ref.positionOffset).toVector2;
        vessel.transform.eulerAngles = new Vector3(0f, 0f, vesselToLoad.rotation);
        if (vesselToLoad.state == Vessel.State.RealTime)
        {
            vessel.partsManager.rb2d.velocity = (vesselToLoad.globalVelocity - Ref.velocityOffset).toVector2;
        }
        else if (vesselToLoad.state == Vessel.State.OnRails || vesselToLoad.state == Vessel.State.OnRailsUnloaded)
        {
            vessel.orbits = Orbit.CalculateOrbits(vesselToLoad.globalPosition, vesselToLoad.globalVelocity, Ref.GetPlanetByName(vesselToLoad.adress));
            vessel.partsManager.rb2d.bodyType = RigidbodyType2D.Static;
            vessel.state = Vessel.State.OnRails;
            if (vessel.state == Vessel.State.OnRailsUnloaded)
            {
                vessel.SetVesselState(Vessel.ToState.ToUnloaded);
            }
            if (double.IsNaN(vessel.orbits[0].meanMotion))
            {
                MonoBehaviour.print("Cannot orbit NaN, went stationary instead");
                vessel.orbits.Clear();
                vessel.stationaryData.posToPlane = vesselToLoad.globalPosition;
                vessel.stationaryData.planet     = Ref.GetPlanetByName(vesselToLoad.adress);
                vessel.state = Vessel.State.Stationary;
                vessel.SetVesselState(Vessel.ToState.ToUnloaded);
                vessel.mapIcon.localPosition = (vessel.stationaryData.posToPlane / 10000.0).toVector3;
            }
        }
        else
        {
            vessel.stationaryData.posToPlane = vesselToLoad.globalPosition;
            vessel.stationaryData.planet     = Ref.GetPlanetByName(vesselToLoad.adress);
            vessel.state = Vessel.State.Stationary;
            if (vesselToLoad.state == Vessel.State.StationaryUnloaded)
            {
                vessel.SetVesselState(Vessel.ToState.ToUnloaded);
            }
            vessel.mapIcon.localPosition = (vessel.stationaryData.posToPlane / 10000.0).toVector3;
        }
        vessel.mapIcon.rotation = vessel.partsManager.parts[0].transform.rotation;
        vessel.RCS = vesselToLoad.RCS;
        return(vessel);
    }
    public List <Vessel> CreateVesselsFromParts(List <Part> unatendedParts, Vector2 velocity, float angularVecloty, Vessel.Throttle throttle, List <string> inheritedArchivments)
    {
        List <Vessel> list = new List <Vessel>();

        for (int i = 0; i < unatendedParts.Count; i++)
        {
            if (unatendedParts[i] != null && unatendedParts[i].vessel == null && unatendedParts[i].gameObject.activeSelf)
            {
                Vessel item = Vessel.CreateVessel(unatendedParts[i], velocity, angularVecloty, throttle, inheritedArchivments, this.loadedPlanet.mapRefs.holder);
                list.Add(item);
            }
        }
        return(list);
    }
Beispiel #3
0
    private static Vessel LoadVessel(GameSaving.VesselSave vesselToLoad)
    {
        Part[] array  = GameSaving.LoadParts(vesselToLoad);
        Vessel vessel = Vessel.CreateVessel(array[0].GetComponent <Part>(), Vector2.zero, vesselToLoad.angularVelocity, vesselToLoad.throttle, vesselToLoad.vesselArchivments, Ref.GetPlanetByName(vesselToLoad.adress).mapRefs.holder);

        vessel.partsManager.UpdateCenterOfMass();
        vessel.partsManager.ReCenter();
        vessel.transform.position    = (vesselToLoad.globalPosition - Ref.positionOffset).toVector2;
        vessel.transform.eulerAngles = new Vector3(0f, 0f, vesselToLoad.rotation);
        if (vesselToLoad.state == Vessel.State.RealTime)
        {
            vessel.partsManager.rb2d.velocity = (vesselToLoad.globalVelocity - Ref.velocityOffset).toVector2;
        }
        else if (vesselToLoad.state == Vessel.State.OnRails || vesselToLoad.state == Vessel.State.OnRailsUnloaded)
        {
            vessel.orbits = Orbit.CalculateOrbits(vesselToLoad.globalPosition, vesselToLoad.globalVelocity, Ref.GetPlanetByName(vesselToLoad.adress));
            vessel.partsManager.rb2d.bodyType = RigidbodyType2D.Static;
            vessel.state = Vessel.State.OnRails;
            if (vessel.state == Vessel.State.OnRailsUnloaded)
            {
                vessel.SetVesselState(Vessel.ToState.ToUnloaded);
            }
            if (double.IsNaN(vessel.orbits[0].meanMotion))
            {
                MonoBehaviour.print("Cannot orbit NaN, went stationary instead");
                vessel.orbits.Clear();
                vessel.stationaryData.posToPlane = vesselToLoad.globalPosition;
                vessel.stationaryData.planet     = Ref.GetPlanetByName(vesselToLoad.adress);
                vessel.state = Vessel.State.Stationary;
                vessel.SetVesselState(Vessel.ToState.ToUnloaded);
                vessel.mapIcon.localPosition = (vessel.stationaryData.posToPlane / 10000.0).toVector3;
            }
        }
        else
        {
            vessel.stationaryData.posToPlane = vesselToLoad.globalPosition;
            vessel.stationaryData.planet     = Ref.GetPlanetByName(vesselToLoad.adress);
            vessel.state = Vessel.State.Stationary;
            if (vesselToLoad.state == Vessel.State.StationaryUnloaded)
            {
                vessel.SetVesselState(Vessel.ToState.ToUnloaded);
            }
            vessel.mapIcon.localPosition = (vessel.stationaryData.posToPlane / 10000.0).toVector3;
        }
        GameSaving.LoadPartsData(vesselToLoad, array);
        vessel.mapIcon.rotation = vessel.partsManager.parts[0].transform.rotation;
        return(vessel);
    }