mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
drewcassidy
da1fbf0f2a
• KSP rescales the model object back to 1,1,1 on start, so don't use that for the model that gets scaled • Some refactoring to consolidate property IDs • rename some classes because I am indecisive • Add and Get methods for MaterialPropertyCollection • Make an attempt at a scale culling fix
55 lines
1.6 KiB
C#
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();
|
|
}
|
|
}
|
|
} |