Created
March 30, 2019 00:58
-
-
Save DMagic1/afb38be601c371de8722e7bbcf814e19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
namespace JettisonFix | |
{ | |
[KSPAddon(KSPAddon.Startup.Flight, false)] | |
public class JettisonFixer : MonoBehaviour | |
{ | |
private void Awake() | |
{ | |
GameEvents.onVesselLoaded.Add(OnVesselLoaded); | |
} | |
private void OnDestroy() | |
{ | |
GameEvents.onVesselLoaded.Remove(OnVesselLoaded); | |
} | |
private void OnVesselLoaded(Vessel v) | |
{ | |
Debug.Log("[RS_Jettison]: " + v.vesselName); | |
if (v == null || !v.loaded || v.isEVA) | |
return; | |
StartCoroutine(WaitForJettison(v)); | |
} | |
private IEnumerator WaitForJettison(Vessel v) | |
{ | |
yield return new WaitForEndOfFrame(); | |
var jettisons = v.FindPartModulesImplementing<ModuleJettison>(); | |
for (int i = jettisons.Count - 1; i >= 0; i--) | |
{ | |
ModuleJettison jet = jettisons[i]; | |
if (!jet.isJettisoned) | |
continue; | |
Debug.Log(string.Format("[RS_Jettison]: {0} - Jettison active: {1}", v.vesselName, jet.part.partInfo.title)); | |
string[] array = jet.jettisonName.Split(','); | |
int num = array.Length; | |
for (int j = 0; j < num; j++) | |
{ | |
Transform transform = jet.part.FindModelTransform(array[j]); | |
if (transform != null) | |
{ | |
if (transform.gameObject.activeInHierarchy) | |
{ | |
Debug.Log(string.Format("[RS_Jettison]: {0} - Jettison active: {1} - Disable transform: {2}" | |
, v.vesselName, jet.part.partInfo.title, array[j])); | |
jet.activejettisonName = array[j]; | |
transform.gameObject.SetActive(false); | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment