void KnobDelegate(MidiChannel channel, int knobnumber, float knobvalue)
        {
            var publishEvent = true;

            switch (knobnumber)
            {
            case 0x0D:
                m_State.SendA1 = knobvalue;
                break;

            case 0x0E:
                m_State.SendA2 = knobvalue;
                break;

            case 0x0F:
                m_State.SendA3 = knobvalue;
                break;

            case 0x10:
                m_State.SendA4 = knobvalue;
                break;

            case 0x11:
                m_State.SendA5 = knobvalue;
                break;

            case 0x12:
                m_State.SendA6 = knobvalue;
                break;

            case 0x13:
                m_State.SendA7 = knobvalue;
                break;

            case 0x14:
                m_State.SendA8 = knobvalue;
                break;

            case 0x1D:
                m_State.SendB1 = knobvalue;
                break;

            case 0x1E:
                m_State.SendB2 = knobvalue;
                break;

            case 0x1F:
                m_State.SendB3 = knobvalue;
                break;

            case 0x20:
                m_State.SendB4 = knobvalue;
                break;

            case 0x21:
                m_State.SendB5 = knobvalue;
                break;

            case 0x22:
                m_State.SendB6 = knobvalue;
                break;

            case 0x23:
                m_State.SendB7 = knobvalue;
                break;

            case 0x24:
                m_State.SendB8 = knobvalue;
                break;

            case 0x31:
                m_State.PanDevice1 = knobvalue;
                break;

            case 0x32:
                m_State.PanDevice2 = knobvalue;
                break;

            case 0x33:
                m_State.PanDevice3 = knobvalue;
                break;

            case 0x34:
                m_State.PanDevice4 = knobvalue;
                break;

            case 0x35:
                m_State.PanDevice5 = knobvalue;
                break;

            case 0x36:
                m_State.PanDevice6 = knobvalue;
                break;

            case 0x37:
                m_State.PanDevice7 = knobvalue;
                break;

            case 0x38:
                m_State.PanDevice8 = knobvalue;
                break;

            case 0x4D:
                m_State.Slider1 = knobvalue;
                break;

            case 0x4E:
                m_State.Slider2 = knobvalue;
                break;

            case 0x4F:
                m_State.Slider3 = knobvalue;
                break;

            case 0x50:
                m_State.Slider4 = knobvalue;
                break;

            case 0x51:
                m_State.Slider5 = knobvalue;
                break;

            case 0x52:
                m_State.Slider6 = knobvalue;
                break;

            case 0x53:
                m_State.Slider7 = knobvalue;
                break;

            case 0x54:
                m_State.Slider8 = knobvalue;
                break;

            default:
                publishEvent = false;
                break;
            }

            if (publishEvent)
            {
                InputSystem.QueueStateEvent(this, m_State);
            }
        }
