SpaceMadness / lunar-unity-console

High-performance Unity iOS/Android logger built with native platform UI
https://www.assetstore.unity3d.com/en/#!/content/43800
Other
848 stars 116 forks source link

Setup Variables at runtime, and document it. #128

Open geekrelief opened 5 years ago

geekrelief commented 5 years ago

To create Variables at runtime I did this. It should be mentioned in the docs.

public class SettingsConsoleVariables : MonoBehaviour
{
    public Settings settings;
    public static CVar factor;

    private void Start()  // Note: setup on Start not Awake
    {
        LunarConsole console = GetComponent<LunarConsole>();
        factor = new CVar("factor", settings.factor);
        factor.AddDelegate(OnFactorUpdate);
        console.registry.Register(factor);
        // would be nice to say: factor = LunarConsole.Register("factor", settings.factor, OnFactorUpdate);
    }

    void OnFactorUpdate(CVar cvar)
    {
        settings.factor = cvar;
    }
}
weeeBox commented 5 years ago

@geekrelief, unfortunately, it didn't end up as a quick fix. I have to think about better variables handling. Stay tuned...