Esempio n. 1
0
            protected override void ContextClickedItem(int id)
            {
                var item = FindItem(id, rootItem);

                if (item == null)
                {
                    return;
                }

                if (item is DeviceItem deviceItem)
                {
                    var menu = new GenericMenu();
                    menu.AddItem(Contents.openDebugView, false, () => InputDeviceDebuggerWindow.CreateOrShowExisting(deviceItem.device));
                    menu.AddItem(Contents.removeDevice, false, () => InputSystem.RemoveDevice(deviceItem.device));
                    if (deviceItem.device.enabled)
                    {
                        menu.AddItem(Contents.disableDevice, false, () => InputSystem.DisableDevice(deviceItem.device));
                    }
                    else
                    {
                        menu.AddItem(Contents.enableDevice, false, () => InputSystem.EnableDevice(deviceItem.device));
                    }
                    menu.ShowAsContext();
                }
            }
            protected override void ContextClickedItem(int id)
            {
                var item = FindItem(id, rootItem);

                if (item == null)
                {
                    return;
                }

                if (item is DeviceItem deviceItem)
                {
                    var menu = new GenericMenu();
                    menu.AddItem(Contents.openDebugView, false, () => InputDeviceDebuggerWindow.CreateOrShowExisting(deviceItem.device));
                    menu.AddItem(Contents.copyDeviceDescription, false,
                                 () => EditorGUIUtility.systemCopyBuffer = deviceItem.device.description.ToJson());
                    menu.AddItem(Contents.removeDevice, false, () => InputSystem.RemoveDevice(deviceItem.device));
                    if (deviceItem.device.enabled)
                    {
                        menu.AddItem(Contents.disableDevice, false, () => InputSystem.DisableDevice(deviceItem.device));
                    }
                    else
                    {
                        menu.AddItem(Contents.enableDevice, false, () => InputSystem.EnableDevice(deviceItem.device));
                    }
                    menu.ShowAsContext();
                }

                if (item is UnsupportedDeviceItem unsupportedDeviceItem)
                {
                    var menu = new GenericMenu();
                    menu.AddItem(Contents.copyDeviceDescription, false,
                                 () => EditorGUIUtility.systemCopyBuffer = unsupportedDeviceItem.description.ToJson());
                    menu.ShowAsContext();
                }
            }
Esempio n. 3
0
    private void SwitchToKeyboard()
    {
        int  count    = SceneManager.sceneCount;
        bool canEvent = false;

        Debug.Log("count: " + count);
        for (int i = 0; i < count; i++)
        {
            string name = SceneManager.GetSceneAt(i).name;
            Debug.Log(name);
            if (name == "CurrentLevelScene")
            {
                canEvent = true;
            }
        }
        if (keyboardEvent != null && canEvent)
        {
            keyboardEvent();
        }
        InputSystem.EnableDevice(Keyboard.current);
        InputSystem.EnableDevice(Mouse.current);
        if (Gamepad.current != null)
        {
            InputSystem.DisableDevice(Gamepad.current);
        }
    }
Esempio n. 4
0
 private void DisableConflictingDevice(InputDevice device)
 {
     if (device.native && (device is Mouse || device is Pen) && device.enabled)
     {
         InputSystem.DisableDevice(device);
         m_DisabledDevices.Add(device);
     }
 }
Esempio n. 5
0
    public void Remote_CanReceiveAccelerometerInputFromUnityRemote()
    {
        SendUnityRemoteMessage(UnityRemoteSupport.HelloMessage.Create());

        // Should always be created. For gyros, we have explicit "is present?" logic but
        // accelerometers are assumed to be present on every mobile device running the Unity Remote.
        Assert.That(Accelerometer.current, Is.Not.Null);
        Assert.That(Accelerometer.current.remote, Is.True);

        // Also, it should not require explicit enabling.
        Assert.That(Accelerometer.current.enabled, Is.True);

        // Update acceleration.
        SendUnityRemoteMessage(new UnityRemoteSupport.AccelerometerInputMessage
        {
            accelerationX = 123,
            accelerationY = 234,
            accelerationZ = 345,
            deltaTime     = 456
        });
        InputSystem.Update();

        Assert.That(Accelerometer.current.acceleration.ReadValue(), Is.EqualTo(new Vector3(123, 234, 345)));

        // Disabling it should work as normal.
        InputSystem.DisableDevice(Accelerometer.current);

        SendUnityRemoteMessage(new UnityRemoteSupport.AccelerometerInputMessage
        {
            accelerationX = 234,
            accelerationY = 345,
            accelerationZ = 456,
            deltaTime     = 567
        });
        InputSystem.Update();

        Assert.That(Accelerometer.current.acceleration.ReadValue(), Is.EqualTo(new Vector3(123, 234, 345)));

        InputSystem.EnableDevice(Accelerometer.current);

        SendUnityRemoteMessage(new UnityRemoteSupport.AccelerometerInputMessage
        {
            accelerationX = 345,
            accelerationY = 456,
            accelerationZ = 567,
            deltaTime     = 678
        });
        InputSystem.Update();

        Assert.That(Accelerometer.current.acceleration.ReadValue(), Is.EqualTo(new Vector3(345, 456, 567)));

        SendUnityRemoteMessage(new UnityRemoteSupport.GoodbyeMessage());

        Assert.That(Accelerometer.current, Is.Null);
    }
