2020-06-03 03:36:45 +00:00
|
|
|
using ConformalDecals.Util;
|
|
|
|
|
|
|
|
namespace ConformalDecals {
|
|
|
|
public class ModuleConformalDecalFlag : ModuleConformalDecalBase {
|
2020-06-06 04:29:57 +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-06 04:29:57 +00:00
|
|
|
UpdateFlag(GetDefaultFlag());
|
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);
|
|
|
|
}
|
2020-06-06 04:29:57 +00:00
|
|
|
|
|
|
|
UpdateFlag(GetDefaultFlag());
|
2020-06-04 07:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06 04:29:57 +00:00
|
|
|
private string GetDefaultFlag() {
|
|
|
|
if (HighLogic.LoadedSceneIsGame) {
|
|
|
|
return EditorLogic.FlagURL != string.Empty ? EditorLogic.FlagURL : HighLogic.CurrentGame.flagURL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return DefaultFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-06 04:29:57 +00:00
|
|
|
materialProperties.AddOrGetTextureProperty("_Decal", true).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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|