You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
KSP-Conformal-Decals/Source/ConformalDecals/ModuleConformalDecalFlag.cs

55 lines
1.6 KiB
C#

using ConformalDecals.Util;
namespace ConformalDecals {
public class ModuleConformalDecalFlag : ModuleConformalDecalBase {
private const string DefaultFlag = "Squad/Flags/default";
public override void OnLoad(ConfigNode node) {
base.OnLoad(node);
UpdateFlag(GetDefaultFlag());
}
public override void OnStart(StartState state) {
base.OnStart(state);
if (HighLogic.LoadedSceneIsGame) {
GameEvents.onMissionFlagSelect.Add(UpdateFlag);
}
UpdateFlag(GetDefaultFlag());
}
public override void OnIconCreate() {
this.Log("called OnIconCreate");
UpdateScale();
}
public override void OnDestroy() {
GameEvents.onMissionFlagSelect.Remove(UpdateFlag);
base.OnDestroy();
}
private string GetDefaultFlag() {
if (HighLogic.LoadedSceneIsGame) {
return EditorLogic.FlagURL != string.Empty ? EditorLogic.FlagURL : HighLogic.CurrentGame.flagURL;
}
else {
return DefaultFlag;
}
}
private void UpdateFlag(string flagUrl) {
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;
}
materialProperties.AddOrGetTextureProperty("_Decal", true).texture = flagTexture;
UpdateMaterials();
}
}
}