Esempio n. 6
0
    void Start()
    {
        //
        // Debug
        //
        InputSystem.DisableDevice(Pointer.current);


        //mechModel = GameObject.FindGameObjectWithTag("MechModel");
        mechRB = GetComponent <Rigidbody>();
    }
 void OnApplicationPause(bool paused)
 {
     if (paused)
     {
         InputSystem.DisableDevice(Accelerometer.current);
     }
     else
     {
         InputSystem.EnableDevice(Accelerometer.current);
     }
 }
Esempio n. 8
0
            protected override void ContextClickedItem(int id)
            {
                var item = FindItem(id, rootItem);

                if (item == null)
                {
                    return;
                }

                if (item is DeviceItem deviceItem)
                {
                    var menu = new GenericMenu();
                    menu.AddItem(Contents.openDebugView, false, () => InputDeviceDebuggerWindow.CreateOrShowExisting(deviceItem.device));
                    menu.AddItem(Contents.copyDeviceDescription, false,
                                 () => EditorGUIUtility.systemCopyBuffer = deviceItem.device.description.ToJson());
                    menu.AddItem(Contents.removeDevice, false, () => InputSystem.RemoveDevice(deviceItem.device));
                    if (deviceItem.device.enabled)
                    {
                        menu.AddItem(Contents.disableDevice, false, () => InputSystem.DisableDevice(deviceItem.device));
                    }
                    else
                    {
                        menu.AddItem(Contents.enableDevice, false, () => InputSystem.EnableDevice(deviceItem.device));
                    }
                    menu.ShowAsContext();
                }

                if (item is UnsupportedDeviceItem unsupportedDeviceItem)
                {
                    var menu = new GenericMenu();
                    menu.AddItem(Contents.copyDeviceDescription, false,
                                 () => EditorGUIUtility.systemCopyBuffer = unsupportedDeviceItem.description.ToJson());
                    menu.ShowAsContext();
                }

                if (item is LayoutItem layoutItem)
                {
                    var layout = EditorInputControlLayoutCache.TryGetLayout(layoutItem.layoutName);
                    if (layout != null)
                    {
                        var menu = new GenericMenu();
                        menu.AddItem(Contents.copyLayoutAsJSON, false,
                                     () => EditorGUIUtility.systemCopyBuffer = layout.ToJson());
                        if (layout.isDeviceLayout)
                        {
                            menu.AddItem(Contents.createDeviceFromLayout, false,
                                         () => InputSystem.AddDevice(layout.name));
                        }
                        menu.ShowAsContext();
                    }
                }
            }
Esempio n. 9
0
        private void SetupButtons()
        {
            m_consoleInputField.onSelect.AddListener(str => InputSystem.DisableDevice(Keyboard.current));
            m_consoleInputField.onDeselect.AddListener(str => InputSystem.EnableDevice(Keyboard.current));

            m_sendButton.onClick.AddListener(() => m_cheatConsole.HandleLogInputCommand(m_consoleInputField.text));
            m_clearButton.onClick.AddListener(() =>
            {
                m_cheatConsole.HandleLogInputCommand("clearLogger");
                m_cheatConsole.HandleLogInputCommand("clearConsole");
            });
            m_closeButton.onClick.AddListener(m_debuggerView.CloseDebugger);
        }
Esempio n. 10
0
    private void StayWithKeyboard()
    {
        Debug.Log("KEYBOARD");
        text.text = "PRESS <sprite index=0> TO START";
        InputSystem.EnableDevice(Keyboard.current);
        InputSystem.EnableDevice(Mouse.current);
        if (Gamepad.current != null)
        {
            InputSystem.DisableDevice(Gamepad.current);
        }

        ListenInput(Keyboard.current);
    }
Esempio n. 11
0
    private void SwitchToGamepad()
    {
        if (Gamepad.current is UnityEngine.InputSystem.XInput.XInputController)
        {
            text.text = "PRESS <sprite index=1> TO START";
        }

        else if (Gamepad.current is UnityEngine.InputSystem.DualShock.DualShockGamepad)
        {
            text.text = "PRESS <sprite index=2> TO START";
        }

        InputSystem.EnableDevice(Gamepad.current);
        InputSystem.DisableDevice(Keyboard.current);
        InputSystem.DisableDevice(Mouse.current);
        ListenInput(Gamepad.current);
    }
