Kingdoms and Castles

Kingdoms and Castles

Mods & Banners
Try out user made mods and share banners!
Learn More
Mr. Bitches 13 Jun, 2020 @ 8:32pm
Building UI
I am trying to set up a new UI associated to a new building. Ideally it would have a similar button as the ChamberOfWarUi, plus one more button. Ideally the new UI would inlay on WorkerUI like other buildings with special UIs. I'd use the custom button functionality on WorkerUI, but I'd like 2 custom buttons. I'm not understanding how to export a new canvas/UI from unity and wire it up to the game at runtime using the mod tools. If anybody has any tips I'd be greatly appreciative
< >
Showing 1-1 of 1 comments
Agentfox 11 24 Nov, 2020 @ 1:02pm 
I realize this is a bit late, but you would generally accomplish this using Unity's AssetBundles. There's a script in the KCToolkit (github repo linked below) that exports any set of Unity Objects (Prefabs, Audio, Meshes, anything in the Assets folder essentially) to an AssetBundle that can be extracted by a mod, and injected into the game. AssetBundles are used because Unity is weird and doesn't like to just have things work directly, there's always a process to follow. Once you've created your AssetBundle, you need to write code that uses its contents. How you would do it is basically the same way you would handle Prefabs in the Unity Engine. You extract the AssetBundle's contents as shown below
myAssetBundle.LoadAsset("your/path/here")
by scene path (from the Unity Editor) and that should return a UnityEngine.Object (which can be cast to a GameObject). This object that is returned is the prefab of your canvas/UI, this can be instantiated however you like, for a reference I recommend looking at Zat's ModMenu (also linked below).


Kingdoms and Castles Toolkit:
https://github.com/mpeddicord/Kingdoms-and-Castles-Toolkit

Zat's ModMenu:
https://github.com/BigMo/KCMods/tree/master/Scripts/ModMenu

A further in-depth explanation is featured in the section of the modding tutorial, Making a Mod with AssetBundles (Ogre Sneakers):
https://docs.google.com/document/d/1hRrV92_n9zuYxuB-7yCaiftzFsGEsoRRkMnTbaaKRqM/edit#heading=h.q3co8lyn7pc6
Last edited by Agentfox; 24 Nov, 2020 @ 1:04pm
< >
Showing 1-1 of 1 comments
Per page: 1530 50