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