mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Get flag module working
This commit is contained in:
@ -60,12 +60,6 @@ namespace ConformalDecals {
|
||||
private Bounds _decalBounds;
|
||||
private Vector2 _backTextureBaseScale;
|
||||
|
||||
public ModuleConformalDecalBase() {
|
||||
decalBackTransform = null;
|
||||
decalModelTransform = null;
|
||||
decalProjectorTransform = null;
|
||||
}
|
||||
|
||||
private int DecalQueue {
|
||||
get {
|
||||
_decalQueueCounter++;
|
||||
@ -83,36 +77,6 @@ namespace ConformalDecals {
|
||||
if (HighLogic.LoadedSceneIsEditor) {
|
||||
UpdateTweakables();
|
||||
}
|
||||
|
||||
if (materialProperties == null) {
|
||||
// materialProperties is null, so make a new one
|
||||
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
|
||||
materialProperties.Initialize();
|
||||
}
|
||||
else {
|
||||
// materialProperties already exists, so make a copy
|
||||
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
||||
}
|
||||
|
||||
// set shader
|
||||
materialProperties.SetShader(decalShader);
|
||||
|
||||
// get back material if necessary
|
||||
if (updateBackScale) {
|
||||
this.Log("Getting material and base scale for back material");
|
||||
var backRenderer = decalBackTransform.GetComponent<MeshRenderer>();
|
||||
if (backRenderer == null) {
|
||||
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
|
||||
updateBackScale = false;
|
||||
}
|
||||
else if ((backMaterial = backRenderer.material) == null) {
|
||||
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
|
||||
updateBackScale = false;
|
||||
}
|
||||
else {
|
||||
_backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
|
||||
}
|
||||
}
|
||||
|
||||
// find front transform
|
||||
decalFrontTransform = part.FindModelTransform(decalFront);
|
||||
@ -148,6 +112,26 @@ namespace ConformalDecals {
|
||||
decalProjectorTransform = part.FindModelTransform(decalProjector);
|
||||
if (decalProjectorTransform == null) throw new FormatException($"Could not find decalProjector transform: '{decalProjector}'.");
|
||||
}
|
||||
|
||||
// get back material if necessary
|
||||
if (updateBackScale) {
|
||||
this.Log("Getting material and base scale for back material");
|
||||
var backRenderer = decalBackTransform.GetComponent<MeshRenderer>();
|
||||
if (backRenderer == null) {
|
||||
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;
|
||||
}
|
||||
else {
|
||||
_backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update EVERYTHING if currently attached
|
||||
if (_isAttached) {
|
||||
|
||||
@ -5,15 +5,24 @@ using UnityEngine;
|
||||
|
||||
namespace ConformalDecals {
|
||||
public class ModuleConformalDecalFlag : ModuleConformalDecalBase {
|
||||
|
||||
[KSPField]
|
||||
private MaterialTextureProperty _flagTextureProperty;
|
||||
[KSPField] public MaterialTextureProperty flagTextureProperty;
|
||||
|
||||
public override void OnLoad(ConfigNode node) {
|
||||
base.OnLoad(node);
|
||||
|
||||
_flagTextureProperty = new MaterialTextureProperty("_MainTex", Texture2D.whiteTexture);
|
||||
materialProperties.AddProperty(_flagTextureProperty);
|
||||
if (materialProperties == null) {
|
||||
// materialProperties is null, so make a new one
|
||||
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
|
||||
materialProperties.Initialize();
|
||||
}
|
||||
else {
|
||||
// materialProperties already exists, so make a copy
|
||||
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
||||
}
|
||||
|
||||
// set shader
|
||||
materialProperties.SetShader(decalShader);
|
||||
|
||||
base.OnLoad(node);
|
||||
}
|
||||
|
||||
public override void OnStart(StartState state) {
|
||||
@ -24,7 +33,21 @@ namespace ConformalDecals {
|
||||
}
|
||||
|
||||
private void UpdateFlag(string flagUrl) {
|
||||
_flagTextureProperty.texture = GameDatabase.Instance.GetTexture(flagUrl, false);
|
||||
this.Log($"Loading flag texture '{flagUrl}'.");
|
||||
var flagTexture = GameDatabase.Instance.GetTexture(flagUrl, false);
|
||||
if (flagTexture == null) {
|
||||
this.LogWarning($"Unable to find flag texture '{flagUrl}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (flagTextureProperty == null) {
|
||||
this.Log("Initializing flag property");
|
||||
flagTextureProperty = new MaterialTextureProperty("_Decal", flagTexture, isMain: true);
|
||||
materialProperties.AddProperty(flagTextureProperty);
|
||||
}
|
||||
else {
|
||||
flagTextureProperty.texture = flagTexture;
|
||||
}
|
||||
|
||||
materialProperties.UpdateMaterials();
|
||||
}
|
||||
|
||||
@ -5,8 +5,19 @@ using UnityEngine;
|
||||
namespace ConformalDecals {
|
||||
public class ModuleConformalDecalGeneric : ModuleConformalDecalBase {
|
||||
public override void OnLoad(ConfigNode node) {
|
||||
base.OnLoad(node);
|
||||
|
||||
if (materialProperties == null) {
|
||||
// materialProperties is null, so make a new one
|
||||
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
|
||||
materialProperties.Initialize();
|
||||
}
|
||||
else {
|
||||
// materialProperties already exists, so make a copy
|
||||
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
||||
}
|
||||
|
||||
// set shader
|
||||
materialProperties.SetShader(decalShader);
|
||||
// add texture nodes
|
||||
foreach (var textureNode in node.GetNodes("TEXTURE")) {
|
||||
materialProperties.AddProperty(new MaterialTextureProperty(textureNode));
|
||||
@ -21,6 +32,8 @@ namespace ConformalDecals {
|
||||
foreach (var colorNode in node.GetNodes("COLOR")) {
|
||||
materialProperties.AddProperty(new MaterialColorProperty(colorNode));
|
||||
}
|
||||
|
||||
base.OnLoad(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user