Custom Resources - ihsoft/TimberbornMods GitHub Wiki
Overview
This mod allows other mods to use their local resources in the stock game methods that don't allow it naturally. Check out README to learn the rationale of this mod.
StatusToggle
Using The game can present a status icon above a gameobject. It can frequently be seen in the game, e.g. when a building is flooded or disconnected from the districts. This is controlled by the StatusToggle
game component. This is how it's usually done in the code:
sealed class CustomStatusBehavior : BaseComponent {
StatusToggle _statusToggle;
void Start() {
_statusToggle = StatusToggle.CreatePriorityStatusWithFloatingIcon("Stranded", "stranded description");
var subject = GetComponentFast<StatusSubject>();
subject.RegisterStatus(_statusToggle);
_statusToggle.Activate();
}
void OnDestroy() {
_statusToggle.Deactivate();
}
}
However, CreatePriorityStatusWithFloatingIcon
(and the other variants) accepts a sprite name. This name internally resolves to a resource path in the game's internal folder "Sprites/StatusIcons". Thus, only the standard game icons can be used this way. With this mod installed, it's possible to provide a mod's specific path to the status icon. E.g. for the mod with asset prefix "mymod.prefix" and asset file name "MySprites", the loading of a custom sprite as status would look like this:
_statusToggle = StatusToggle.CreatePriorityStatusWithFloatingIcon(
"mymod.prefix/MySprites/MyCustomIcon",
"my status description");
For the best results, make the custom icon resolution 512x512 and enable mipmaps (in read/write mode).
CursorService.SetCursor
Using The game has a service that controls the current cursor in the scene: CursorSystem
. It's usually used like this:
sealed class MyBehavior : BaseComponent {
CursorSystem _cursorSystem;
[Inject]
public void InjectDependencies(CursorSystem cursorSystem) {
_cursorSystem = cursorSystem;
}
protected void ShowCustomCursor() {
_cursorSystem.SetCursor("CancelCursor");
}
protected void ResetCustomCursor() {
_cursorSystem.ResetCursor();
}
}
However, the service key method SetCursor
accepts only a name of the game internal scriptable object CustomCursor
. It internally resolves to a resource path in the game's internal folder "UI/Cursors". Thus, only the standard cursors can be used through this system by default. With this mod installed, it's possible to provide a mod's specific path to a texture that will become a new cursor. E.g. for the mod with asset prefix "mymod.prefix" and asset filename "MyCursors", the loading of a custom cursor would look like this:
protected void ShowCustomCursor() {
_cursorSystem.SetCursor("mymod.prefix/MyCursors/CustomCancelCursor");
}
For the code above to work, the resource in the asset bundle must be created as a 2D texture of type Cursor
. The texture must allow read/write operations and don't have mipmaps. It's a Unity requirement.