void HandleToggle(NuiToggleInfo toggle) { //If the current state is closed, we want to open it and request a toggle to the NUI backend. if (!toggle.State) { //Open the menu. toggle.OpenFunction(); toggle.State = true; //Setup a callback for NUI to call us back when the player want to close the UI. string uniqueName = Guid.NewGuid().ToString("n"); var values = new Dictionary <string, string> { { "toggleName", uniqueName }, { "toggleKey", toggle.KeyName } }; SendMessage("toggleInit", values); //Listen for when the user wants to close the UI. AddCallback($"toggleInvoke_{uniqueName}", (dict) => { toggle.CloseFunction(); toggle.State = false; }); } }
public void AddToggle(int keyCode, string keyName, NuiToggleFunctions openFunc, NuiToggleFunctions closeFunc) { NuiToggleInfo info = new NuiToggleInfo { KeyCode = keyCode, KeyName = keyName, OpenFunction = openFunc, CloseFunction = closeFunc }; inputRef.Get().RegisterKey(0, keyCode, InputKeyType.Once, (time) => { HandleToggle(info); }); toggles.Add(info); }