🏒
Puck
  • Welcome!
  • GETTING STARTED
    • Development environment setup
    • Using the Puck API
    • Testing your mod
    • Development optimizations
  • PUBLISHING
    • SteamWorkshopUploader
    • Publishing to the Steam Workshop
  • Puck API
    • Singletons
    • Harmony
    • Referencing the source
Powered by GitBook
On this page
  1. Puck API

Singletons

Puck makes use of singletons for all crucial systems. Two main singleton types are used within the Puck codebase:

  1. MonoBehaviorSingleton<T> - For standard Unity MonoBehaviour-based managers

  2. NetworkBehaviorSingleton<T> - For network-aware managers that need to work with Unity's Netcode for GameObjects

Accessing singleton instances is straight forward:

public class Class1 : IPuckMod
{
    public bool OnEnable()
    {
        Debug.Log($"Your global volume is {SettingsManager.Instance.GlobalVolume}!");

        SettingsManager.Instance.UpdateGlobalVolume(0.5f);
        Debug.Log($"Your global volume is now {SettingsManager.Instance.GlobalVolume}!");

        return true;
    }

    public bool OnDisable()
    {
        return true;
    }
}

Some mods will suffice with simply accessing existing public members provided by singletons themselves, though more advanced mods might require your to modify existing functionality of singletons or multi-instance classes. Let's cover how we can modify functionality with Harmony next.

PreviousPublishing to the Steam WorkshopNextHarmony

Last updated 8 days ago