lunar-unity-console icon indicating copy to clipboard operation
lunar-unity-console copied to clipboard

Setup Variables at runtime, and document it.

Open geekrelief opened this issue 6 years ago • 1 comments

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;
    }
}

geekrelief avatar Feb 08 '19 04:02 geekrelief

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

weeeBox avatar Apr 06 '19 02:04 weeeBox