public void copyOf(TelemetryUpdateData stockTUData) { //replace the mode button var customModeButton = stockTUData.modeButton.gameObject.AddComponent <CNCCommNetUIModeButton>(); customModeButton.copyOf(stockTUData.modeButton); UnityEngine.Object.DestroyImmediate(stockTUData.modeButton); this.modeButton = customModeButton; this.NOSIG = stockTUData.NOSIG; this.NOEP = stockTUData.NOEP; this.BLK = stockTUData.BLK; this.AUP = stockTUData.AUP; this.ADN = stockTUData.ADN; this.EP0 = stockTUData.EP0; this.EP1 = stockTUData.EP1; this.EP2 = stockTUData.EP2; this.CK1 = stockTUData.CK1; this.CK2 = stockTUData.CK2; this.CK3 = stockTUData.CK3; this.CP1 = stockTUData.CP1; this.CP2 = stockTUData.CP2; this.CP3 = stockTUData.CP3; this.SS0 = stockTUData.SS0; this.SS1 = stockTUData.SS1; this.SS2 = stockTUData.SS2; this.SS3 = stockTUData.SS3; this.SS4 = stockTUData.SS4; this.arrow_icon = stockTUData.arrow_icon; this.firstHop_icon = stockTUData.firstHop_icon; this.lastHop_icon = stockTUData.lastHop_icon; this.control_icon = stockTUData.control_icon; this.signal_icon = stockTUData.signal_icon; this.firstHop_tooltip = stockTUData.firstHop_tooltip; this.arrow_tooltip = stockTUData.arrow_tooltip; this.lastHop_tooltip = stockTUData.lastHop_tooltip; this.control_tooltip = stockTUData.control_tooltip; this.signal_tooltip = stockTUData.signal_tooltip; }
protected override void Start() { CNCCommNetScenario.Instance = this; this.commVessels = new List <CNCCommNetVessel>(); this.dirtyCommNetVesselList = true; CNCLog.Verbose("CommNet Scenario loading ..."); //Issue #13: Commnet behaves like vanilla when joining a DMP server for the second time. //if stock CommNet logic somehow runs (such as the order of CNCCommNetScenario and CommNetScenario in persisten.sfs) if (CommNetScenario.Instance != null) { UnityEngine.Object.DestroyImmediate(CommNetScenario.Instance); CNCCommNetScenario.Instance = this; } //Replace the CommNet user interface CommNetUI ui = FindObjectOfType <CommNetUI>(); // the order of the three lines is important CustomCommNetUI = gameObject.AddComponent <CNCCommNetUI>(); // gameObject.AddComponent<>() is "new" keyword for Monohebaviour class UnityEngine.Object.Destroy(ui); //Replace the CommNet network CommNetNetwork net = FindObjectOfType <CommNetNetwork>(); CustomCommNetNetwork = gameObject.AddComponent <CNCCommNetNetwork>(); UnityEngine.Object.Destroy(net); //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work //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 <CNCTelemetryUpdate>(); CustomCommNetTelemetry.copyOf(tempData); } else if (cnmodeUI != null && HighLogic.LoadedScene == GameScenes.TRACKSTATION) { CustomCommNetModeButton = cnmodeUI.gameObject.AddComponent <CNCCommNetUIModeButton>(); CustomCommNetModeButton.copyOf(cnmodeUI); UnityEngine.Object.DestroyImmediate(cnmodeUI); } //Replace the CommNet ground stations groundStations.Clear(); CommNetHome[] homes = FindObjectsOfType <CommNetHome>(); for (int i = 0; i < homes.Length; i++) { CNCCommNetHome customHome = homes[i].gameObject.AddComponent(typeof(CNCCommNetHome)) as CNCCommNetHome; customHome.copyOf(homes[i]); UnityEngine.Object.Destroy(homes[i]); groundStations.Add(customHome); } groundStations.Sort(); //Apply the ground-station changes from persistent.sfs for (int i = 0; i < persistentGroundStations.Count; i++) { if (groundStations.Exists(x => x.ID.Equals(persistentGroundStations[i].ID))) { groundStations.Find(x => x.ID.Equals(persistentGroundStations[i].ID)).applySavedChanges(persistentGroundStations[i]); } } persistentGroundStations.Clear();//dont need anymore //Replace the CommNet celestial bodies CommNetBody[] bodies = FindObjectsOfType <CommNetBody>(); for (int i = 0; i < bodies.Length; i++) { CNCCommNetBody customBody = bodies[i].gameObject.AddComponent(typeof(CNCCommNetBody)) as CNCCommNetBody; customBody.copyOf(bodies[i]); UnityEngine.Object.Destroy(bodies[i]); } //Imitate stock CommNetScenario.Instance in order to run certain stock functionalities //Comment: Vessel.GetControlLevel() has the check on CommNetScenario.Instance != null before calling vessel.connection.GetControlLevel() PropertyInfo property = typeof(CommNetScenario).GetProperty("Instance"); property.DeclaringType.GetProperty("Instance"); property.SetValue(CommNetScenario.Instance, this, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null); CNCLog.Verbose("CommNet Scenario loading done!"); }
protected override void Start() { CNCCommNetScenario.Instance = this; this.commVessels = new List <CNCCommNetVessel>(); this.dirtyCommNetVesselList = true; CNCLog.Verbose("CommNet Scenario loading ..."); //Replace the CommNet user interface CommNetUI ui = FindObjectOfType <CommNetUI>(); // the order of the three lines is important CustomCommNetUI = gameObject.AddComponent <CNCCommNetUI>(); // gameObject.AddComponent<>() is "new" keyword for Monohebaviour class UnityEngine.Object.Destroy(ui); //Replace the CommNet network CommNetNetwork net = FindObjectOfType <CommNetNetwork>(); CustomCommNetNetwork = gameObject.AddComponent <CNCCommNetNetwork>(); UnityEngine.Object.Destroy(net); //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work //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 <CNCTelemetryUpdate>(); CustomCommNetTelemetry.copyOf(tempData); } else if (cnmodeUI != null && HighLogic.LoadedScene == GameScenes.TRACKSTATION) { CustomCommNetModeButton = cnmodeUI.gameObject.AddComponent <CNCCommNetUIModeButton>(); CustomCommNetModeButton.copyOf(cnmodeUI); UnityEngine.Object.DestroyImmediate(cnmodeUI); } //Replace the CommNet ground stations groundStations.Clear(); CommNetHome[] homes = FindObjectsOfType <CommNetHome>(); for (int i = 0; i < homes.Length; i++) { CNCCommNetHome customHome = homes[i].gameObject.AddComponent(typeof(CNCCommNetHome)) as CNCCommNetHome; customHome.copyOf(homes[i]); UnityEngine.Object.Destroy(homes[i]); groundStations.Add(customHome); } groundStations.Sort(); //Apply the ground-station changes from persistent.sfs for (int i = 0; i < persistentGroundStations.Count; i++) { if (groundStations.Exists(x => x.ID.Equals(persistentGroundStations[i].ID))) { groundStations.Find(x => x.ID.Equals(persistentGroundStations[i].ID)).applySavedChanges(persistentGroundStations[i]); } } persistentGroundStations.Clear();//dont need anymore //Replace the CommNet celestial bodies CommNetBody[] bodies = FindObjectsOfType <CommNetBody>(); for (int i = 0; i < bodies.Length; i++) { CNCCommNetBody customBody = bodies[i].gameObject.AddComponent(typeof(CNCCommNetBody)) as CNCCommNetBody; customBody.copyOf(bodies[i]); UnityEngine.Object.Destroy(bodies[i]); } CNCLog.Verbose("CommNet Scenario loading done!"); }