mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Fix OnDestroy not being called
This commit is contained in:
parent
2cca6c37bb
commit
dfdf280564
@ -14,6 +14,10 @@ All notable changes to this project will be documented in this file
|
||||
|
||||
- Updated bundled Shabby to 0.3.0. Does not affect CKAN users
|
||||
|
||||
### Fixed
|
||||
|
||||
- Reverted some changes from last version that were causing issues on launch
|
||||
|
||||
|
||||
## 0.2.11 - 2022-10-30
|
||||
|
||||
|
@ -122,8 +122,7 @@ namespace ConformalDecals {
|
||||
|
||||
if (materialProperties == null) {
|
||||
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
||||
}
|
||||
}
|
||||
@ -153,14 +152,12 @@ namespace ConformalDecals {
|
||||
if (backRenderer == null) {
|
||||
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
|
||||
updateBackScale = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
backMaterial = backRenderer.material;
|
||||
if (backMaterial == null) {
|
||||
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
|
||||
updateBackScale = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
|
||||
}
|
||||
}
|
||||
@ -201,12 +198,10 @@ namespace ConformalDecals {
|
||||
|
||||
if (tileRect.x >= 0) {
|
||||
materialProperties.UpdateTile(tileRect);
|
||||
}
|
||||
else if (tileIndex >= 0) {
|
||||
} else if (tileIndex >= 0) {
|
||||
materialProperties.UpdateTile(tileIndex, tileSize);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
this.LogException("Exception parsing partmodule", e);
|
||||
}
|
||||
|
||||
@ -222,8 +217,7 @@ namespace ConformalDecals {
|
||||
|
||||
if (HighLogic.LoadedSceneIsGame) {
|
||||
UpdateScale();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
scale = defaultScale;
|
||||
depth = defaultDepth;
|
||||
opacity = defaultOpacity;
|
||||
@ -261,8 +255,7 @@ namespace ConformalDecals {
|
||||
// set initial attachment state
|
||||
if (part.parent == null) {
|
||||
OnDetach();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
OnAttach();
|
||||
}
|
||||
}
|
||||
@ -283,7 +276,7 @@ namespace ConformalDecals {
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDestroy() {
|
||||
public virtual void OnDestroy() {
|
||||
// remove GameEvents
|
||||
if (HighLogic.LoadedSceneIsEditor) {
|
||||
GameEvents.onEditorPartEvent.Remove(OnEditorEvent);
|
||||
@ -440,11 +433,13 @@ namespace ConformalDecals {
|
||||
|
||||
// update projection
|
||||
foreach (var target in _targets) {
|
||||
if (target != null)
|
||||
if (target == null) {
|
||||
_targets.Remove(target);
|
||||
} else {
|
||||
target.Project(_orthoMatrix, decalProjectorTransform, _boundsRenderer.bounds, useBaseNormal);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// rescale preview model
|
||||
decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2);
|
||||
|
||||
@ -472,8 +467,7 @@ namespace ConformalDecals {
|
||||
protected void UpdateTargets() {
|
||||
if (_targets == null) {
|
||||
_targets = new List<ProjectionTarget>();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_targets.Clear();
|
||||
}
|
||||
|
||||
@ -482,7 +476,7 @@ namespace ConformalDecals {
|
||||
foreach (var renderer in renderers) {
|
||||
// skip disabled renderers
|
||||
if (renderer.gameObject.activeInHierarchy == false) continue;
|
||||
|
||||
|
||||
// skip blacklisted shaders
|
||||
if (DecalConfig.IsBlacklisted(renderer.material.shader)) continue;
|
||||
|
||||
@ -578,8 +572,11 @@ namespace ConformalDecals {
|
||||
|
||||
// render on each target object
|
||||
foreach (var target in _targets) {
|
||||
if (target != null)
|
||||
if (target == null) {
|
||||
_targets.Remove(target);
|
||||
} else {
|
||||
target.Render(_decalMaterial, part.mpb, camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace ConformalDecals {
|
||||
if (HighLogic.LoadedSceneIsEditor) {
|
||||
// Register flag change event
|
||||
GameEvents.onMissionFlagSelect.Add(OnEditorFlagSelected);
|
||||
|
||||
|
||||
// Register reset button event
|
||||
Events[nameof(ResetFlag)].guiActiveEditor = useCustomFlag;
|
||||
}
|
||||
@ -48,19 +48,21 @@ namespace ConformalDecals {
|
||||
UpdateFlag();
|
||||
}
|
||||
|
||||
public void OnDestroy() {
|
||||
public virtual void OnDestroy() {
|
||||
if (HighLogic.LoadedSceneIsEditor) {
|
||||
// Unregister flag change event
|
||||
GameEvents.onMissionFlagSelect.Remove(OnEditorFlagSelected);
|
||||
}
|
||||
}
|
||||
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
|
||||
public void SelectFlag() {
|
||||
// Button for selecting a flag
|
||||
// This is a bit of a hack to bring up the stock flag selection menu
|
||||
// When its done, it calls OnCustomFlagSelected()
|
||||
|
||||
|
||||
// ReSharper disable once PossibleNullReferenceException
|
||||
var flagBrowser = (Instantiate((Object) (new FlagBrowserGUIButton(null, null, null, null)).FlagBrowserPrefab) as GameObject).GetComponent<FlagBrowser>();
|
||||
flagBrowser.OnFlagSelected = OnCustomFlagSelected;
|
||||
@ -68,24 +70,24 @@ namespace ConformalDecals {
|
||||
|
||||
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-reset-flag")]
|
||||
public void ResetFlag() {
|
||||
|
||||
|
||||
// we are no longer using a custom flag, so instead use the mission or agency flag
|
||||
useCustomFlag = false;
|
||||
flagUrl = "Mission";
|
||||
UpdateFlag(true);
|
||||
|
||||
|
||||
// disable the reset button, since it no longer makes sense
|
||||
Events[nameof(ResetFlag)].guiActiveEditor = false;
|
||||
}
|
||||
|
||||
private void OnCustomFlagSelected(FlagBrowser.FlagEntry newFlagEntry) {
|
||||
// Callback for when a flag is selected in the menu spawned by SelectFlag()
|
||||
|
||||
|
||||
// we are now using a custom flag with the URL of the new flag entry
|
||||
useCustomFlag = true;
|
||||
flagUrl = newFlagEntry.textureInfo.name;
|
||||
UpdateFlag(true);
|
||||
|
||||
|
||||
// make sure the reset button is now available
|
||||
Events[nameof(ResetFlag)].guiActiveEditor = true;
|
||||
}
|
||||
@ -103,16 +105,15 @@ namespace ConformalDecals {
|
||||
private void UpdateFlag(bool recursive = false) {
|
||||
// get the decal material property for the decal texture
|
||||
var textureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
||||
|
||||
if(useCustomFlag) {
|
||||
|
||||
if (useCustomFlag) {
|
||||
// set the texture to the custom flag
|
||||
textureProperty.TextureUrl = flagUrl;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// set the texture to the mission flag
|
||||
textureProperty.TextureUrl = MissionFlagUrl;
|
||||
}
|
||||
|
||||
|
||||
UpdateMaterials();
|
||||
UpdateScale();
|
||||
|
||||
@ -120,7 +121,7 @@ namespace ConformalDecals {
|
||||
// for each symmetry counterpart, copy this part's properties and update it in turn
|
||||
foreach (var counterpart in part.symmetryCounterparts) {
|
||||
var decal = counterpart.GetComponent<ModuleConformalFlag>();
|
||||
|
||||
|
||||
decal.useCustomFlag = useCustomFlag;
|
||||
decal.flagUrl = flagUrl;
|
||||
decal.UpdateFlag();
|
||||
|
@ -227,6 +227,8 @@ namespace ConformalDecals {
|
||||
if (_textEntryController != null) _textEntryController.Close();
|
||||
if (_fillColorPickerController != null) _fillColorPickerController.Close();
|
||||
if (_outlineColorPickerController != null) _outlineColorPickerController.Close();
|
||||
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
protected override void OnDetach() {
|
||||
|
Loading…
Reference in New Issue
Block a user