コード例 #1
0
        public void ReadState(ControllerState outState, int controller_id)
        {
            if (controller_id >= MaxControllerCount)
            {
                return;
            }
#if UNITY_ANDROID
            if (InstantPreview.IsActive &&
                !EmulatorManager.Instance.Connected)
            {
                // Uses Instant Preview to get controller state if connected.
                instantPreviewControllerProvider.ReadState(outState, controller_id);
                return;
            }
#endif // UNITY_ANDROID

            // If Instant Preview is not connected, tries to use the emulator or
            // mouse.
            emulatorControllerProvider.ReadState(emulatorState, controller_id);
            mouseControllerProvider.ReadState(mouseState, controller_id);

            // Defaults to mouse state if the emulator isn't available.
            if (emulatorState.connectionState != GvrConnectionState.Connected &&
                mouseState.connectionState == GvrConnectionState.Connected)
            {
                outState.CopyFrom(mouseState);
            }
            else
            {
                outState.CopyFrom(emulatorState);
            }
        }
コード例 #2
0
        public void ReadState(ControllerState outState)
        {
#if UNITY_HAS_GOOGLEVR
            if (InstantPreview.Instance != null &&
                InstantPreview.Instance.IsCurrentlyConnected &&
                !EmulatorManager.Instance.Connected)
            {
                // Uses Instant Preview to get controller state if connected.
                instantPreviewControllerProvider.ReadState(outState);
                return;
            }
#endif // UNITY_HAS_GOOGLEVR

            // If Instant Preview is not connected, tries to use the emulator or
            // mouse.
            emulatorControllerProvider.ReadState(emulatorState);
            mouseControllerProvider.ReadState(mouseState);

            // Defaults to mouse state if the emulator isn't available.
            if (emulatorState.connectionState != GvrConnectionState.Connected &&
                mouseState.connectionState == GvrConnectionState.Connected)
            {
                outState.CopyFrom(mouseState);
            }
            else
            {
                outState.CopyFrom(emulatorState);
            }
        }
コード例 #3
0
        public void ReadState(ControllerState outState)
        {
#if UNITY_HAS_GOOGLEVR && UNITY_ANDROID
            if (InstantPreview.Instance != null && InstantPreview.Instance.IsCurrentlyConnected &&
                !EmulatorManager.Instance.Connected)
            {
                // Uses Instant Preview to get controller state if connected.
                instantPreviewControllerProvider.ReadState(outState);
                return;
            }
#endif // UNITY_HAS_GOOGLEVR && UNITY_ANDROID
            // If Instant Preview is not connected, tries to use the Controller Emulator.
            lock (state) {
                state.connectionState = GvrConnectionState.Connected;
                if (!EmulatorManager.Instance.Connected)
                {
                    state.connectionState = EmulatorManager.Instance.Connecting ?
                                            GvrConnectionState.Connecting : GvrConnectionState.Disconnected;
                }
                state.apiStatus = EmulatorManager.Instance.Connected ? GvrControllerApiStatus.Ok :
                                  GvrControllerApiStatus.Unavailable;

                // During emulation, just assume the controller is fully charged
                state.isCharging   = false;
                state.batteryLevel = GvrControllerBatteryLevel.Full;

                outState.CopyFrom(state);
            }
            state.ClearTransientState();
        }
コード例 #4
0
        public void ReadState(ControllerState outState, int controller_id)
        {
            emulatorControllerProvider.ReadState(emulatorState, controller_id);
            mouseControllerProvider.ReadState(mouseState, controller_id);

            // Defaults to mouse state if the emulator isn't available.
            if (emulatorState.connectionState != GvrConnectionState.Connected &&
                mouseState.connectionState == GvrConnectionState.Connected)
            {
                outState.CopyFrom(mouseState);
            }
            else
            {
                outState.CopyFrom(emulatorState);
            }
        }
コード例 #5
0
        public void ReadState(ControllerState outState)
        {
            if (InstantPreview.Instance != null && InstantPreview.Instance.IsCurrentlyConnected)
            {
                // Uses Instant Preview to get controller state if connected.
                instantPreviewControllerProvider.ReadState(outState);
            }
            else
            {
                // If Instant Preview is not connected, tries to use the Controller Emulator.
                lock (state) {
                    state.connectionState = EmulatorManager.Instance.Connected ? GvrConnectionState.Connected :
                                            GvrConnectionState.Connecting;
                    state.apiStatus = EmulatorManager.Instance.Connected ? GvrControllerApiStatus.Ok :
                                      GvrControllerApiStatus.Unavailable;

                    // During emulation, just assume the controller is fully charged
                    state.isCharging   = false;
                    state.batteryLevel = GvrControllerBatteryLevel.Full;

                    outState.CopyFrom(state);
                }
                state.ClearTransientState();
            }
        }
