public void SaveToFile(string path) { IniParser parser = new IniParser(); parser.Open(path); foreach (var pair in keyList) { var keyValue = pair.behaviour; foreach (var keycode in pair.keycodes) { var keyCodeStr = Enum.GetName(typeof(KeyCode), keycode); parser.WriteValue(SECTION_KEY, keyCodeStr, keyValue); } } parser.Close(); }
public void LoadFromFile(string path) { IniParser parser = new IniParser(); parser.Open(path); Dictionary <string, string> dectionary = null; parser.ReadAllValues(SECTION_KEY, dectionary); parser.Close(); if (dectionary != null) { Dictionary <int, List <KeyCode> > tmpMap = new Dictionary <int, List <KeyCode> >(); foreach (var pair in dectionary) { var keyCodeStr = pair.Key; var keyCode = (KeyCode)Enum.Parse(typeof(KeyCode), keyCodeStr); var keyValue = int.Parse(pair.Value); List <KeyCode> codeList = null; if (!tmpMap.TryGetValue(keyValue, out codeList)) { codeList = new List <KeyCode>(); tmpMap.Add(keyValue, codeList); } codeList.Add(keyCode); } keyList.Clear(); foreach (var pair in tmpMap) { KeyPair keyPair = new KeyPair(); keyPair.behaviour = pair.Key; keyPair.keycodes = pair.Value; keyList.Add(keyPair); } } }