public void ReplaceKeyBind(VirtualKey key, KeyProperty val) { if (_map.ContainsKey(key)) { _map[key].Clear(); _map[key].Add(val); } }
public void AddKeyBind(VirtualKey key, KeyProperty val) { if (!_map.ContainsKey(key)) { List <KeyProperty> newList = new List <KeyProperty>(); _map[key] = newList; } _map[key].Add(val); }
public void SetKeyBind(VirtualKey key, KeyProperty val) { if (_map.ContainsKey(key)) { ReplaceKeyBind(key, val); } else { AddKeyBind(key, val); } }
public static KeyMap JsonToKeyMap(string jsonString) { //Debug.Log(jsonString); JSONNode config = JSON.Parse(jsonString); KeyMap deviceMap = new KeyMap(); //iterate through all virtualkeys foreach (string virtualKeyName in config.AsObject.Keys) { IEnumerable <JSONNode> hardKeys = config[virtualKeyName].Children; VirtualKey vKey = VirtualKey.NONE; try { vKey = (VirtualKey)Enum.Parse(typeof(VirtualKey), virtualKeyName); } catch (ArgumentException) { return(null); } //iterate all hardkeys assigned to a virtual key foreach (JSONNode hardKey in hardKeys) { string keyName = hardKey["KeyName"].Value; bool isAxis = hardKey["IsAxis"] != null ? hardKey["IsAxis"].AsBool : false; bool invert = hardKey["Inverted"] != null ? hardKey["Inverted"].AsBool : false; string condValue = hardKey["KeyTriggerCondition"]; string orientValue = hardKey["AxisOrientation"]; KeyTriggerCondition condition = KeyTriggerCondition.NON_ZERO; if (condValue != null) { try { condition = (KeyTriggerCondition)Enum.Parse(typeof(KeyTriggerCondition), condValue); } catch (ArgumentException) {} } AxisOrientation orientation = AxisOrientation.NONE; if (orientValue != null) { try { orientation = (AxisOrientation)Enum.Parse(typeof(AxisOrientation), orientValue); } catch (ArgumentException) {} } KeyProperty property = new KeyProperty(keyName, isAxis, invert, condition, orientation); deviceMap.AddKeyBind(vKey, property); } } return(deviceMap); }