Esempio n. 12
0
        public InputSystemBackend()
        {
            // UGUI gets confused when multiple pointers for example mouse and touchscreen are sending data at the same time.
            // @rene recommended disabling all native mice.
            m_DisabledDevices = new List <InputDevice>();
            foreach (var device in InputSystem.devices)
            {
                if (device.native && device is Mouse && device.enabled)
                {
                    InputSystem.DisableDevice(device);
                    m_DisabledDevices.Add(device);
                }
            }

            if (Touchscreen.current == null)
            {
                m_SimulatorTouchscreen = InputSystem.AddDevice <Touchscreen>();
            }
        }
Esempio n. 13
0
    private void OnDisable()
    {
        Debug.Log("Disable " + name, gameObject);
#if UNITY_ANDROID
        if (GravitySensor.current != null)
        {
            InputSystem.DisableDevice(GravitySensor.current);
            Debug.Log("Disabled gravity sensor");
        }
        else
        {
            if (OnScreenJoystick != null)
            {
                OnScreenJoystick.SetActive(false);
            }
            Debug.LogError("No gravity sensor");
        }
#endif

        Controls.Disable();
    }
Esempio n. 14
0
        protected void AddPointer(Pointer pointer)
        {
            if (pointer == null)
            {
                throw new ArgumentNullException(nameof(pointer));
            }

            // Ignore if already added.
            if (m_Pointers.ContainsReference(m_NumPointers, pointer))
            {
                return;
            }

            // Add to list.
            var numPointers = m_NumPointers;

            ArrayHelpers.AppendWithCapacity(ref m_Pointers, ref m_NumPointers, pointer);
            ArrayHelpers.AppendWithCapacity(ref m_CurrentPositions, ref numPointers, default);

            InputSystem.DisableDevice(pointer, keepSendingEvents: true);
        }
Esempio n. 15
0
    public virtual void DoGUI()
    {
        DoToolbar();
        if (GUILayout.Button(m_Device.enabled ? "Disable Device" : "Enable Device", Styles.BoldButton))
        {
            if (m_Device.enabled)
            {
                InputSystem.DisableDevice(m_Device);
            }
            else
            {
                InputSystem.EnableDevice(m_Device);
            }
        }

        GUILayout.Label(string.Format("{0} (Type = {1}, Id = {2}, Controls = {3})", m_Device.displayName, m_Device.GetType().Name, m_Device.deviceId, m_Controls.Count), Styles.BoldLabel);
        switch (m_UIType)
        {
        case UIType.Generic:
            m_ControlScrollView = GUILayout.BeginScrollView(m_ControlScrollView);
            foreach (var c in m_Controls)
            {
                GUILayout.Button(string.Format("{0} (Type = {1}, Value = {2}, Info = ({3}) )", c.name, c.GetType().Name, c.ReadValueAsObject(), GetAdditionalInfo(c)), Styles.BoldButton);
            }
            GUILayout.EndScrollView();
            break;

        case UIType.Specialized:
            DoSpecializedGUI();
            break;

        case UIType.Events:
            DoEventsGUI();
            break;
        }
    }
 public void CallDisableDevice()
 {
     InputSystem.DisableDevice(Accelerometer.current);
 }
            protected override void ContextClickedItem(int id)
            {
                var item = FindItem(id, rootItem);

                if (item == null)
                {
                    return;
                }

                if (item is DeviceItem deviceItem)
                {
                    var menu = new GenericMenu();
                    menu.AddItem(Contents.openDebugView, false, () => InputDeviceDebuggerWindow.CreateOrShowExisting(deviceItem.device));
                    menu.AddItem(Contents.copyDeviceDescription, false,
                                 () => EditorGUIUtility.systemCopyBuffer = deviceItem.device.description.ToJson());
                    menu.AddItem(Contents.removeDevice, false, () => InputSystem.RemoveDevice(deviceItem.device));
                    if (deviceItem.device.enabled)
                    {
                        menu.AddItem(Contents.disableDevice, false, () => InputSystem.DisableDevice(deviceItem.device));
                    }
                    else
                    {
                        menu.AddItem(Contents.enableDevice, false, () => InputSystem.EnableDevice(deviceItem.device));
                    }
                    menu.ShowAsContext();
                }

                if (item is UnsupportedDeviceItem unsupportedDeviceItem)
                {
                    var menu = new GenericMenu();
                    menu.AddItem(Contents.copyDeviceDescription, false,
                                 () => EditorGUIUtility.systemCopyBuffer = unsupportedDeviceItem.description.ToJson());
                    menu.ShowAsContext();
                }

                if (item is LayoutItem layoutItem)
                {
                    var layout = EditorInputControlLayoutCache.TryGetLayout(layoutItem.layoutName);
                    if (layout != null)
                    {
                        var menu = new GenericMenu();
                        menu.AddItem(Contents.copyLayoutAsJSON, false,
                                     () => EditorGUIUtility.systemCopyBuffer = layout.ToJson());
                        if (layout.isDeviceLayout)
                        {
                            menu.AddItem(Contents.createDeviceFromLayout, false,
                                         () => InputSystem.AddDevice(layout.name));
                            menu.AddItem(Contents.generateCodeFromLayout, false, () =>
                            {
                                var fileName   = EditorUtility.SaveFilePanel("Generate InputDevice Code", "", "Fast" + layoutItem.layoutName, "cs");
                                var isInAssets = fileName.StartsWith(Application.dataPath, StringComparison.OrdinalIgnoreCase);
                                if (isInAssets)
                                {
                                    fileName = "Assets/" + fileName.Substring(Application.dataPath.Length + 1);
                                }
                                if (!string.IsNullOrEmpty(fileName))
                                {
                                    var code = InputLayoutCodeGenerator.GenerateCodeFileForDeviceLayout(layoutItem.layoutName, fileName, prefix: "Fast");
                                    File.WriteAllText(fileName, code);
                                    if (isInAssets)
                                    {
                                        AssetDatabase.Refresh();
                                    }
                                }
                            });
                        }
                        menu.ShowAsContext();
                    }
                }
            }
