Clear targets on attach

feature-multiProject
Andrew Cassidy 3 years ago
parent 7b9ed99325
commit 7406fa613b

@ -298,7 +298,7 @@ namespace ConformalDecals {
if (this.part == eventPart) { if (this.part == eventPart) {
OnAttach(); OnAttach();
} }
else if (projectMultiple) { else if (_isAttached && projectMultiple) {
UpdatePartTarget(eventPart, _boundsRenderer.bounds); UpdatePartTarget(eventPart, _boundsRenderer.bounds);
// recursively call for child parts // recursively call for child parts
foreach (var child in eventPart.children) { foreach (var child in eventPart.children) {
@ -312,7 +312,7 @@ namespace ConformalDecals {
if (this.part == eventPart) { if (this.part == eventPart) {
OnDetach(); OnDetach();
} }
else if (projectMultiple) { else if (_isAttached && projectMultiple) {
_targets.Remove(eventPart); _targets.Remove(eventPart);
// recursively call for child parts // recursively call for child parts
foreach (var child in eventPart.children) { foreach (var child in eventPart.children) {
@ -327,7 +327,7 @@ namespace ConformalDecals {
this.Log("Parent part about to be destroyed! Killing decal part."); this.Log("Parent part about to be destroyed! Killing decal part.");
part.Die(); part.Die();
} }
else if (projectMultiple) { else if (_isAttached && projectMultiple) {
_targets.Remove(willDie); _targets.Remove(willDie);
} }
} }
@ -341,6 +341,7 @@ namespace ConformalDecals {
} }
_isAttached = true; _isAttached = true;
_targets.Clear();
// hide model // hide model
decalModelTransform.gameObject.SetActive(false); decalModelTransform.gameObject.SetActive(false);
@ -620,9 +621,13 @@ namespace ConformalDecals {
/// Called when updating decal targets /// Called when updating decal targets
protected void UpdateTargets() { protected void UpdateTargets() {
if (!_isAttached) return; if (!_isAttached) return;
var projectionBounds = _boundsRenderer.bounds; var projectionBounds = _boundsRenderer.bounds;
// disable all targets
foreach (var target in _targets.Values) {
target.enabled = false;
}
// collect list of potential targets // collect list of potential targets
IEnumerable<Part> targetParts; IEnumerable<Part> targetParts;
if (projectMultiple) { if (projectMultiple) {

@ -40,6 +40,8 @@ namespace ConformalDecals {
} }
public void Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) { public void Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
if (!enabled) return;
foreach (var target in meshTargets) { foreach (var target in meshTargets) {
target.Render(decalMaterial, partMPB, camera); target.Render(decalMaterial, partMPB, camera);
} }

Loading…
Cancel
Save