|
|
@ -5,7 +5,7 @@ using ConformalDecals.Util;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ConformalDecals {
|
|
|
|
namespace ConformalDecals {
|
|
|
|
public abstract class ModuleConformalDecalBase : PartModule {
|
|
|
|
public class ModuleConformalDecal : PartModule {
|
|
|
|
[KSPField(guiName = "#LOC_ConformalDecals_gui-scale", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F2", guiUnits = "m"),
|
|
|
|
[KSPField(guiName = "#LOC_ConformalDecals_gui-scale", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F2", guiUnits = "m"),
|
|
|
|
UI_FloatRange(stepIncrement = 0.05f)]
|
|
|
|
UI_FloatRange(stepIncrement = 0.05f)]
|
|
|
|
public float scale = 1.0f;
|
|
|
|
public float scale = 1.0f;
|
|
|
@ -76,10 +76,23 @@ namespace ConformalDecals {
|
|
|
|
return _decalQueueCounter;
|
|
|
|
return _decalQueueCounter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnAwake() {
|
|
|
|
|
|
|
|
base.OnAwake();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (materialProperties == null) {
|
|
|
|
|
|
|
|
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnLoad(ConfigNode node) {
|
|
|
|
public override void OnLoad(ConfigNode node) {
|
|
|
|
this.Log("Loading module");
|
|
|
|
this.Log("Loading module");
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// SETUP TRANSFORMS
|
|
|
|
|
|
|
|
|
|
|
|
// find front transform
|
|
|
|
// find front transform
|
|
|
|
decalFrontTransform = part.FindModelTransform(decalFront);
|
|
|
|
decalFrontTransform = part.FindModelTransform(decalFront);
|
|
|
|
if (decalFrontTransform == null) throw new FormatException($"Could not find decalFront transform: '{decalFront}'.");
|
|
|
|
if (decalFrontTransform == null) throw new FormatException($"Could not find decalFront transform: '{decalFront}'.");
|
|
|
@ -135,34 +148,52 @@ namespace ConformalDecals {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DecalIconFixer.QueuePart(part.name);
|
|
|
|
// PARSE MATERIAL PROPERTIES
|
|
|
|
|
|
|
|
|
|
|
|
// set shader
|
|
|
|
// set shader
|
|
|
|
materialProperties.SetShader(shader);
|
|
|
|
materialProperties.SetShader(shader);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add texture nodes
|
|
|
|
|
|
|
|
foreach (var textureNode in node.GetNodes("TEXTURE")) {
|
|
|
|
|
|
|
|
materialProperties.ParseProperty<MaterialTextureProperty>(textureNode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add float nodes
|
|
|
|
|
|
|
|
foreach (var floatNode in node.GetNodes("FLOAT")) {
|
|
|
|
|
|
|
|
materialProperties.ParseProperty<MaterialTextureProperty>(floatNode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add color nodes
|
|
|
|
|
|
|
|
foreach (var colorNode in node.GetNodes("COLOR")) {
|
|
|
|
|
|
|
|
materialProperties.ParseProperty<MaterialColorProperty>(colorNode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tileString = node.GetValue("tile");
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(tileString)) {
|
|
|
|
|
|
|
|
var tileValid = ParseExtensions.TryParseRect(tileString, out var tile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!tileValid) throw new FormatException($"Improperly formatted value for tile '{tileString}");
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
materialProperties.UpdateTile(tile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// QUEUE PART FOR ICON FIXING IN VAB
|
|
|
|
|
|
|
|
DecalIconFixer.QueuePart(part.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
catch (Exception e) {
|
|
|
|
this.LogException("Exception parsing partmodule", e);
|
|
|
|
this.LogException("Exception parsing partmodule", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (HighLogic.LoadedSceneIsGame) {
|
|
|
|
if (HighLogic.LoadedSceneIsGame) {
|
|
|
|
UpdateMaterials();
|
|
|
|
UpdateMaterials();
|
|
|
|
UpdateScale();
|
|
|
|
UpdateScale();
|
|
|
|
UpdateProjection();
|
|
|
|
UpdateProjection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
UpdateScale();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnAwake() {
|
|
|
|
public override void OnIconCreate() {
|
|
|
|
base.OnAwake();
|
|
|
|
UpdateScale();
|
|
|
|
|
|
|
|
|
|
|
|
if (materialProperties == null) {
|
|
|
|
|
|
|
|
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnStart(StartState state) {
|
|
|
|
public override void OnStart(StartState state) {
|
|
|
@ -175,11 +206,11 @@ namespace ConformalDecals {
|
|
|
|
|
|
|
|
|
|
|
|
UpdateTweakables();
|
|
|
|
UpdateTweakables();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
materialProperties.SetRenderQueue(DecalQueue);
|
|
|
|
materialProperties.SetRenderQueue(DecalQueue);
|
|
|
|
|
|
|
|
|
|
|
|
UpdateMaterials();
|
|
|
|
UpdateMaterials();
|
|
|
|
|
|
|
|
|
|
|
|
if (HighLogic.LoadedSceneIsGame) {
|
|
|
|
if (HighLogic.LoadedSceneIsGame) {
|
|
|
|
// set initial attachment state
|
|
|
|
// set initial attachment state
|
|
|
|
if (part.parent == null) {
|
|
|
|
if (part.parent == null) {
|
|
|
@ -312,7 +343,7 @@ namespace ConformalDecals {
|
|
|
|
materialProperties.UpdateMaterials();
|
|
|
|
materialProperties.UpdateMaterials();
|
|
|
|
materialProperties.SetOpacity(opacity);
|
|
|
|
materialProperties.SetOpacity(opacity);
|
|
|
|
materialProperties.SetCutoff(cutoff);
|
|
|
|
materialProperties.SetCutoff(cutoff);
|
|
|
|
|
|
|
|
|
|
|
|
_decalMaterial = materialProperties.DecalMaterial;
|
|
|
|
_decalMaterial = materialProperties.DecalMaterial;
|
|
|
|
_previewMaterial = materialProperties.PreviewMaterial;
|
|
|
|
_previewMaterial = materialProperties.PreviewMaterial;
|
|
|
|
|
|
|
|
|