mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Debug statement cleanup and fix icon creation
This commit is contained in:
parent
79bdc03c4b
commit
a8313127e2
Binary file not shown.
@ -18,6 +18,7 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
if (node == null) throw new ArgumentNullException(nameof(node));
|
if (node == null) throw new ArgumentNullException(nameof(node));
|
||||||
|
|
||||||
PropertyName = node.GetValue("name");
|
PropertyName = node.GetValue("name");
|
||||||
|
Debug.Log($"Parsing material property {_propertyName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void Modify(Material material);
|
public abstract void Modify(Material material);
|
||||||
|
@ -74,7 +74,6 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
|
|
||||||
for (var i = 0; i < _serializedNames.Length; i++) {
|
for (var i = 0; i < _serializedNames.Length; i++) {
|
||||||
var property = MaterialProperty.Instantiate(_serializedProperties[i]);
|
var property = MaterialProperty.Instantiate(_serializedProperties[i]);
|
||||||
Debug.Log($"insantiating {property.GetType().Name} {property.GetInstanceID()}");
|
|
||||||
_materialProperties.Add(_serializedNames[i], property);
|
_materialProperties.Add(_serializedNames[i], property);
|
||||||
|
|
||||||
if (property is MaterialTextureProperty textureProperty && textureProperty.isMain) {
|
if (property is MaterialTextureProperty textureProperty && textureProperty.isMain) {
|
||||||
@ -112,7 +111,7 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
var newProperty = MaterialProperty.CreateInstance<T>();
|
var newProperty = MaterialProperty.CreateInstance<T>();
|
||||||
newProperty.PropertyName = propertyName;
|
newProperty.PropertyName = propertyName;
|
||||||
_materialProperties.Add(propertyName, newProperty);
|
_materialProperties.Add(propertyName, newProperty);
|
||||||
|
|
||||||
return newProperty;
|
return newProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +136,7 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
public MaterialTextureProperty AddTextureProperty(string propertyName, bool isMain = false) {
|
public MaterialTextureProperty AddTextureProperty(string propertyName, bool isMain = false) {
|
||||||
var newProperty = AddProperty<MaterialTextureProperty>(propertyName);
|
var newProperty = AddProperty<MaterialTextureProperty>(propertyName);
|
||||||
if (isMain) _mainTexture = newProperty;
|
if (isMain) _mainTexture = newProperty;
|
||||||
|
|
||||||
return newProperty;
|
return newProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,13 +154,11 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
public T ParseProperty<T>(ConfigNode node) where T : MaterialProperty {
|
public T ParseProperty<T>(ConfigNode node) where T : MaterialProperty {
|
||||||
var propertyName = node.GetValue("name");
|
var propertyName = node.GetValue("name");
|
||||||
if (string.IsNullOrEmpty(propertyName)) throw new ArgumentException("node has no name");
|
if (string.IsNullOrEmpty(propertyName)) throw new ArgumentException("node has no name");
|
||||||
Debug.Log($"Parsing material property {propertyName}");
|
|
||||||
|
|
||||||
var newProperty = AddOrGetProperty<T>(propertyName);
|
var newProperty = AddOrGetProperty<T>(propertyName);
|
||||||
newProperty.ParseNode(node);
|
newProperty.ParseNode(node);
|
||||||
|
|
||||||
if (newProperty is MaterialTextureProperty textureProperty && textureProperty.isMain) {
|
if (newProperty is MaterialTextureProperty textureProperty && textureProperty.isMain) {
|
||||||
Debug.Log("new texture has isMain enabled");
|
|
||||||
_mainTexture = textureProperty;
|
_mainTexture = textureProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +200,7 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
public void UpdateTile(Rect tile) {
|
public void UpdateTile(Rect tile) {
|
||||||
if (_mainTexture == null) throw new InvalidOperationException("UpdateTile called but no main texture is specified!");
|
if (_mainTexture == null) throw new InvalidOperationException("UpdateTile called but no main texture is specified!");
|
||||||
var mainTexSize = _mainTexture.Dimensions;
|
var mainTexSize = _mainTexture.Dimensions;
|
||||||
|
|
||||||
Debug.Log($"Main texture is {_mainTexture.PropertyName} and its size is {mainTexSize}");
|
Debug.Log($"Main texture is {_mainTexture.PropertyName} and its size is {mainTexSize}");
|
||||||
|
|
||||||
foreach (var entry in _materialProperties) {
|
foreach (var entry in _materialProperties) {
|
||||||
@ -219,9 +216,9 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
|
|
||||||
int x = index % tileCountX;
|
int x = index % tileCountX;
|
||||||
int y = index / tileCountY;
|
int y = index / tileCountY;
|
||||||
|
|
||||||
var tile = new Rect(x * tileSize.x, y * tileSize.y, tileSize.x, tileSize.y);
|
var tile = new Rect(x * tileSize.x, y * tileSize.y, tileSize.x, tileSize.y);
|
||||||
|
|
||||||
UpdateTile(tile);
|
UpdateTile(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,15 +2,14 @@ using System;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace ConformalDecals.MaterialModifiers {
|
namespace ConformalDecals.MaterialModifiers {
|
||||||
public class MaterialTextureProperty : MaterialProperty, ISerializationCallbackReceiver {
|
public class MaterialTextureProperty : MaterialProperty {
|
||||||
[SerializeField] public bool isNormal;
|
[SerializeField] public bool isNormal;
|
||||||
[SerializeField] public bool isMain;
|
[SerializeField] public bool isMain;
|
||||||
[SerializeField] public bool autoScale;
|
[SerializeField] public bool autoScale;
|
||||||
[SerializeField] public bool autoTile;
|
[SerializeField] public bool autoTile;
|
||||||
|
|
||||||
[SerializeField] private string _textureUrl;
|
[SerializeField] private string _textureUrl;
|
||||||
|
[SerializeField] private Texture2D _texture;
|
||||||
private Texture2D _texture;
|
|
||||||
|
|
||||||
[SerializeField] private bool _hasTile;
|
[SerializeField] private bool _hasTile;
|
||||||
[SerializeField] private Rect _tileRect;
|
[SerializeField] private Rect _tileRect;
|
||||||
@ -40,13 +39,6 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
|
|
||||||
public float AspectRatio => MaskedHeight / (float) MaskedWidth;
|
public float AspectRatio => MaskedHeight / (float) MaskedWidth;
|
||||||
|
|
||||||
public void OnBeforeSerialize() { }
|
|
||||||
|
|
||||||
public void OnAfterDeserialize() {
|
|
||||||
// Unity appears to be screwing up textures when deserializing them, so this is the fix?
|
|
||||||
_texture = LoadTexture(_textureUrl, isNormal);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void ParseNode(ConfigNode node) {
|
public override void ParseNode(ConfigNode node) {
|
||||||
base.ParseNode(node);
|
base.ParseNode(node);
|
||||||
|
|
||||||
@ -65,13 +57,10 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
else {
|
else {
|
||||||
TextureUrl = node.GetValue("textureUrl");
|
TextureUrl = node.GetValue("textureUrl");
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log($"parsed texture node with texture {_textureUrl}, {isMain}");
|
|
||||||
|
|
||||||
if (node.HasValue("tileRect") && !autoTile) {
|
if (node.HasValue("tileRect") && !autoTile) {
|
||||||
SetTile(ParsePropertyRect(node, "tileRect", true, _tileRect));
|
SetTile(ParsePropertyRect(node, "tileRect", true, _tileRect));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Modify(Material material) {
|
public override void Modify(Material material) {
|
||||||
@ -91,7 +80,7 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetTile(Rect tile) {
|
public void SetTile(Rect tile) {
|
||||||
SetTile(tile, new Vector2(_texture.width, _texture.height));
|
SetTile(tile, Dimensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTile(Rect tile, Vector2 mainTexDimensions) {
|
public void SetTile(Rect tile, Vector2 mainTexDimensions) {
|
||||||
|
@ -93,7 +93,6 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
public override void OnLoad(ConfigNode node) {
|
public override void OnLoad(ConfigNode node) {
|
||||||
this.Log("Loading module");
|
this.Log("Loading module");
|
||||||
this.Log($"{node.ToString()}");
|
|
||||||
try {
|
try {
|
||||||
// SETUP TRANSFORMS
|
// SETUP TRANSFORMS
|
||||||
|
|
||||||
@ -191,9 +190,10 @@ namespace ConformalDecals {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
this.LogException("Exception parsing partmodule", e);
|
this.LogException("Exception parsing partmodule", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateMaterials();
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
UpdateMaterials();
|
|
||||||
UpdateScale();
|
UpdateScale();
|
||||||
UpdateProjection();
|
UpdateProjection();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user