2020-06-03 03:36:45 +00:00
|
|
|
using ConformalDecals.MaterialModifiers;
|
|
|
|
using ConformalDecals.Util;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace ConformalDecals {
|
|
|
|
public class ModuleConformalDecalFlag : ModuleConformalDecalBase {
|
2020-06-03 05:45:48 +00:00
|
|
|
[KSPField] public MaterialTextureProperty flagTextureProperty;
|
2020-06-03 03:36:45 +00:00
|
|
|
|
2020-06-04 07:12:09 +00:00
|
|
|
private const string defaultFlag = "Squad/Flags/default";
|
2020-06-03 03:36:45 +00:00
|
|
|
|
2020-06-04 07:12:09 +00:00
|
|
|
public override void OnLoad(ConfigNode node) {
|
|
|
|
base.OnLoad(node);
|
2020-06-03 05:45:48 +00:00
|
|
|
|
2020-06-04 07:12:09 +00:00
|
|
|
if (HighLogic.LoadedSceneIsGame) {
|
2020-06-05 07:29:23 +00:00
|
|
|
UpdateFlag(EditorLogic.FlagURL != string.Empty ? EditorLogic.FlagURL : HighLogic.CurrentGame.flagURL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UpdateFlag(defaultFlag);
|
2020-06-04 07:12:09 +00:00
|
|
|
}
|
2020-06-03 03:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnStart(StartState state) {
|
|
|
|
base.OnStart(state);
|
|
|
|
|
2020-06-04 07:12:09 +00:00
|
|
|
if (HighLogic.LoadedSceneIsGame) {
|
|
|
|
GameEvents.onMissionFlagSelect.Add(UpdateFlag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnIconCreate() {
|
|
|
|
this.Log("called OnIconCreate");
|
|
|
|
UpdateScale();
|
2020-06-03 03:36:45 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 07:29:23 +00:00
|
|
|
public override void OnDestroy() {
|
|
|
|
GameEvents.onMissionFlagSelect.Remove(UpdateFlag);
|
|
|
|
base.OnDestroy();
|
|
|
|
}
|
|
|
|
|
2020-06-03 03:36:45 +00:00
|
|
|
private void UpdateFlag(string flagUrl) {
|
2020-06-03 05:45:48 +00:00
|
|
|
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");
|
2020-06-04 07:12:09 +00:00
|
|
|
flagTextureProperty = ScriptableObject.CreateInstance<MaterialTextureProperty>();
|
2020-06-05 07:29:23 +00:00
|
|
|
flagTextureProperty.PropertyName = "_Decal";
|
2020-06-04 07:12:09 +00:00
|
|
|
flagTextureProperty.isMain = true;
|
2020-06-03 05:45:48 +00:00
|
|
|
materialProperties.AddProperty(flagTextureProperty);
|
2020-06-05 07:29:23 +00:00
|
|
|
materialProperties.MainTexture = flagTextureProperty;
|
2020-06-03 05:45:48 +00:00
|
|
|
}
|
2020-06-04 07:12:09 +00:00
|
|
|
else { }
|
|
|
|
|
|
|
|
flagTextureProperty.texture = flagTexture;
|
|
|
|
|
2020-06-03 03:36:45 +00:00
|
|
|
|
2020-06-04 07:12:09 +00:00
|
|
|
UpdateMaterials();
|
2020-06-03 03:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|