diff --git a/GameData/ConformalDecals/Plugins/ConformalDecals.dll b/GameData/ConformalDecals/Plugins/ConformalDecals.dll index 2286ffc..a42d00a 100644 Binary files a/GameData/ConformalDecals/Plugins/ConformalDecals.dll and b/GameData/ConformalDecals/Plugins/ConformalDecals.dll differ diff --git a/GameData/ConformalDecals/Resources/ConformalDecals.cfg b/GameData/ConformalDecals/Resources/ConformalDecals.cfg index 72c6e59..bed0e9c 100644 --- a/GameData/ConformalDecals/Resources/ConformalDecals.cfg +++ b/GameData/ConformalDecals/Resources/ConformalDecals.cfg @@ -1,4 +1,7 @@ CONFORMALDECALS { + decalLayer = 31 + selectableInFlight = false + SHADERBLACKLIST { shader = DepthMask shader = KSP/Alpha/Cutoff diff --git a/Source/ConformalDecals/DecalConfig.cs b/Source/ConformalDecals/DecalConfig.cs index 9304988..ca35d8d 100644 --- a/Source/ConformalDecals/DecalConfig.cs +++ b/Source/ConformalDecals/DecalConfig.cs @@ -6,11 +6,15 @@ namespace ConformalDecals { public static class DecalConfig { private static Texture2D _blankNormal; private static List _shaderBlacklist; - private static int _decalLayer = 31; + private static int _decalLayer = 31; + private static bool _selectableInFlight = false; public static Texture2D BlankNormal => _blankNormal; + public static int DecalLayer => _decalLayer; + public static bool SelectableInFlight => _selectableInFlight; + public static bool IsBlacklisted(Shader shader) { return IsBlacklisted(shader.name); } @@ -26,6 +30,7 @@ namespace ConformalDecals { } ParseUtil.ParseIntIndirect(ref _decalLayer, node, "decalLayer"); + ParseUtil.ParseBoolIndirect(ref _selectableInFlight, node, "selectableInFlight"); } } diff --git a/Source/ConformalDecals/ModuleConformalDecal.cs b/Source/ConformalDecals/ModuleConformalDecal.cs index 9a997c0..c5b06e2 100644 --- a/Source/ConformalDecals/ModuleConformalDecal.cs +++ b/Source/ConformalDecals/ModuleConformalDecal.cs @@ -237,13 +237,7 @@ namespace ConformalDecals { public override void OnStart(StartState state) { this.Log("Starting module"); - // handle tweakables - if (HighLogic.LoadedSceneIsEditor) { - GameEvents.onEditorPartEvent.Add(OnEditorEvent); - GameEvents.onVariantApplied.Add(OnVariantApplied); - UpdateTweakables(); - } materialProperties.RenderQueue = DecalQueue; @@ -261,19 +255,39 @@ namespace ConformalDecals { } } + // handle tweakables + if (HighLogic.LoadedSceneIsEditor) { + GameEvents.onEditorPartEvent.Add(OnEditorEvent); + GameEvents.onVariantApplied.Add(OnVariantApplied); + + UpdateTweakables(); + } + + // handle flight events if (HighLogic.LoadedSceneIsFlight) { + GameEvents.onPartWillDie.Add(OnPartWillDie); + Part.layerMask |= 1 << DecalConfig.DecalLayer; decalColliderTransform.gameObject.layer = DecalConfig.DecalLayer; - if (!selectableInFlight) { + + if (!selectableInFlight || !DecalConfig.SelectableInFlight) { decalColliderTransform.GetComponent().enabled = false; } + + if (part.parent == null) part.explode(); } } public virtual void OnDestroy() { // remove GameEvents - GameEvents.onEditorPartEvent.Remove(OnEditorEvent); - GameEvents.onVariantApplied.Remove(OnVariantApplied); + if (HighLogic.LoadedSceneIsEditor) { + GameEvents.onEditorPartEvent.Remove(OnEditorEvent); + GameEvents.onVariantApplied.Remove(OnVariantApplied); + } + + if (HighLogic.LoadedSceneIsFlight) { + GameEvents.onPartWillDie.Remove(OnPartWillDie); + } // remove from preCull delegate Camera.onPreCull -= Render; @@ -332,6 +346,13 @@ namespace ConformalDecals { } } + protected void OnPartWillDie(Part willDie) { + if (willDie == part.parent) { + this.Log("Parent part about to be destroyed! Killing decal part."); + part.Die(); + } + } + protected void OnAttach() { if (part.parent == null) { this.LogError("Attach function called but part has no parent!");