/// <summary> /// Retrieves a specific input handler based on the name. /// </summary> /// <param name="name">the handler name to look for</param> /// <returns>the input handler</returns> /// public static InputHandler GetInputHandler(string name) { InputHandler handler; if (!handlers.TryGetValue(name, out handler)) { handler = new InputHandler(name); handlers[name] = handler; } return handler; }
private void ReadMappings() { if (mappingFile == null) return; // JSON file cannot directly be read because of polymorphism > split manually // remove tabs and linefeeds string txtConfig = mappingFile.text.Replace("\t", "").Replace("\n", ""); // cut beginning and end txtConfig = Regex.Replace(txtConfig, "^\\s*{\\s*\"Inputs\":\\[\\s*{", ""); txtConfig = Regex.Replace(txtConfig, "}\\s*\\]\\s*}\\s*$", ""); // split string[] inputMappings = Regex.Split(txtConfig, "}\\s*,\\s*{"); foreach (string configTxt in inputMappings) { try { string configTxtTrim = "{" + configTxt + "}"; InputMap map = JsonUtility.FromJson<InputMap>(configTxtTrim); InputHandler handler; if (!handlers.TryGetValue(map.inputName, out handler)) { handler = new InputHandler(map.inputName); handlers[map.inputName] = handler; } handler.AddMapping(map.inputType, map.parameters); } catch (System.Exception e) { Debug.LogWarning("Could not parse Input Mapping Configuration entry " + "'" + configTxt + "'" + " - Reason: " + e.Message); } } }
private void ParseMappings() { // create/update handlers foreach (InputMap map in mappings) { InputHandler handler; if (!handlers.TryGetValue(map.inputName, out handler)) { handler = new InputHandler(map.inputName); handlers[map.inputName] = handler; } handler.AddMapping(map.inputType, map.parameters); } }