protected override void Start() { CNVCommNetScenario.Instance = this; UnityEngine.Debug.Log("CommNet Scenario loading ..."); //Replace the CommNet user interface CommNetUI ui = FindObjectOfType <CommNetUI>(); // the order of the three lines is important CustomCommNetUI = gameObject.AddComponent <CNVCommNetUI>(); // gameObject.AddComponent<>() is "new" keyword for Monohebaviour class UnityEngine.Object.Destroy(ui); //Replace the TelemetryUpdate TelemetryUpdate tel = TelemetryUpdate.Instance; //only appear in flight CommNetUIModeButton cnmodeUI = FindObjectOfType <CommNetUIModeButton>(); //only appear in tracking station; initialised separately by TelemetryUpdate in flight if (tel != null && HighLogic.LoadedSceneIsFlight) { TelemetryUpdateData tempData = new TelemetryUpdateData(tel); UnityEngine.Object.DestroyImmediate(tel); //seem like UE won't initialise CNCTelemetryUpdate instance in presence of TelemetryUpdate instance CustomCommNetTelemetry = gameObject.AddComponent <CNVTelemetryUpdate>(); CustomCommNetTelemetry.copyOf(tempData); } else if (cnmodeUI != null && HighLogic.LoadedScene == GameScenes.TRACKSTATION) { CustomCommNetModeButton = cnmodeUI.gameObject.AddComponent <CNVCommNetUIModeButton>(); CustomCommNetModeButton.copyOf(cnmodeUI); UnityEngine.Object.DestroyImmediate(cnmodeUI); } UnityEngine.Debug.Log("CommNet Scenario loading done! "); }
private void OnDestroy() { if (CNVCommNetScenario.Instance == this) { if (this.CustomCommNetUI != null) { UnityEngine.Object.Destroy(this.CustomCommNetUI); } if (this.CustomCommNetTelemetry != null) { UnityEngine.Object.Destroy(this.CustomCommNetTelemetry); } if (this.CustomCommNetModeButton != null) { UnityEngine.Object.Destroy(this.CustomCommNetModeButton); } CNVCommNetScenario.Instance = null; } }
public override void OnAwake() { CNVCommNetScenario.Instance = this; //override to turn off CommNetScenario's instance check }