/// <summary> /// update the script /// </summary> private void Update() { MIControllerState state = MIInputManager.ControllerState; this.touchDownCount += state.TouchDown ? 1 : 0; this.touchUpCount += state.TouchUp ? 1 : 0; this.clickDownCount += state.ClickButtonDown ? 1 : 0; this.clickUpCount += state.ClickButtonUp ? 1 : 0; this.appDownCount += state.AppButtonDown ? 1 : 0; this.appUpCount += state.AppButtonUp ? 1 : 0; this.recenteredCount += state.Recentered ? 1 : 0; StringBuilder result = new StringBuilder(); result.AppendFormat("connection state: {0}", state.ConnectionState); result.AppendLine(); result.AppendFormat("IsTouching {0}", state.IsTouching); result.AppendLine(); result.AppendFormat("TouchDown count: {0}", this.touchDownCount); result.AppendLine(); result.AppendFormat("TouchUp count: {0}", this.touchUpCount); result.AppendLine(); result.AppendFormat("Touch position x: {0}, y: {1}", state.TouchPosition.x, state.TouchPosition.y); result.AppendLine(); result.AppendFormat("Click button state is {0}", state.ClickButtonState); result.AppendLine(); result.AppendFormat("Click button down count is {0}", this.clickDownCount); result.AppendLine(); result.AppendFormat("Click button up count is {0}", this.clickUpCount); result.AppendLine(); result.AppendFormat("App button state is {0}", state.AppButtonState); result.AppendLine(); result.AppendFormat("App button down count is {0}", this.appDownCount); result.AppendLine(); result.AppendFormat("App button up count is {0}", this.appUpCount); result.AppendLine(); result.AppendFormat("Recentered count is {0}", this.recenteredCount); result.AppendLine(); this.textUI.text = result.ToString(); this.controller.transform.rotation = state.Orientation * new Quaternion(0, 1, 0, 0); }
/// <summary> /// Converts the state. /// </summary> /// <param name="nativeState">State of the native.</param> /// <returns>the controller state</returns> private static MIControllerState ConvertState(NativeControllerState nativeState) { MIControllerState state = new MIControllerState(); #if UNITY_ANDROID && !UNITY_EDITOR switch (nativeState.ConnectionState) { case 0: state.ConnectionState = MIConnectionState.Disconnected; break; case 1: state.ConnectionState = MIConnectionState.Connected; break; case 2: state.ConnectionState = MIConnectionState.Connecting; break; default: state.ConnectionState = MIConnectionState.Disconnected; break; } state.IsTouching = nativeState.IsTouching == 0x01; state.TouchDown = nativeState.TouchDown == 0x01; state.TouchUp = nativeState.TouchUp == 0x01; state.TouchPosition = new Vector2(nativeState.TouchPos.X, nativeState.TouchPos.Y); state.Orientation = new Quaternion(nativeState.Orientation.X, nativeState.Orientation.Y, nativeState.Orientation.Z, nativeState.Orientation.W); const int ClickButtonIndex = 0; state.ClickButtonState = nativeState.ButtonState[ClickButtonIndex] == 0x01; state.ClickButtonDown = nativeState.ButtonDown[ClickButtonIndex] == 0x01; state.ClickButtonUp = nativeState.ButtonUp[ClickButtonIndex] == 0x01; const int AppButtonIndex = 1; state.AppButtonState = nativeState.ButtonState[AppButtonIndex] == 0x01; state.AppButtonDown = nativeState.ButtonDown[AppButtonIndex] == 0x01; state.AppButtonUp = nativeState.ButtonUp[AppButtonIndex] == 0x01; state.Recentered = nativeState.Recentered == 0x01; #endif return(state); }