private void Initialize() { ReInput.InputSourceUpdateEvent += new Action(this.OnInputSourceUpdate); this.touchController = base.GetComponent <TouchControllerExample>(); this.axisCount = this.touchController.joysticks.Length * 2; this.buttonCount = this.touchController.buttons.Length; this.axisValues = new float[this.axisCount]; this.buttonValues = new bool[this.buttonCount]; Player player = ReInput.players.GetPlayer(this.playerId); this.controller = player.controllers.GetControllerWithTag <CustomController>(this.controllerTag); if (this.controller == null) { Debug.LogError("A matching controller was not found for tag \"" + this.controllerTag + "\""); } if (this.controller.buttonCount != this.buttonValues.Length || this.controller.axisCount != this.axisValues.Length) { Debug.LogError("Controller has wrong number of elements!"); } if (this.useUpdateCallbacks && this.controller != null) { this.controller.SetAxisUpdateCallback(new Func <int, float>(this.GetAxisValueCallback)); this.controller.SetButtonUpdateCallback(new Func <int, bool>(this.GetButtonValueCallback)); } this.initialized = true; }
private void Initialize() { // Subscribe to the input source update event so we can update our source element data before controllers are updated ReInput.InputSourceUpdateEvent += OnInputSourceUpdate; // Get the touch controller touchController = GetComponent <TouchControllerExample>(); // Get expected element counts axisCount = touchController.joysticks.Length * 2; // 2 axes per stick buttonCount = touchController.buttons.Length; // Set up arrays to store our current source element values axisValues = new float[axisCount]; buttonValues = new bool[buttonCount]; // Find the controller we want to manage Player player = ReInput.players.GetPlayer(playerId); // get the player controller = player.controllers.GetControllerWithTag <CustomController>(controllerTag); // get the controller if (controller == null) { Debug.LogError("A matching controller was not found for tag \"" + controllerTag + "\""); } // Verify controller has the number of elements we're expecting if (controller.buttonCount != buttonValues.Length || controller.axisCount != axisValues.Length) // controller has wrong number of elements { Debug.LogError("Controller has wrong number of elements!"); } // Callback Update Method: // Set callbacks to retrieve current element values. // This is a different way of updating the element values in the controller. // You set an update function for axes and buttons and these functions will be called // to retrieve the current source element values on every update loop in which input is updated. if (useUpdateCallbacks && controller != null) { controller.SetAxisUpdateCallback(GetAxisValueCallback); controller.SetButtonUpdateCallback(GetButtonValueCallback); } initialized = true; }
private void Initialize() { // Subscribe to the input source update event so we can update our source element data before controllers are updated ReInput.InputSourceUpdateEvent += OnInputSourceUpdate; // Get the touch controller touchController = GetComponent<Demos.TouchControllerExample>(); // Get expected element counts axisCount = touchController.joysticks.Length * 2; // 2 axes per stick buttonCount = touchController.buttons.Length; // Set up arrays to store our current source element values axisValues = new float[axisCount]; buttonValues = new bool[buttonCount]; // Find the controller we want to manage Player player = ReInput.players.GetPlayer(playerId); // get the player controller = player.controllers.GetControllerWithTag<CustomController>(controllerTag); // get the controller if(controller == null) { Debug.LogError("A matching controller was not found for tag \"" + controllerTag + "\""); } // Verify controller has the number of elements we're expecting if(controller.buttonCount != buttonValues.Length || controller.axisCount != axisValues.Length) { // controller has wrong number of elements Debug.LogError("Controller has wrong number of elements!"); } // Callback Update Method: // Set callbacks to retrieve current element values. // This is a different way of updating the element values in the controller. // You set an update function for axes and buttons and these functions will be called // to retrieve the current source element values on every update loop in which input is updated. if(useUpdateCallbacks && controller != null) { controller.SetAxisUpdateCallback(GetAxisValueCallback); controller.SetButtonUpdateCallback(GetButtonValueCallback); } initialized = true; }