Exemplo n.º 2
0
        private static unsafe bool ProcessMessageFromUnityRemote(IntPtr messageData)
        {
            var messageHeader = (MessageHeader *)messageData;

            switch (messageHeader->type)
            {
            case (byte)MessageType.Hello:
                if (s_State.connected)
                {
                    break;
                }

                // Install handlers.
                s_State.deviceChangeHandler  = OnDeviceChange;
                s_State.deviceCommandHandler = OnDeviceCommand;     ////REVIEW: We really should have a way of installing a handler just for a specific device.
                InputSystem.onDeviceChange  += s_State.deviceChangeHandler;
                InputSystem.onDeviceCommand += s_State.deviceCommandHandler;

                // Add devices.
                s_State.touchscreen = InputSystem.AddDevice <Touchscreen>();
                s_State.touchscreen.m_DeviceFlags   |= InputDevice.DeviceFlags.Remote;
                s_State.accelerometer                = InputSystem.AddDevice <Accelerometer>();
                s_State.accelerometer.m_DeviceFlags |= InputDevice.DeviceFlags.Remote;
                // Gryo etc. added only when we receive GyroSettingsMessage.

                s_State.connected = true;
                Debug.Log("Unity Remote connected to input!");
                break;

            case (byte)MessageType.Goodbye:
                if (!s_State.connected)
                {
                    break;
                }
                Disconnect();
                Debug.Log("Unity Remote disconnected from input!");
                break;

            case (byte)MessageType.Options:
                var optionsMessage = (OptionsMessage *)messageData;
                s_State.screenSize = DetermineScreenSize(optionsMessage->dimension1, optionsMessage->dimension2);
                break;

            case (byte)MessageType.TouchInput:
                if (s_State.touchscreen == null)
                {
                    break;
                }
                // Android Remote seems to not be sending the last two fields (azimuthAngle and attitudeAngle).
                if (messageHeader->length < 56)
                {
                    break;
                }
                var touchMessage = (TouchInputMessage *)messageData;
                var phase        = TouchPhase.None;
                switch (touchMessage->phase)
                {
                case (int)UnityEngine.TouchPhase.Began: phase = TouchPhase.Began; break;

                case (int)UnityEngine.TouchPhase.Canceled: phase = TouchPhase.Canceled; break;

                case (int)UnityEngine.TouchPhase.Ended: phase = TouchPhase.Ended; break;

                case (int)UnityEngine.TouchPhase.Moved: phase = TouchPhase.Moved; break;
                    // Ignore stationary.
                }
                if (phase == default)
                {
                    break;
                }
                InputSystem.QueueStateEvent(s_State.touchscreen, new TouchState
                {
                    touchId  = touchMessage->id + 1,
                    phase    = phase,
                    position = MapRemoteTouchCoordinatesToLocal(new Vector2(touchMessage->positionX, touchMessage->positionY)),
                    radius   = new Vector2(touchMessage->radius, touchMessage->radius),
                    pressure = touchMessage->pressure
                });
                break;

            case (byte)MessageType.GyroSettings:
                var gyroSettingsMessage = (GyroSettingsMessage *)messageData;
                if (!s_State.gyroInitialized)
                {
                    // Message itself indicates presence of a gyro. Add the devices.
                    s_State.gyroscope                         = InputSystem.AddDevice <Gyroscope>();
                    s_State.attitude                          = InputSystem.AddDevice <AttitudeSensor>();
                    s_State.gravity                           = InputSystem.AddDevice <GravitySensor>();
                    s_State.linearAcceleration                = InputSystem.AddDevice <LinearAccelerationSensor>();
                    s_State.gyroscope.m_DeviceFlags          |= InputDevice.DeviceFlags.Remote;
                    s_State.attitude.m_DeviceFlags           |= InputDevice.DeviceFlags.Remote;
                    s_State.gravity.m_DeviceFlags            |= InputDevice.DeviceFlags.Remote;
                    s_State.linearAcceleration.m_DeviceFlags |= InputDevice.DeviceFlags.Remote;

                    s_State.gyroInitialized = true;
                }
                // Disable them if they are not currently enabled.
                if (gyroSettingsMessage->enabled == 0)
                {
                    InputSystem.DisableDevice(s_State.gyroscope);
                    InputSystem.DisableDevice(s_State.attitude);
                    InputSystem.DisableDevice(s_State.gravity);
                    InputSystem.DisableDevice(s_State.linearAcceleration);
                }
                else
                {
                    s_State.gyroEnabled = true;
                }
                s_State.gyroUpdateInterval = gyroSettingsMessage->receivedGyroUpdateInternal;
                break;

            case (byte)MessageType.GyroInput:
                var gyroInputMessage = (GyroInputMessage *)messageData;
                if (s_State.attitude != null && s_State.attitude.enabled)
                {
                    InputSystem.QueueStateEvent(s_State.attitude, new AttitudeState
                    {
                        attitude = new Quaternion(gyroInputMessage->attitudeX, gyroInputMessage->attitudeY, gyroInputMessage->attitudeZ,
                                                  gyroInputMessage->attitudeW)
                    });
                }
                if (s_State.gyroscope != null && s_State.gyroscope.enabled)
                {
                    InputSystem.QueueStateEvent(s_State.gyroscope, new GyroscopeState
                    {
                        angularVelocity = new Vector3(gyroInputMessage->rotationRateX, gyroInputMessage->rotationRateY,
                                                      gyroInputMessage->rotationRateZ)
                    });
                }
                if (s_State.gravity != null && s_State.gravity.enabled)
                {
                    InputSystem.QueueStateEvent(s_State.gravity, new GravityState
                    {
                        gravity = new Vector3(gyroInputMessage->gravityX, gyroInputMessage->gravityY,
                                              gyroInputMessage->gravityZ)
                    });
                }
                if (s_State.linearAcceleration != null && s_State.linearAcceleration.enabled)
                {
                    InputSystem.QueueStateEvent(s_State.linearAcceleration, new LinearAccelerationState
                    {
                        acceleration = new Vector3(gyroInputMessage->userAccelerationX, gyroInputMessage->userAccelerationY,
                                                   gyroInputMessage->userAccelerationZ)
                    });
                }
                break;

            case (byte)MessageType.AccelerometerInput:
                if (s_State.accelerometer == null)
                {
                    break;
                }
                var accelerometerMessage = (AccelerometerInputMessage *)messageData;
                InputSystem.QueueStateEvent(s_State.accelerometer, new AccelerometerState
                {
                    acceleration = new Vector3(accelerometerMessage->accelerationX, accelerometerMessage->accelerationY,
                                               accelerometerMessage->accelerationZ)
                });
                break;
            }

            return(false);
        }