コード例 #1
0
 private void StartRecord()
 {
     initial.transform.position = player.transform.position;
     initial.transform.rotation = player.transform.rotation;
     record = new InputEventTrace();
     record.Enable();
     state = recordState.recording;
 }
コード例 #2
0
 private void StartEventTracing()
 {
     if (m_EventTrace != null)
     {
         m_EventTrace.Dispose();
     }
     m_EventCount = 0;
     m_EventQueue.Clear();
     m_EventTrace = new InputEventTrace()
     {
         deviceId = m_Device.deviceId
     };
     m_EventTrace.onEvent += M_EventTrace_onEvent;;
     m_EventTrace.Enable();
 }
コード例 #3
0
    public unsafe void Events_CanTraceEventsOfDevice()
    {
        InputSystem.settings.timesliceEvents = false;

        var device = InputSystem.AddDevice <Gamepad>();
        var noise  = InputSystem.AddDevice <Gamepad>();

        using (var trace = new InputEventTrace {
            deviceId = device.id
        })
        {
            trace.Enable();
            Assert.That(trace.enabled, Is.True);

            var firstState = new GamepadState {
                rightTrigger = 0.35f
            };
            var secondState = new GamepadState {
                leftTrigger = 0.75f
            };

            InputSystem.QueueStateEvent(device, firstState, 0.5);
            InputSystem.QueueStateEvent(device, secondState, 1.5);
            InputSystem.QueueStateEvent(noise, new GamepadState()); // This one just to make sure we don't get it.

            InputSystem.Update();

            trace.Disable();

            var events = trace.ToList();

            Assert.That(events, Has.Count.EqualTo(2));

            Assert.That(events[0].type, Is.EqualTo((FourCC)StateEvent.Type));
            Assert.That(events[0].deviceId, Is.EqualTo(device.id));
            Assert.That(events[0].time, Is.EqualTo(0.5).Within(0.000001));
            Assert.That(events[0].sizeInBytes, Is.EqualTo(StateEvent.GetEventSizeWithPayload <GamepadState>()));
            Assert.That(UnsafeUtility.MemCmp(UnsafeUtility.AddressOf(ref firstState),
                                             StateEvent.From(events[0])->state, UnsafeUtility.SizeOf <GamepadState>()), Is.Zero);

            Assert.That(events[1].type, Is.EqualTo((FourCC)StateEvent.Type));
            Assert.That(events[1].deviceId, Is.EqualTo(device.id));
            Assert.That(events[1].time, Is.EqualTo(1.5).Within(0.000001));
            Assert.That(events[1].sizeInBytes, Is.EqualTo(StateEvent.GetEventSizeWithPayload <GamepadState>()));
            Assert.That(UnsafeUtility.MemCmp(UnsafeUtility.AddressOf(ref secondState),
                                             StateEvent.From(events[1])->state, UnsafeUtility.SizeOf <GamepadState>()), Is.Zero);
        }
    }
コード例 #4
0
    public void Events_CanClearEventTrace()
    {
        using (var trace = new InputEventTrace())
        {
            trace.Enable();

            var device = InputSystem.AddDevice <Gamepad>();
            InputSystem.QueueStateEvent(device, new GamepadState());
            InputSystem.QueueStateEvent(device, new GamepadState());
            InputSystem.Update();

            Assert.That(trace.ToList(), Has.Count.EqualTo(2));

            trace.Clear();

            Assert.That(trace.ToList(), Has.Count.EqualTo(0));
        }
    }
コード例 #5
0
        private void InitializeWith(InputDevice device)
        {
            m_Device             = device;
            m_DeviceId           = device.id;
            m_DeviceIdString     = device.id.ToString();
            m_DeviceUsagesString = string.Join(", ", device.usages.Select(x => x.ToString()).ToArray());

            // Set up event trace. The default trace size of 1mb fits a ton of events and will
            // likely bog down the UI if we try to display that many events. Instead, come up
            // with a more reasonable sized based on the state size of the device.
            if (m_EventTrace == null)
            {
                m_EventTrace = new InputEventTrace((int)device.stateBlock.alignedSizeInBytes * 64)
                {
                    deviceId = device.id
                }
            }
            ;
            m_EventTrace.onEvent += _ =>
            {
                ////FIXME: this is very inefficient
                m_EventTree.Reload();
                Repaint();
            };
            if (!m_EventTraceDisabled)
            {
                m_EventTrace.Enable();
            }

            // Set up event tree.
            m_EventTree = InputEventTreeView.Create(m_Device, m_EventTrace, ref m_EventTreeState, ref m_EventTreeHeaderState);

            // Set up control tree.
            m_ControlTree = InputControlTreeView.Create(m_Device, ref m_ControlTreeState, ref m_ControlTreeHeaderState);
            m_ControlTree.ExpandAll();

            // Look for GUI extension methods in plugins.
            m_OnToolbarGUIMethods = InputManager.ScanForPluginMethods("OnToolbarGUI");
        }
