From 253a54a9ea8f3f3c67facc39ac74fc2804ad6d5c Mon Sep 17 00:00:00 2001 From: KSP-TaxiService Date: Wed, 18 Mar 2020 00:10:12 +0800 Subject: [PATCH] Add functionality to delete stock CommNetVessel instances from CommNet network --- .../CommNetLayer/CNCCommNetVessel.cs | 22 ++++++++++++++++++- .../CommNetLayer/CNCCommNetwork.cs | 5 +++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs index bf4d751..3428ddd 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs @@ -93,7 +93,7 @@ public enum FrequencyListOperation public bool IsCommandable = true; /// - /// Retrieve the CNC data from the vessel + /// Retrieve the CNC data from the vessel, in addition of stock network joining /// protected override void OnNetworkInitialized() { @@ -140,6 +140,26 @@ protected override void OnNetworkInitialized() } } + protected override void OnAwake() + { + base.OnAwake(); + } + + protected override void OnStart() + { + if (this.vessel != null) + { + //if this connection is stock, replace it with this custom connection + if (this.vessel.connection != null && this.vessel.connection is CommNetVessel && CommNetNetwork.Initialized) + { + CommNetNetwork.Remove(this.vessel.connection.Comm); //delete stock node from commnet network + //UnityEngine.Object.DestroyObject(this.vessel.connection); // don't do this. there are still action-call leftovers of stock CommNetVessel + this.vessel.connection = this; + } + } + base.OnStart(); + } + protected override void OnDestroy() { base.OnDestroy(); diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetwork.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetwork.cs index c2dca75..d105d44 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetwork.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetwork.cs @@ -41,6 +41,11 @@ protected override bool SetNodeConnection(CommNode a, CommNode b) { this.Disconnect(a, b, true); } + // disconnect connection between "itself" + else if (AreSame(a, b)) + { + this.Disconnect(a, b, true); + } else { //each CommNode has at least some frequencies?