Esempio n. 18
0
    private void Init()
    {
        if (_initialized)
        {
            return;
        }

        // Init the replay system
        switch (_traceMode)
        {
        // Do nothing
        case TraceManagerMode.NONE:
            _recordingIndicator.SetActive(false);
            _replayingIndicator.SetActive(false);
            break;

        // Saves input to file
        case TraceManagerMode.RECORD:

            // Filename based on date
            string dateFMT = System.DateTime.Now.ToString("u");                                                         //preferred format for file ordering
            _savedInputFilename = "IT_" + dateFMT.Replace(" ", "_").Replace("-", "").Replace(":", "").Replace("Z", ""); //improved filename
            Debug.Log("Replay: Input will be saved to file '" + _savedInputFilename + "'");
            _initialSeed = Random.seed;
            _trace       = new InputEventTrace();
            _trace.Enable();
            _recordingIndicator.SetActive(true);
            _initialized = true;
            break;

        // Replays input from saved file
        case TraceManagerMode.REPRODUCE:
            /// todo: aqui hay que asignar el savedinputfilename
            Debug.Log("Replay: Loading Input Trace from file '" + _savedInputFilename + "'");

            if (File.Exists(_savePath + _savedInputFilename))
            {
                _trace = InputEventTrace.LoadFrom(_savePath + _savedInputFilename);
            }
            else
            {
                Debug.LogError("Replay ERROR: File '" + _savedInputFilename + "' doesn't exist. Trace reproduction Cancelled.");
                return;
            }

            if (File.Exists(_seedPath + _savedInputFilename + "Seed"))
            {
                string randomSeed = File.ReadAllText(_seedPath + _savedInputFilename + "Seed");
                int    seedValue  = 0;
                if (int.TryParse(randomSeed, System.Globalization.NumberStyles.AllowLeadingSign, System.Globalization.NumberFormatInfo.InvariantInfo, out seedValue))
                {
                    Random.seed = seedValue;
                }
                else
                {
                    Debug.LogWarning("Replay Warning: Seed file with incorrect format. Trace reproduction may not work as intented.");
                }
            }
            else
            {
                Debug.LogWarning("Replay Warning: Missing seed file. Trace reproduction may not work as intented.");
            }



            foreach (InputDevice device in InputSystem.devices)
            {
                InputSystem.DisableDevice(device);
            }

            _replayController = _trace.Replay();
            _replayController.WithAllDevicesMappedToNewInstances();
            _replayController.PlayAllEventsAccordingToTimestamps();
            _replayingIndicator.SetActive(true);
            _initialized = true;
            break;
        }
    }
Esempio n. 19
0
 void OnDestroy()
 {
     // Reset InputControl of Gyroscope surely.
     InputSystem.ResetDevice(Gyroscope.current, true);
     InputSystem.DisableDevice(Gyroscope.current);
 }
Esempio n. 20
0
 private void OnDisable()
 {
     //android.PlayerAndroid.Disable();
     InputSystem.DisableDevice(UnityEngine.InputSystem.Gyroscope.current);
 }
Esempio n. 21
0
 void OnDestroy()
 {
     InputSystem.DisableDevice(Gyroscope.current);
 }