Run some logic only at startup

feature-better-tweakables
Andrew Cassidy 3 years ago
parent 6ee52ac18e
commit f20119565f

@ -71,16 +71,19 @@ namespace ConformalDecals {
[KSPField(guiName = "#LOC_ConformalDecals_gui-opacity", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"), [KSPField(guiName = "#LOC_ConformalDecals_gui-opacity", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
UI_FloatRange()] UI_FloatRange()]
public float opacity = 1.0f; public float opacity = 1.0f;
private MaterialFloatProperty _opacityProperty; private MaterialFloatProperty _opacityProperty;
[KSPField(guiName = "#LOC_ConformalDecals_gui-cutoff", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"), [KSPField(guiName = "#LOC_ConformalDecals_gui-cutoff", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
UI_FloatRange()] UI_FloatRange()]
public float cutoff = 0.5f; public float cutoff = 0.5f;
private MaterialFloatProperty _cutoffProperty; private MaterialFloatProperty _cutoffProperty;
[KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"), [KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"),
UI_FloatRange()] UI_FloatRange()]
public float wear = 100; public float wear = 100;
private MaterialFloatProperty _wearProperty; private MaterialFloatProperty _wearProperty;
[KSPField(guiName = "#LOC_ConformalDecals_gui-multiproject", guiActive = false, guiActiveEditor = true, isPersistant = true), [KSPField(guiName = "#LOC_ConformalDecals_gui-multiproject", guiActive = false, guiActiveEditor = true, isPersistant = true),
@ -380,36 +383,38 @@ namespace ConformalDecals {
/// Load any settings from the decal config /// Load any settings from the decal config
protected virtual void LoadDecal(ConfigNode node) { protected virtual void LoadDecal(ConfigNode node) {
// PARSE TRANSFORMS // PARSE TRANSFORMS
decalFrontTransform = part.FindModelTransform(decalFront); if (!HighLogic.LoadedSceneIsGame) {
if (decalFrontTransform == null) throw new FormatException($"Could not find decalFront transform: '{decalFront}'."); decalFrontTransform = part.FindModelTransform(decalFront);
if (decalFrontTransform == null) throw new FormatException($"Could not find decalFront transform: '{decalFront}'.");
decalBackTransform = part.FindModelTransform(decalBack); decalBackTransform = part.FindModelTransform(decalBack);
if (decalBackTransform == null) throw new FormatException($"Could not find decalBack transform: '{decalBack}'."); if (decalBackTransform == null) throw new FormatException($"Could not find decalBack transform: '{decalBack}'.");
decalModelTransform = part.FindModelTransform(decalModel); decalModelTransform = part.FindModelTransform(decalModel);
if (decalModelTransform == null) throw new FormatException($"Could not find decalModel transform: '{decalModel}'."); if (decalModelTransform == null) throw new FormatException($"Could not find decalModel transform: '{decalModel}'.");
decalProjectorTransform = part.FindModelTransform(decalProjector); decalProjectorTransform = part.FindModelTransform(decalProjector);
if (decalProjectorTransform == null) throw new FormatException($"Could not find decalProjector transform: '{decalProjector}'."); if (decalProjectorTransform == null) throw new FormatException($"Could not find decalProjector transform: '{decalProjector}'.");
decalColliderTransform = part.FindModelTransform(decalCollider); decalColliderTransform = part.FindModelTransform(decalCollider);
if (decalColliderTransform == null) throw new FormatException($"Could not find decalCollider transform: '{decalCollider}'."); if (decalColliderTransform == null) throw new FormatException($"Could not find decalCollider transform: '{decalCollider}'.");
// SETUP BACK MATERIAL // SETUP BACK MATERIAL
if (updateBackScale) { if (updateBackScale) {
var backRenderer = decalBackTransform.GetComponent<MeshRenderer>(); var backRenderer = decalBackTransform.GetComponent<MeshRenderer>();
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;
}
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; updateBackScale = false;
} }
else { else {
if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex); 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 {
if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
}
} }
} }
} }
@ -553,7 +558,7 @@ namespace ConformalDecals {
_opacityProperty.value = opacity; _opacityProperty.value = opacity;
_cutoffProperty.value = cutoff; _cutoffProperty.value = cutoff;
_wearProperty.value = wear; _wearProperty.value = wear;
materialProperties.UpdateMaterials(); materialProperties.UpdateMaterials();
_decalMaterial = materialProperties.DecalMaterial; _decalMaterial = materialProperties.DecalMaterial;
@ -598,14 +603,14 @@ namespace ConformalDecals {
// update material scale // update material scale
materialProperties.UpdateScale(size); materialProperties.UpdateScale(size);
decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth);
if (_isAttached) { if (_isAttached) {
// update orthogonal matrix // update orthogonal matrix
_orthoMatrix = Matrix4x4.identity; _orthoMatrix = Matrix4x4.identity;
_orthoMatrix[0, 3] = 0.5f; _orthoMatrix[0, 3] = 0.5f;
_orthoMatrix[1, 3] = 0.5f; _orthoMatrix[1, 3] = 0.5f;
decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth);
var projectionBounds = _boundsRenderer.bounds; var projectionBounds = _boundsRenderer.bounds;
// disable all targets // disable all targets

Loading…
Cancel
Save