/// <summary> /// Returns a KeycodeData structure object containing information about any keybinding codes in the config file. /// /// </summary> /// <param name="sTheText"></param> /// <returns>Returns KeycodeData object where NumOfCodes contains how many are in use, 0 if there were errors</returns> public static KeycodeData getAlternateKeyBindings(String sTheText) { KeycodeData kcData = new KeycodeData(); kcData.NumOfCodes = 0; kcData.kCode1 = KeyCode.None; kcData.kCode2 = KeyCode.None; kcData.kCode3 = KeyCode.None; try { string[] sArray = sTheText.Split(','); byte ilen = (byte)sArray.Length; // if not at least two, just return an object with 0 marked, basically error condition. if (ilen <= 1) { return(kcData); } // if 2 string then let's try and convert them to proper Unity KeyCodes. if (ilen == 2) { kcData.kCode1 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[0].ToString()); kcData.kCode2 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[1].ToString()); kcData.NumOfCodes = 2; } else { // if 3 strings then let's try and convert first three to proper Unity KeyCodes. kcData.kCode1 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[0].ToString()); kcData.kCode2 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[1].ToString()); kcData.kCode3 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[2].ToString()); kcData.NumOfCodes = 3; } if (Mod.DEBUG_LOG_ON) { Logger.dbgLog("Alternate Keys bound: " + kcData.NumOfCodes.ToString()); } } catch (Exception ex) { Logger.dbgLog(ex.Message.ToString(), ex, true); } // We check if our kCodes1 or 2 are "None", if they are then there were problems and lets just use // our default values and return a well formed object. if ((kcData.kCode1 == KeyCode.None) || kcData.kCode2 == KeyCode.None) { kcData.kCode1 = KeyCode.LeftControl; kcData.kCode2 = KeyCode.LeftAlt; kcData.kCode3 = KeyCode.L; kcData.NumOfCodes = 3; Logger.dbgLog("Alternate Keys enabled but used incorrectly, using default alternate."); } return(kcData); }
/// <summary> /// Returns a KeycodeData structure object containing information about any keybinding codes in the config file. /// /// </summary> /// <param name="sTheText"></param> /// <returns>Returns KeycodeData object where NumOfCodes contains how many are in use, 0 if there were errors</returns> public static KeycodeData getAlternateKeyBindings(String sTheText) { KeycodeData kcData = new KeycodeData(); kcData.NumOfCodes = 0; kcData.kCode1 = KeyCode.None; kcData.kCode2 = KeyCode.None; kcData.kCode3 = KeyCode.None; try { string[] sArray = sTheText.Split(','); byte ilen = (byte)sArray.Length; // if not at least two, just return an object with 0 marked, basically error condition. if (ilen <= 1) { return kcData; } // if 2 string then let's try and convert them to proper Unity KeyCodes. if (ilen == 2) { kcData.kCode1 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[0].ToString()); kcData.kCode2 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[1].ToString()); kcData.NumOfCodes = 2; } else { // if 3 strings then let's try and convert first three to proper Unity KeyCodes. kcData.kCode1 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[0].ToString()); kcData.kCode2 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[1].ToString()); kcData.kCode3 = (KeyCode)Enum.Parse(typeof(KeyCode), sArray[2].ToString()); kcData.NumOfCodes = 3; } if (SomeModName.DEBUG_LOG_ON) { Logger.dbgLog("Alternate Keys bound: " + kcData.NumOfCodes.ToString()); } } catch(Exception ex) { Logger.dbgLog(ex.Message.ToString(), ex, true); } // We check if our kCodes1 or 2 are "None", if they are then there were problems and lets just use // our default values and return a well formed object. if ((kcData.kCode1 == KeyCode.None) || kcData.kCode2 == KeyCode.None) { kcData.kCode1 = KeyCode.LeftControl; kcData.kCode2 = KeyCode.LeftAlt; kcData.kCode3 = KeyCode.L; kcData.NumOfCodes = 3; Logger.dbgLog("Alternate Keys enabled but used incorrectly, using default alternate."); } return kcData; }