Christopher Goy
4 年前
当前提交
881b71be
共有 21 个文件被更改,包括 240 次插入 和 50 次删除
-
6DevProject/Packages/packages-lock.json
-
7com.unity.ml-agents.extensions/Runtime/Input/Adaptors/ButtonInputActionAdaptor.cs
-
7com.unity.ml-agents.extensions/Runtime/Input/Adaptors/DoubleInputActionAdaptor.cs
-
6com.unity.ml-agents.extensions/Runtime/Input/Adaptors/FloatInputActionAdaptor.cs
-
6com.unity.ml-agents.extensions/Runtime/Input/Adaptors/IntegerInputActionAdaptor.cs
-
7com.unity.ml-agents.extensions/Runtime/Input/Adaptors/Vector2InputActionAdaptor.cs
-
4com.unity.ml-agents.extensions/Runtime/Input/IRLActionInputAdaptor.cs
-
12com.unity.ml-agents.extensions/Runtime/Input/InputActionActuator.cs
-
63com.unity.ml-agents.extensions/Runtime/Input/InputActuatorComponent.cs
-
4com.unity.ml-agents.extensions/Runtime/Input/Unity.ML-Agents.Extensions.Input.asmdef
-
12com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/ButtonInputActionAdaptorTests.cs
-
12com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/DoubleInputActionAdaptorTests.cs
-
12com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/FloatInputActionAdapatorTests.cs
-
12com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/IntegerInputActionAdaptorTests.cs
-
12com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/Vector2InputActionAdaptorTests.cs
-
17com.unity.ml-agents.extensions/Tests/Runtime/Input/InputActionActuatorTests.cs
-
2com.unity.ml-agents.extensions/Tests/Runtime/Input/InputActuatorComponentTests.cs
-
2com.unity.ml-agents.extensions/Tests/Runtime/Input/Unity.ML-Agents.Extensions.Input.Tests.Runtime.asmdef
-
3com.unity.ml-agents/CHANGELOG.md
-
81com.unity.ml-agents.extensions/Runtime/Input/InputActuatorEventContext.cs
-
3com.unity.ml-agents.extensions/Runtime/Input/InputActuatorEventContext.cs.meta
|
|||
#if MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER
|
|||
using System; |
|||
using Unity.Collections; |
|||
using UnityEngine.InputSystem; |
|||
using UnityEngine.InputSystem.LowLevel; |
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
|
|||
namespace Unity.MLAgents.Extensions.Input |
|||
{ |
|||
/// <summary>
|
|||
/// This interface is passed to InputActionActuators to allow them to write to InputEvents.
|
|||
/// The way this interface should be used is to request the <see cref="InputEventPtr"/> by calling
|
|||
/// <see cref="GetEventForFrame"/> then call <see cref="EventProcessedInFrame"/> before returning from
|
|||
/// </summary>
|
|||
public class InputActuatorEventContext : IDisposable |
|||
{ |
|||
|
|||
/// <summary>
|
|||
/// The number of times to allow the use of an event before queuing it in the InputSystem.
|
|||
/// </summary>
|
|||
public readonly int NumTimesToProcess; |
|||
public readonly InputDevice InputDevice; |
|||
NativeArray<byte> m_EventBuffer; |
|||
InputEventPtr m_Ptr; |
|||
int m_Count; |
|||
|
|||
#if UNITY_EDITOR
|
|||
public static InputActuatorEventContext s_EditorContext = new InputActuatorEventContext(); |
|||
#endif
|
|||
|
|||
public InputActuatorEventContext(int numTimesToProcess = 1, InputDevice device = null) |
|||
{ |
|||
NumTimesToProcess = numTimesToProcess; |
|||
InputDevice = device; |
|||
m_Count = 0; |
|||
m_Ptr = new InputEventPtr(); |
|||
m_EventBuffer = new NativeArray<byte>(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the <see cref="InputEventPtr"/> to write to for the current frame.
|
|||
/// </summary>
|
|||
/// <returns>The <see cref="InputEventPtr"/> to write to for the current frame.</returns>
|
|||
public IDisposable GetEventForFrame(out InputEventPtr eventPtr) |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
if (!EditorApplication.isPlaying) |
|||
{ |
|||
eventPtr = new InputEventPtr(); |
|||
} |
|||
#endif
|
|||
if (m_Count % NumTimesToProcess == 0) |
|||
{ |
|||
m_Count = 0; |
|||
m_EventBuffer = StateEvent.From(InputDevice, out m_Ptr); |
|||
} |
|||
eventPtr = m_Ptr; |
|||
return this; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
if (!EditorApplication.isPlaying) |
|||
{ |
|||
return; |
|||
} |
|||
#endif
|
|||
m_Count++; |
|||
if (m_Count == NumTimesToProcess && m_Ptr.valid) |
|||
{ |
|||
InputSystem.QueueEvent(m_Ptr); |
|||
m_EventBuffer.Dispose(); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
#endif // MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER
|
|
|||
fileFormatVersion: 2 |
|||
guid: 76c31df314114ec6bf104e8db4e5568b |
|||
timeCreated: 1614892215 |
撰写
预览
正在加载...
取消
保存
Reference in new issue