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); }
public KeyProperty(string name, bool isAxis = false, bool inverted = false, KeyTriggerCondition condition = KeyTriggerCondition.NON_ZERO, AxisOrientation orientation = AxisOrientation.NONE) { Name = name; IsAxis = isAxis; Inverted = inverted; TriggerCondition = condition; Orientation = orientation; try { ToKeycode = (KeyCode)Enum.Parse(typeof(KeyCode), name); } catch (ArgumentException) { ToKeycode = KeyCode.None; } }