protected override void Awake() { keyboard = new KeyboardInputModel(commandList, keyBoardInputList); for (int i = 0; i < k_playerCount; i++) { joystickInput[i] = new XboxInputModel(i + 1); controllers[i] = new ControllerInputModel(joystickInput[i], commandList, controllerInputList); } StartCoroutine(DetectGameController()); base.Awake(); }
public ControllerInputModel(XboxInputModel input, string[] commandList, string[] controllerKeys) { if (input == null || input.JoyStickNumber <= 0) { throw new System.ArgumentException("Input is null or haven't intialized"); } if (commandList.Length != controllerKeys.Length) { throw new System.ArgumentException("Length of the arraies don't match"); } this.input = input; axisMap = new Dictionary <string, XboxControllerInputAxis>(); buttonMap = new Dictionary <string, XboxControllerInputButton>(); axisAlternativeMap = new Dictionary <string, XboxControllerInputAxis>(); buttonAlternativeMap = new Dictionary <string, XboxControllerInputButton>(); for (int i = 0; i < commandList.Length; i++) { if (System.Enum.IsDefined(typeof(XboxControllerInputButton), controllerKeys[i])) { var button = (XboxControllerInputButton)System.Enum.Parse(typeof(XboxControllerInputButton), controllerKeys[i]); if (!buttonMap.ContainsKey(commandList[i])) { buttonMap.Add(commandList[i], button); } else { buttonAlternativeMap.Add(commandList[i], button); } continue; } if (System.Enum.IsDefined(typeof(XboxControllerInputAxis), controllerKeys[i])) { var axis = (XboxControllerInputAxis)System.Enum.Parse(typeof(XboxControllerInputAxis), controllerKeys[i]); if (!axisMap.ContainsKey(commandList[i])) { axisMap.Add(commandList[i], axis); } else { axisAlternativeMap.Add(commandList[i], axis); } continue; } Debug.Log("Cannot parse the key " + controllerKeys[i]); } }