コード例 #6
0
        public void ReadState(ControllerState outState, int controller_id)
        {
            if (controller_id != 0)
            {
                return;
            }
            lock (state) {
                state.connectionState = GvrConnectionState.Connected;
                if (!EmulatorManager.Instance.Connected)
                {
                    state.connectionState = EmulatorManager.Instance.Connecting ?
                                            GvrConnectionState.Connecting : GvrConnectionState.Disconnected;
                }
                state.apiStatus = EmulatorManager.Instance.Connected ? GvrControllerApiStatus.Ok :
                                  GvrControllerApiStatus.Unavailable;

                // During emulation, just assume the controller is fully charged
                state.isCharging   = false;
                state.batteryLevel = GvrControllerBatteryLevel.Full;

                state.SetButtonsUpDownFromPrevious(lastButtonsState);
                lastButtonsState = state.buttonsState;

                outState.CopyFrom(state);
            }
            state.ClearTransientState();
        }
コード例 #7
0
        public void ReadState(ControllerState outState, int controller_id)
        {
            if (controller_id != 0)
            {
                outState.CopyFrom(dummyState);
                return;
            }

            lock (state)
            {
                UpdateState();

                outState.CopyFrom(state);
            }

            state.ClearTransientState();
        }
コード例 #8
0
        public void ReadState(ControllerState outState)
        {
            // If Instant Preview is not connected, tries to use the emulator or
            // mouse.
            mouseControllerProvider.ReadState(mouseState);

            // Defaults to mouse state if the emulator isn't available.
            if (emulatorState.connectionState != GvrConnectionState.Connected &&
                mouseState.connectionState == GvrConnectionState.Connected)
            {
                outState.CopyFrom(mouseState);
            }
            else
            {
                outState.CopyFrom(emulatorState);
            }
        }
コード例 #9
0
        public void ReadState(ControllerState outState)
        {
            lock (state) {
                UpdateState();

                outState.CopyFrom(state);
            }
            state.ClearTransientState();
        }
コード例 #10
0
 public void ReadState(ControllerState outState)
 {
     lock (state) {
         state.connectionState = EmulatorManager.Instance.Connected ? GvrConnectionState.Connected :
                                 GvrConnectionState.Connecting;
         outState.CopyFrom(state);
     }
     state.ClearTransientState();
 }
コード例 #11
0
        public void ReadState(ControllerState outState)
        {
            outState.orientation = Quaternion.identity;
            lock (state) {
                UpdateState();

                outState.CopyFrom(state);
            }
            state.ClearTransientState();
        }
コード例 #12
0
 public void ReadState(ControllerState outState) {
   lock (state) {
     state.connectionState = EmulatorManager.Instance.Connected ? GvrConnectionState.Connected :
         GvrConnectionState.Connecting;
     state.apiStatus = EmulatorManager.Instance.Connected ? GvrControllerApiStatus.Ok :
         GvrControllerApiStatus.Unavailable;
     outState.CopyFrom(state);
   }
   state.ClearTransientState();
 }
 public void ReadState(ControllerState outState)
 {
     lock (state) {
         state.connectionState = EmulatorManager.Instance.Connected ? GvrConnectionState.Connected :
                                 GvrConnectionState.Connecting;
         state.apiStatus = EmulatorManager.Instance.Connected ? GvrControllerApiStatus.Ok :
                           GvrControllerApiStatus.Unavailable;
         outState.CopyFrom(state);
     }
     state.ClearTransientState();
 }
コード例 #14
0
        public void ReadState(ControllerState outState)
        {
            lock (state) {
                state.connectionState = EmulatorManager.Instance.Connected ? GvrConnectionState.Connected :
                                        GvrConnectionState.Connecting;
                state.apiStatus = EmulatorManager.Instance.Connected ? GvrControllerApiStatus.Ok :
                                  GvrControllerApiStatus.Unavailable;

                // During emulation, just assume the controller is fully charged
                state.isCharging   = false;
                state.batteryLevel = GvrControllerBatteryLevel.Full;

                outState.CopyFrom(state);
            }
            state.ClearTransientState();
        }
コード例 #15
0
 public void ReadState(ControllerState outState)
 {
     lock (state) {
     state.connectionState = EmulatorManager.Instance.Connected ? GvrConnectionState.Connected :
     GvrConnectionState.Connecting;
     outState.CopyFrom(state);
       }
       state.ClearTransientState();
 }
コード例 #16
0
 public void ReadState(ControllerState outState)
 {
     outState.CopyFrom(dummyState);
 }
