roj Posted January 30, 2022 Share Posted January 30, 2022 Hello! I have written a mod that is simply copies of exiting buildings (the storage buildings) that are more expensive, but store more stuff. I'd So I've figured out how to alter capacity, names, etc, but I can't find anything in there to simply alter color. I don't need custom art, and I'm hoping it's simpler to just shift or overlay a color. Can someone give me some guidance? Do I need to add new assets with different colors? Can anyone point me to a mod that does something similar? I've found fancy mods that color shift according to material or temp, but I can't parse those out (or, rather, I don't think it'll be worth the 80 hours of thinking. ... let's go with that.) Thanks! Link to comment Share on other sites More sharing options...
pether Posted January 30, 2022 Share Posted January 30, 2022 KAnimControllerBase kanim = gameObject.GetComponent<KAnimControllerBase>(); if (kanim != null) kanim.TintColour = yourColorHere; for more examples see mods like "Wallpaper", "MaterialColor" etc. In fact if you search "color" in steam workshop you will find many examples Link to comment Share on other sites More sharing options...
roj Posted January 30, 2022 Author Share Posted January 30, 2022 Hmm, that's what I've been fiddling with today, but I can't get it to work. (got it out of MaterialColor, in fact!) Maybe it's WHEN I'm using it. MaterialColor seems to run it constantly. I only have access to the game object during ConfigureBuildingTemplate, which I am overriding, but I get a crash there. Link to comment Share on other sites More sharing options...
roj Posted January 30, 2022 Author Share Posted January 30, 2022 Update! Here is what worked. Put this into an OnLoad override. This is coloring my buildings cyan. [HarmonyPatch(typeof(Game), "OnSpawn")] public static class GameStart { public static void Postfix() => TryInitMod(); private static void ApplyColorToBuilding(BuildingComplete building) { KAnimControllerBase kanim = building.GetComponent<KAnimControllerBase>(); if (kanim != null && (building.name.ToString().StartsWith("YourBuildingID"))) { kanim.TintColour = Color.cyan; //any UnityEngine.Color32 } } private static void TryInitMod() { try { Components.BuildingCompletes.OnAdd += new Action<BuildingComplete>(ApplyColorToBuilding); } catch (Exception ex) { Log(ex.ToString());//logging optional, use your logger } } } New problem! I cannot tint a solid storage container. How do I give THOSE a tint? Link to comment Share on other sites More sharing options...
roj Posted January 30, 2022 Author Share Posted January 30, 2022 The solid storages are 'tree filterable' and the above does not work. Use this instead: [HarmonyPatch(typeof(FilteredStorage), "OnFilterChanged")] public static class FilteredStorage_OnFilterChanged { public static void Postfix(KMonoBehaviour ___root, Tag[] tags) { if (___root.name.ToString().StartsWith("YourBuildngName")) { try { if (!IsActive(tags)) return; KAnimControllerBase kanim = ___root.GetComponent<KAnimControllerBase>(); if (kanim != null) { kanim.TintColour = Color.cyan; Log(string.Concat("Updating Filterable Object Color:", ___root.name.ToString())); //logging optional, use your logger } } catch (Exception ex) { Log(ex.ToString());//logging optional, use your logger } } } private static bool IsActive(Tag[] tags) => tags != null && (uint) tags.Length > 0U; } [HarmonyPatch(typeof(Game), "OnSpawn")] public static class GameStart { public static void Postfix() => TryInitMod(); private static void ApplyColorToBuilding(BuildingComplete building) { if (building.name.ToString().StartsWith("YourBuildngName")) { TreeFilterable treeFilterable = building.GetComponent<TreeFilterable>(); if (treeFilterable != null) { Traverse traverse = Traverse.Create(treeFilterable); traverse.Field("filterTint").SetValue(defaultColor); //defaultColor is any UnityEngine.Color32 Tag[] array = traverse.Field<List<Tag>>("acceptedTags").Value.ToArray(); treeFilterable.OnFilterChanged(array); } } } private static void TryInitMod() { try { Components.BuildingCompletes.OnAdd += new Action<BuildingComplete>(ApplyColorToBuilding); } catch (Exception ex) { Log(ex.ToString());//logging optional, use your logger } } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.