KSP-Conformal-Decals/Source/ConformalDecals/ModuleConformalDecalGeneric.cs
drewcassidy e9c8f3dafb Big refactor to enable preview materials
• add shader variants for decal previewing
• start to add code for part icon
• refactor material properties to be serializable
todo:
• fix decal preview scale (need to call UpdateScale on detached state)
• fix texture preview in part icon
• adjust culling per-object when rendering (turns out cull and ztest values are used by unity at the render time, not by the shader itself, so they can be adjusted in material property blocks!)
2020-06-04 00:12:09 -07:00

46 lines
1.6 KiB
C#

using ConformalDecals.MaterialModifiers;
using ConformalDecals.Util;
using UnityEngine;
namespace ConformalDecals {
public class ModuleConformalDecalGeneric : ModuleConformalDecalBase {
public override void OnLoad(ConfigNode node) {
base.OnLoad(node);
// set shader
materialProperties.SetShader(shader);
// add texture nodes
foreach (var textureNode in node.GetNodes("TEXTURE")) {
var textureProperty = ScriptableObject.CreateInstance<MaterialTextureProperty>();
textureProperty.ParseNode(textureNode);
materialProperties.AddProperty(textureProperty);
}
// add float nodes
foreach (var floatNode in node.GetNodes("FLOAT")) {
var floatProperty = ScriptableObject.CreateInstance<MaterialFloatProperty>();
floatProperty.ParseNode(floatNode);
materialProperties.AddProperty(floatProperty);
}
// add color nodes
foreach (var colorNode in node.GetNodes("COLOR")) {
var colorProperty = ScriptableObject.CreateInstance<MaterialColorProperty>();
colorProperty.ParseNode(colorNode);
materialProperties.AddProperty(colorProperty);
}
if (HighLogic.LoadedSceneIsGame) {
UpdateMaterials();
UpdateScale();
UpdateProjection();
}
}
public override void OnIconCreate() {
this.Log("called OnIconCreate");
OnStart(StartState.None);
UpdateScale();
}
}
}