예제 #1
0
        /// <summary>
        /// The hotkey change function.
        /// Changes the hotkey accordingly.
        /// </summary>
        public void HotkeyChange()
        {
            if (this.CurrentKey != null)
            {
                Event e = Event.current;

                // Check if its a key and if its a mappable key
                if (e.isKey && this.possiblekeys.Contains(e.keyCode))
                {
                    // Get the key
                    string kb_key = this.CurrentKey.GetComponentInChildren <Text>().text;

                    // Map key code to the key
                    this.thekeybinddictionary[kb_key] = e.keyCode;

                    this.hotkeys = new HotKeySerializables();

                    foreach (var val in this.thekeybinddictionary)
                    {
                        this.MakeHotKey(val.Key, val.Value.ToString());
                    }

                    this.SaveHotkeys();

                    // Set sprite here
                    this.CurrentKey.GetComponent <Image>().sprite = this.spritedictionary[e.keyCode];
                    this.CurrentKey = null;

                    // Reset timer
                    this.Timer = 0.0f;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// The load hotkeys function.
        /// Loads hot keys from the saved file.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool LoadHotkeys()
        {
            // The folder exists and the file exists then load the keys
            if (System.IO.Directory.Exists(@"..\KeyBindings") && System.IO.File.Exists(@"..\KeyBindings\HotKeys.json"))
            {
                this.hotkeysconfig = System.IO.File.ReadAllText(@"..\KeyBindings\HotKeys.json");

                this.hotkeys = JsonUtility.FromJson(this.hotkeysconfig, typeof(HotKeySerializables)) as HotKeySerializables;

                if (this.hotkeys != null)
                {
                    Button[] keybuttons = this.customizeUi.GetComponentsInChildren <Button>();

                    for (int i = 0; i < this.hotkeys.Hotkeys.Count; i++)
                    {
                        // Convert the message string into its keycode form.
                        KeyCode keycode = (KeyCode)System.Enum.Parse(typeof(KeyCode), this.hotkeys.Hotkeys[i].Message);

                        this.thekeybinddictionary[this.hotkeys.Hotkeys[i].Hotkey] = keycode;
                        keybuttons[i].GetComponent <Image>().sprite = this.spritedictionary[keycode];
                    }

                    return(true);
                }
            }
            return(false);
        }