コード例 #6
0
    public void Events_WhenTraceIsFull_WillStartOverwritingOldEvents()
    {
        InputSystem.settings.timesliceEvents = false;

        var device = InputSystem.AddDevice <Gamepad>();

        using (var trace =
                   new InputEventTrace(StateEvent.GetEventSizeWithPayload <GamepadState>() * 2)
        {
            deviceId = device.id
        })
        {
            trace.Enable();

            var firstState = new GamepadState {
                rightTrigger = 0.35f
            };
            var secondState = new GamepadState {
                leftTrigger = 0.75f
            };
            var thirdState = new GamepadState {
                leftTrigger = 0.95f
            };

            InputSystem.QueueStateEvent(device, firstState, 0.5);
            InputSystem.QueueStateEvent(device, secondState, 1.5);
            InputSystem.QueueStateEvent(device, thirdState, 2.5);

            InputSystem.Update();

            trace.Disable();

            var events = trace.ToList();

            Assert.That(events, Has.Count.EqualTo(2));
            Assert.That(events, Has.Exactly(1).With.Property("time").EqualTo(1.5).Within(0.000001));
            Assert.That(events, Has.Exactly(1).With.Property("time").EqualTo(2.5).Within(0.000001));
        }
    }
コード例 #7
0
    public unsafe void Events_CanGetStatePointerFromEventThroughControl_EvenIfDeviceIsStateCallbackReceiver()
    {
        var touchscreen = InputSystem.AddDevice <Touchscreen>();

        using (var trace = new InputEventTrace {
            deviceId = touchscreen.deviceId
        })
        {
            trace.Enable();

            BeginTouch(1, new Vector2(123, 234));

            var statePtr = touchscreen.primaryTouch.position.GetStatePtrFromStateEvent(trace.ToArray()[0]);
            Assert.That(statePtr != null);

            // Attempt reading the position value from the touch event.
            Assert.That(touchscreen.primaryTouch.position.ReadValueFromState(statePtr),
                        Is.EqualTo(new Vector2(123, 234)).Using(Vector2EqualityComparer.Instance));

            // It only works with primaryTouch. See Touchscreen.GetStateOffsetForEvent for details.
            Assert.That(touchscreen.touches[1].position.GetStatePtrFromStateEvent(trace.ToArray()[0]) == null);
        }
    }
コード例 #8
0
        ////FIXME: some of the state in here doesn't get refreshed when it's changed on the device
        private void InitializeWith(InputDevice device)
        {
            m_Device             = device;
            m_DeviceId           = device.id;
            m_DeviceIdString     = device.id.ToString();
            m_DeviceUsagesString = string.Join(", ", device.usages.Select(x => x.ToString()).ToArray());

            var flags = new List <string>();

            if ((m_Device.m_DeviceFlags & InputDevice.DeviceFlags.Native) == InputDevice.DeviceFlags.Native)
            {
                flags.Add("Native");
            }
            if ((m_Device.m_DeviceFlags & InputDevice.DeviceFlags.Remote) == InputDevice.DeviceFlags.Remote)
            {
                flags.Add("Remote");
            }
            if ((m_Device.m_DeviceFlags & InputDevice.DeviceFlags.UpdateBeforeRender) == InputDevice.DeviceFlags.UpdateBeforeRender)
            {
                flags.Add("UpdateBeforeRender");
            }
            if ((m_Device.m_DeviceFlags & InputDevice.DeviceFlags.HasStateCallbacks) == InputDevice.DeviceFlags.HasStateCallbacks)
            {
                flags.Add("HasStateCallbacks");
            }
            if ((m_Device.m_DeviceFlags & InputDevice.DeviceFlags.Disabled) == InputDevice.DeviceFlags.Disabled)
            {
                flags.Add("Disabled");
            }
            m_DeviceFlagsString = string.Join(", ", flags.ToArray());

            // Set up event trace. The default trace size of 1mb fits a ton of events and will
            // likely bog down the UI if we try to display that many events. Instead, come up
            // with a more reasonable sized based on the state size of the device.
            if (m_EventTrace == null)
            {
                m_EventTrace = new InputEventTrace((int)device.stateBlock.alignedSizeInBytes * kMaxNumEventsInTrace)
                {
                    deviceId = device.id
                }
            }
            ;
            m_EventTrace.onEvent += _ =>
            {
                ////FIXME: this is very inefficient
                m_EventTree.Reload();
            };
            if (!m_EventTraceDisabled)
            {
                m_EventTrace.Enable();
            }

            // Set up event tree.
            m_EventTree = InputEventTreeView.Create(m_Device, m_EventTrace, ref m_EventTreeState, ref m_EventTreeHeaderState);

            // Set up control tree.
            m_ControlTree = InputControlTreeView.Create(m_Device, 1, ref m_ControlTreeState, ref m_ControlTreeHeaderState);
            m_ControlTree.Reload();
            m_ControlTree.ExpandAll();

            AddToList();
            InputSystem.onDeviceChange += OnDeviceChange;
        }
コード例 #9
0
 void EnableTrace()
 {
     Trace = new InputEventTrace();
     Trace.Enable();
 }
コード例 #10
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;
        }
    }