Mega Tree API
API reference
Every public type and member in MegaTree.Api, flat and anchored.
Namespace: MegaTree.Api. Assembly:
MegaTree.dll. Nothing outside this namespace is public - the rest of
the mod is internal on purpose, so there is exactly one door.
Every member here takes or returns plain objects and delegates. Nothing in the surface is a
Sprite, a Color or a
GameObject, so a mod can use the API without referencing a single Unity
UI assembly.
MegaTreeApi
public static class MegaTreeApi
| Member | Description |
|---|---|
const string ModGuid |
Always "MegaTree". Use it in [BepInDependency]. |
static readonly int ApiVersion |
Contract version of the installed dll. readonly, never const - see Versioning. Currently 1. |
MegaTreeModule ForPlugin(string pluginGuid, string tabName) |
Creates or renames your sub-tab and returns your module. Call once, keep the result. Never returns null. |
int GetLevel(string nodeId) |
Owned levels, clamped to that node's MaxLevel. 0 for an unknown id. Dictionary lookup - cheap enough for a hot patch. |
bool IsRegistered(string nodeId) |
Whether the id is currently in the tree. |
void RefreshUi() |
Ask an open tree window to repaint. No-op when nothing is open, and it only marks the view stale - calling it in a loop costs one redraw. |
event Action<string,int> LevelChanged |
(nodeId, newLevel), after a buy or a sell-back. All nodes, including built-ins. Does not fire for a level restored on registration. |
event Action Apply |
About twice a second, after Mega Tree's own effects. Not a per-frame hook. |
event Action<int> SaveLoaded |
(slotIndex), once levels for that slot have been read. |
MegaTreeModule
public sealed class MegaTreeModule - obtained from
ForPlugin, never constructed directly.
| Member | Description |
|---|---|
string PluginGuid { get; } | The guid you passed in. |
string TabName { get; } | Your sub-tab label after trimming to 18 characters. |
UpgradeHandle Register(UpgradeDefinition definition) |
Adds one upgrade line. Never throws; check .Success. |
bool Unregister(string nodeId) |
Removes one of your nodes. The player's level is kept in the save. |
void AddTranslations(string locale, IDictionary<string,string> values) |
UI strings for one language. Accepts "pt-BR" or "Portuguese". Mega Tree's own keys are skipped. Details |
UpgradeDefinition
public sealed class UpgradeDefinition - a plain object with public
fields. Full explanations on Node definition.
| Field | Type | Default |
|---|---|---|
Id required | string | - |
DisplayName | string | null |
NameKey | string | null (auto: <id>.name) |
MaxLevel | int | 1 |
BaseCost | float | 1000 |
CostMultiplier | float | 1.8 |
CostForLevel | Func<int,int> | null |
SellBackRate | float? | null (50%) |
Icon | UpgradeIcon | null |
DescribeLevel required | Func<int,string> | - |
IsUnlocked | Func<bool> | null |
LockedReason | Func<string> | null |
RequiredStoreLevel | Func<int,int> | null |
ComingSoon | bool | false |
SortOrder | int | 0 |
LegacyIds | string[] | null |
OnLevelChanged | Action<int> | null |
OnApply | Action | null |
There is no category field. Every registered node lives in the Mods tab, in your sub-tab. Why
UpgradeIcon
public sealed class UpgradeIcon - built through factory methods.
| Member | Description |
|---|---|
static UpgradeIcon Builtin(string name) |
One of the 14 built-in icons. Unknown names fall back to a generic one. List |
static UpgradeIcon FromPng(byte[] data, bool whiteSilhouette = false) |
Your own PNG. Ship white artwork with alpha, or pass whiteSilhouette: true. |
UpgradeHandle
public sealed class UpgradeHandle - what
Register returns. Always non-null.
| Member | Description |
|---|---|
string NodeId { get; } | The id you registered. |
string OwnerGuid { get; } | The plugin guid that owns it. |
RegisterResult Result { get; } | Why it succeeded or failed. |
bool Success { get; } | Shorthand for Result.Success. |
int Level { get; } | Current owned level. Same as MegaTreeApi.GetLevel(NodeId). |
bool Unregister() | Removes the node; the level stays in the save. |
RegisterResult
public sealed class RegisterResult
| Member | Description |
|---|---|
bool Success { get; } | True for Ok and Replaced. |
RegisterStatus Status { get; } | Machine-readable outcome. |
string Message { get; } | The same text that went to the log. |
string ToString() | "Status: message". |
RegisterStatus
public enum RegisterStatus
| Value | Meaning |
|---|---|
Ok | Added. |
Replaced | Same plugin re-registered the id; level kept. |
MissingField | Null definition, or no DescribeLevel / no name. |
InvalidId | Not prefix.name, or bad characters. |
ReservedId | Starts with megatree. or mt. |
OwnedByAnother | Another plugin owns the id. |
InvalidLevels | MaxLevel outside 1..20. |
InvalidCost | No positive BaseCost and no CostForLevel. |
InvalidModule | Empty plugin guid. |
Built-in node ids
Stable, and none of them contains a dot - which is exactly why your ids must. Useful for gating.
| Id | Name | Tab | Levels |
|---|---|---|---|
walk | Walking Speed | You | 5 |
sprint | Sprint Speed | You | 5 |
reach | Long Reach | You | 4 |
push | Push Through | You | 4 |
cashier | Fast Cashier | Staff | 5 |
fullday | Full Day Shift | Staff | 1 |
training | Staff Training | Staff | 1 soon |
mv_cashier | Cashier Legs | Staff | 5 soon |
mv_restocker | Restocker Legs | Staff | 5 soon |
mv_unloader | Unloader Legs | Staff | 5 soon |
mv_baker | Baker Legs | Staff | 5 soon |
mv_butcher | Butcher Legs | Staff | 5 soon |
mv_seafood | Seafood Legs | Staff | 5 soon |
The ones marked soon are drawn and unbuyable. GetLevel
returns 0 for them and will keep doing so until they ship - do not gate anything on them.
Limits at a glance
| Limit | Value |
|---|---|
| Nodes per plugin | 64 |
| Levels per node | 1 - 20 |
| Id length | 3 - 64 characters |
| Sub-tab label | 18 characters |
| Sub-tabs per page | 5, then arrows |
| Kept lines per save slot | 4096 |
IsUnlocked cache | 0.25 s |
| Sell-back rate | 50% by default; a registered node can declare 0..1 via SellBackRate |
Differences from the Tech Tree API
The surface is the same, name for name. What differs is the platform and a few numbers:
| Tech Tree | Mega Tree | |
|---|---|---|
| Namespace | TechTree.Api | MegaTree.Api |
| Entry class | TechTreeApi | MegaTreeApi |
| Module type | TechTreeModule | MegaTreeModule |
| Reserved prefixes | techtree. tt. | megatree. mt. |
| Default sell-back | 60% | 50% |
Apply period | ~2 s | ~0.5 s |
| Locale argument | BCP-47 (pt-BR) | BCP-47 or the game's name (Portuguese) |
| Plugin base | BasePlugin / Load() | BaseUnityPlugin / Awake() |