public static void SetupVessel(LaunchedVessel lv) { GameObject obj = new GameObject(); DontDestroyOnLoad(obj); obj.AddComponent <MonoBehaviour>().StartCoroutine(setup_vessel(obj, lv)); }
//static coroutine launched from a DontDestroyOnLoad sentinel object allows to execute code while the scene is switching static IEnumerator<YieldInstruction> setup_vessel(UnityEngine.Object sentinel, LaunchedVessel lv) { while(!lv.launched) yield return new WaitForFixedUpdate(); lv.tunePosition(); lv.stiffenWheels(); lv.transferCrew(); //it seems you must give KSP a moment to sort it all out, //so delay the remaining steps of the transfer process. //(from the CrewManifest: https://github.com/sarbian/CrewManifest/blob/master/CrewManifest/ManifestController.cs) yield return new WaitForSeconds(0.25f); lv.vessel.SpawnCrew(); Destroy(sentinel); }
//static coroutine launched from a DontDestroyOnLoad sentinel object allows to execute code while the scene is switching static IEnumerator <YieldInstruction> setup_vessel(UnityEngine.Object sentinel, LaunchedVessel lv) { while (!lv.launched) { yield return(new WaitForFixedUpdate()); } lv.tunePosition(); lv.stiffenWheels(); lv.transferCrew(); //it seems you must give KSP a moment to sort it all out, //so delay the remaining steps of the transfer process. //(from the CrewManifest: https://github.com/sarbian/CrewManifest/blob/master/CrewManifest/ManifestController.cs) yield return(new WaitForSeconds(0.25f)); lv.vessel.SpawnCrew(); Destroy(sentinel); }
public static void SetupVessel(LaunchedVessel lv) { GameObject obj = new GameObject(); DontDestroyOnLoad(obj); obj.AddComponent<MonoBehaviour>().StartCoroutine(setup_vessel(obj, lv)); }