コード例 #17
0
        // this is called every frame
        void IControllerProvider.ReadState(ControllerState outState)
        {
            lock (state) {
                if (ctrl != null)
                {
                    XDevicePlugin.UpdateInputState(handle);
                    XDevicePlugin.GetInputState(handle, ref m_leftControllerState);
                    state.orientation = new Quaternion(
                        -m_leftControllerState.rotation[0],
                        -m_leftControllerState.rotation[1],
                        m_leftControllerState.rotation[2],
                        m_leftControllerState.rotation[3]
                        );
                    state.gyro = new Vector3(
                        -m_leftControllerState.gyroscope[0],
                        -m_leftControllerState.gyroscope[1],
                        m_leftControllerState.gyroscope[2]
                        );
                    state.accel = new Vector3(
                        m_leftControllerState.accelerometer[0],
                        m_leftControllerState.accelerometer[1],
                        -m_leftControllerState.accelerometer[2]
                        );
                    state.touchPos = ctrl.touchPos;
                    // GVR Hack Detection Controller
                    if (ctrl.connectionState == DeviceConnectionState.Connected)
                    {
                        state.connectionState = GvrConnectionState.Connected;
                    }
                    else if (ctrl.connectionState == DeviceConnectionState.Connecting)
                    {
                        state.connectionState = GvrConnectionState.Connecting;
                    }
                    else
                    {
                        state.connectionState = GvrConnectionState.Disconnected;
                    }

                    // GVR Input Mapping
                    state.apiStatus        = GvrControllerApiStatus.Ok;
                    state.appButtonState   = ctrl.GetButton(XimmerseButton.App);
                    state.appButtonDown    = ctrl.GetButtonDown(XimmerseButton.App);
                    state.appButtonUp      = ctrl.GetButtonUp(XimmerseButton.App);
                    state.homeButtonDown   = ctrl.GetButtonDown(XimmerseButton.Home);
                    state.homeButtonState  = ctrl.GetButton(XimmerseButton.Home);
                    state.clickButtonDown  = ctrl.GetButtonDown(XimmerseButton.Click) || ctrl.GetButtonDown(XimmerseButton.Trigger);
                    state.clickButtonState = ctrl.GetButton(XimmerseButton.Click) || ctrl.GetButton(XimmerseButton.Trigger);
                    state.clickButtonUp    = ctrl.GetButtonUp(XimmerseButton.Click) || ctrl.GetButtonUp(XimmerseButton.Trigger);

                    // GVR Battery Indicator
                    if (ctrl.batteryLevel > 80)
                    {
                        state.batteryLevel = GvrControllerBatteryLevel.Full;
                    }
                    if (ctrl.batteryLevel > 60 && ctrl.batteryLevel <= 80)
                    {
                        state.batteryLevel = GvrControllerBatteryLevel.AlmostFull;
                    }
                    if (ctrl.batteryLevel > 40 && ctrl.batteryLevel <= 60)
                    {
                        state.batteryLevel = GvrControllerBatteryLevel.Medium;
                    }
                    if (ctrl.batteryLevel > 20 && ctrl.batteryLevel <= 40)
                    {
                        state.batteryLevel = GvrControllerBatteryLevel.Low;
                    }
                    if (ctrl.batteryLevel >= 0 && ctrl.batteryLevel <= 20)
                    {
                        state.batteryLevel = GvrControllerBatteryLevel.CriticalLow;
                    }

                    // GVR Recenter Touchpad Detection
                    if (ctrl.GetButtonDown(ControllerButton.PrimaryThumbMove) || ctrl.GetButtonDown(XimmerseButton.Click))
                    {
                        state.touchDown  = true;
                        state.isTouching = true;
                    }
                    if (ctrl.GetButton(ControllerButton.PrimaryThumbMove) || ctrl.GetButton(XimmerseButton.Click))
                    {
                        state.isTouching = true;
                    }
                    if (ctrl.GetButtonUp(ControllerButton.PrimaryThumbMove) || ctrl.GetButtonUp(XimmerseButton.Click))
                    {
                        state.touchUp    = true;
                        state.isTouching = false;
                    }


                    // GVR Recenter Interactions
                    state.gvrPtr = IntPtr.Zero;

                    if (ctrl.GetButtonUp(XimmerseButton.Home))
                    {
                        GvrCardboardHelpers.Recenter();
                        ctrl.Recenter();
                        state.recentered = true;
                    }
                }

                else
                {
                    if (EnableXdevice == false && FlipAppInstalled() == true)
                    {
                        EnableXdevice = true;
                        XDevicePlugin.Init();
                        handle = XDevicePlugin.GetInputDeviceHandle("XCobra-0");
                        ctrl   = new ControllerInput(handle);
                    }
                    state.connectionState  = GvrConnectionState.Disconnected;
                    state.clickButtonState = false;
                    state.clickButtonDown  = false;
                    state.clickButtonUp    = false;
                    state.appButtonState   = false;
                    state.appButtonDown    = false;
                    state.appButtonUp      = false;
                }


                outState.CopyFrom(state);
            }
            state.ClearTransientState();
        }
コード例 #18
0
 public void ReadState(ControllerState outState) {
   outState.CopyFrom(dummyState);
 }