Mega Tree API
Icons
The fourteen built-in icons, and how to ship your own PNG so it does not come out the wrong colour.
Built-in icons
Cheapest option, and it keeps your node visually consistent with the rest of the tree. Pass the
name; an unknown name silently falls back to git-branch.
Icon = UpgradeIcon.Builtin("package"),These are the exact images the mod draws, rendered here from the same files:
Icons by Lucide, ISC License.
Mega Tree ships the identical icon set, under the identical names. A registration copied from a Supermarket mod keeps the same picture without you checking anything.
Your own PNG
Icon = UpgradeIcon.FromPng(MyIcons.Capacity),
// ...and if your art is coloured, let Mega Tree flatten it:
Icon = UpgradeIcon.FromPng(MyIcons.Capacity, whiteSilhouette: true),| Requirement | Value |
|---|---|
| Format | PNG with an alpha channel |
| Colour | White artwork on a transparent background |
| Size | Square. 128×128 is what the built-ins use and is plenty |
| File size | Keep it under 512 KB |
Mega Tree tints the icon through
Image.color to show state - grey when locked, dim when unaffordable,
branch colour when bought. Tinting multiplies, so a green icon tinted violet comes out
near black, and a dark icon comes out invisible. White is the only colour that survives every
state.
If you cannot re-export your art, pass
whiteSilhouette: true and every opaque pixel is flattened to white for
you, keeping the alpha. You lose the internal shading, so it works for flat symbols and not for
detailed pictures.
Embedding the bytes
Never ask the player to drop a loose png next to your dll: a missing file means a broken node and a bug report you cannot reproduce. Put the bytes in your assembly.
As an embedded resource
<ItemGroup>
<EmbeddedResource Include="assets\capacity.png">
<LogicalName>BigBoxes.capacity.png</LogicalName>
</EmbeddedResource>
</ItemGroup>private static byte[] Load(string name)
{
using (var s = typeof(Plugin).Assembly.GetManifestResourceStream(name))
{
if (s == null) return null;
using (var ms = new MemoryStream())
{
s.CopyTo(ms);
return ms.ToArray();
}
}
}
// Icon = UpgradeIcon.FromPng(Load("BigBoxes.capacity.png")),MSBuild treats a file named
icon.en.png as an English satellite resource and moves it into
a separate assembly, where GetManifestResourceStream will never find
it. If a filename has a dot-separated segment that looks like a culture code, set
<WithCulture>false</WithCulture> alongside
LogicalName.
As base64
No resource plumbing, at the cost of a large string literal. This is what the example mod does.
internal static class MyIcons
{
private static byte[] _capacity;
public static byte[] Capacity => _capacity ?? (_capacity = Convert.FromBase64String(CapacityB64));
private const string CapacityB64 =
"iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAB9klEQVR42u3cUW7DMAwE0azR" +
"...";
}Generate the string from a file:
[Convert]::ToBase64String([IO.File]::ReadAllBytes("icon.png")) | clipWhen the decoding happens
Your bytes are kept as bytes at registration and only turned into a texture the first time a
node using them is drawn. This is not laziness for its own sake: a
Texture2D can only be created on Unity's main thread once the engine is
up, and your plugin's Awake() runs long before any scene exists.
Decoding at registration would crash the game.
Consequences worth knowing:
- A malformed PNG is not reported until the player opens the tree. Test yours.
- The sprite is cached per node id, so the cost is paid once - including the cache of a failed decode, so a broken PNG is not retried on every repaint.
- Textures are created with
HideAndDontSave, so they survive the scene change from menu to store. - A PNG that fails to decode falls back to
git-branchand writes one line to the log naming your node and your guid.
Choosing well
- Icons render small. Detail below a few pixels wide disappears - draw the silhouette, not the illustration.
- Leave a margin. The circle crops the corners.
- Pick a built-in if one is close. Fourteen options and a consistent look beat a bespoke icon that reads as a different mod.