浏览代码

InputActuatorComponent to allow the generation of an action space from an InputActionAsset (#4881) (#4974)

/release_13_branch
GitHub 4 年前
当前提交
7f70330b
共有 76 个文件被更改,包括 2586 次插入43 次删除
  1. 2
      .yamato/com.unity.ml-agents-test.yml
  2. 16
      DevProject/Packages/manifest.json
  3. 42
      DevProject/ProjectSettings/ProjectSettings.asset
  4. 4
      DevProject/ProjectSettings/ProjectVersion.txt
  5. 10
      com.unity.ml-agents.extensions/Documentation~/com.unity.ml-agents.extensions.md
  6. 3
      com.unity.ml-agents.extensions/Runtime/Unity.ML-Agents.Extensions.asmdef
  7. 4
      com.unity.ml-agents/CHANGELOG.md
  8. 45
      com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs
  9. 12
      com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs
  10. 10
      com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs
  11. 8
      com.unity.ml-agents/Runtime/Agent.deprecated.cs
  12. 1
      com.unity.ml-agents/Runtime/AssemblyInfo.cs
  13. 28
      com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
  14. 46
      com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs
  15. 2
      DevProject/DevProject.sln.DotSettings
  16. 519
      DevProject/Packages/packages-lock.json
  17. 57
      com.unity.ml-agents.extensions/Documentation~/InputActuatorComponent.md
  18. 3
      com.unity.ml-agents.extensions/Editor/Input.meta
  19. 3
      com.unity.ml-agents.extensions/Runtime/Input.meta
  20. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input.meta
  21. 40
      com.unity.ml-agents/Tests/Editor/Actuators/ActionSpecTests.cs
  22. 3
      com.unity.ml-agents/Tests/Editor/Actuators/ActionSpecTests.cs.meta
  23. 7
      DevProject/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json
  24. 26
      com.unity.ml-agents.extensions/Editor/Input/InputActuatorComponentEditor.cs
  25. 3
      com.unity.ml-agents.extensions/Editor/Input/InputActuatorComponentEditor.cs.meta
  26. 26
      com.unity.ml-agents.extensions/Editor/Input/Unity.ML-Agents.Extensions.Editor.Input.asmdef
  27. 7
      com.unity.ml-agents.extensions/Editor/Input/Unity.ML-Agents.Extensions.Editor.Input.asmdef.meta
  28. 3
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors.meta
  29. 45
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/ButtonInputActionAdaptor.cs
  30. 3
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/ButtonInputActionAdaptor.cs.meta
  31. 35
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/DoubleInputActionAdaptor.cs
  32. 3
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/DoubleInputActionAdaptor.cs.meta
  33. 35
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/FloatInputActionAdaptor.cs
  34. 3
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/FloatInputActionAdaptor.cs.meta
  35. 36
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/IntegerInputActionAdaptor.cs
  36. 3
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/IntegerInputActionAdaptor.cs.meta
  37. 44
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/Vector2InputActionAdaptor.cs
  38. 3
      com.unity.ml-agents.extensions/Runtime/Input/Adaptors/Vector2InputActionAdaptor.cs.meta
  39. 3
      com.unity.ml-agents.extensions/Runtime/Input/AssemblyInfo.cs
  40. 3
      com.unity.ml-agents.extensions/Runtime/Input/AssemblyInfo.cs.meta
  41. 27
      com.unity.ml-agents.extensions/Runtime/Input/IInputActionAssetProvider.cs
  42. 11
      com.unity.ml-agents.extensions/Runtime/Input/IInputActionAssetProvider.cs.meta
  43. 39
      com.unity.ml-agents.extensions/Runtime/Input/IRLActionInputAdaptor.cs
  44. 3
      com.unity.ml-agents.extensions/Runtime/Input/IRLActionInputAdaptor.cs.meta
  45. 89
      com.unity.ml-agents.extensions/Runtime/Input/InputActionActuator.cs
  46. 3
      com.unity.ml-agents.extensions/Runtime/Input/InputActionActuator.cs.meta
  47. 331
      com.unity.ml-agents.extensions/Runtime/Input/InputActuatorComponent.cs
  48. 11
      com.unity.ml-agents.extensions/Runtime/Input/InputActuatorComponent.cs.meta
  49. 23
      com.unity.ml-agents.extensions/Runtime/Input/Unity.ML-Agents.Extensions.Input.asmdef
  50. 7
      com.unity.ml-agents.extensions/Runtime/Input/Unity.ML-Agents.Extensions.Input.asmdef.meta
  51. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors.meta
  52. 72
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/ButtonInputActionAdaptorTests.cs
  53. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/ButtonInputActionAdaptorTests.cs.meta
  54. 70
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/DoubleInputActionAdaptorTests.cs
  55. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/DoubleInputActionAdaptorTests.cs.meta
  56. 71
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/FloatInputActionAdapatorTests.cs
  57. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/FloatInputActionAdapatorTests.cs.meta
  58. 73
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/IntegerInputActionAdaptorTests.cs
  59. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/IntegerInputActionAdaptorTests.cs.meta
  60. 73
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/Vector2InputActionAdaptorTests.cs
  61. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Adaptors/Vector2InputActionAdaptorTests.cs.meta
  62. 82
      com.unity.ml-agents.extensions/Tests/Runtime/Input/InputActionActuatorTests.cs
  63. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input/InputActionActuatorTests.cs.meta
  64. 112
      com.unity.ml-agents.extensions/Tests/Runtime/Input/InputActuatorComponentTests.cs
  65. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input/InputActuatorComponentTests.cs.meta
  66. 318
      com.unity.ml-agents.extensions/Tests/Runtime/Input/TestPushBlockActions.cs
  67. 3
      com.unity.ml-agents.extensions/Tests/Runtime/Input/TestPushBlockActions.cs.meta
  68. 31
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Unity.ML-Agents.Extensions.Input.Tests.Runtime.asmdef
  69. 7
      com.unity.ml-agents.extensions/Tests/Runtime/Input/Unity.ML-Agents.Extensions.Input.Tests.Runtime.asmdef.meta

2
.yamato/com.unity.ml-agents-test.yml


assembly: Unity.ML-Agents
minCoveragePct: 72
- name: com.unity.ml-agents.extensions
assembly: Unity.ML-Agents.Extensions
assembly: Unity.ML-Agents.Extensions*
minCoveragePct: 75
---

16
DevProject/Packages/manifest.json


"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.ads": "3.4.9",
"com.unity.ads": "3.6.1",
"com.unity.ide.vscode": "1.2.1",
"com.unity.ide.vscode": "1.2.3",
"com.unity.inputsystem": "1.1.0-preview.3",
"com.unity.multiplayer-hlapi": "1.0.6",
"com.unity.multiplayer-hlapi": "1.0.8",
"com.unity.purchasing": "2.1.0",
"com.unity.test-framework": "1.1.16",
"com.unity.purchasing": "2.2.1",
"com.unity.test-framework": "1.1.20",
"com.unity.xr.legacyinputhelpers": "2.1.4",
"com.unity.xr.legacyinputhelpers": "2.1.7",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",

"registry": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates",
"testables": [
"com.unity.ml-agents",
"com.unity.ml-agents.extensions"
"com.unity.ml-agents.extensions",
"com.unity.inputsystem"
]
}

42
DevProject/ProjectSettings/ProjectSettings.asset


androidBlitType: 0
defaultIsNativeResolution: 1
macRetinaSupport: 1
runInBackground: 0
runInBackground: 1
captureSingleScreen: 0
muteOtherAudioSources: 0
Prepare IOS For Recording: 0

xboxOneMonoLoggingLevel: 0
xboxOneLoggingLevel: 1
xboxOneDisableEsram: 0
xboxOneEnableTypeOptimization: 0
xboxOnePresentImmediateThreshold: 0
switchQueueCommandMemory: 1048576
switchQueueControlMemory: 16384

switchNVNOtherPoolsGranularity: 16777216
switchNVNMaxPublicTextureIDCount: 0
switchNVNMaxPublicSamplerIDCount: 0
stadiaPresentMode: 0
stadiaTargetFramerate: 0
vulkanEnableLateAcquireNextImage: 0
m_SupportedAspectRatios:
4:3: 1
5:4: 1

useHDRDisplay: 0
D3DHDRBitDepth: 0
m_ColorGamuts: 00000000
targetPixelDensity: 0
targetPixelDensity: 30
resolutionScalingMode: 0
androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1

StripUnusedMeshComponents: 0
VertexChannelCompressionMask: 4054
iPhoneSdkVersion: 988
iOSTargetOSVersionString:
iOSTargetOSVersionString: 10.0
tvOSTargetOSVersionString:
tvOSTargetOSVersionString: 10.0
uIPrerenderedIcon: 0
uIRequiresPersistentWiFi: 0
uIRequiresFullScreen: 1

iPhoneSplashScreen: {fileID: 0}
iPhoneHighResSplashScreen: {fileID: 0}
iPhoneTallHighResSplashScreen: {fileID: 0}
iPhone47inSplashScreen: {fileID: 0}
iPhone55inPortraitSplashScreen: {fileID: 0}
iPhone55inLandscapeSplashScreen: {fileID: 0}
iPhone58inPortraitSplashScreen: {fileID: 0}
iPhone58inLandscapeSplashScreen: {fileID: 0}
iPadPortraitSplashScreen: {fileID: 0}
iPadHighResPortraitSplashScreen: {fileID: 0}
iPadLandscapeSplashScreen: {fileID: 0}
iPadHighResLandscapeSplashScreen: {fileID: 0}
iPhone65inPortraitSplashScreen: {fileID: 0}
iPhone65inLandscapeSplashScreen: {fileID: 0}
iPhone61inPortraitSplashScreen: {fileID: 0}
iPhone61inLandscapeSplashScreen: {fileID: 0}
appleTVSplashScreen: {fileID: 0}
appleTVSplashScreen2x: {fileID: 0}
tvOSSmallIconLayers: []

metalEditorSupport: 1
metalAPIValidation: 1
iOSRenderExtraFrameOnPause: 0
iosCopyPluginsCodeInsteadOfSymlink: 0
appleDeveloperTeamID:
iOSManualSigningProvisioningProfileID:
tvOSManualSigningProvisioningProfileID:

ps4ShareFilePath:
ps4ShareOverlayImagePath:
ps4PrivacyGuardImagePath:
ps4ExtraSceSysFile:
ps4NPtitleDatPath:
ps4RemotePlayKeyAssignment: -1
ps4RemotePlayKeyMappingDir:

ps4UseResolutionFallback: 0
ps4ReprojectionSupport: 0
ps4UseAudio3dBackend: 0
ps4UseLowGarlicFragmentationMode: 1
ps4SocialScreenEnabled: 0
ps4ScriptOptimizationLevel: 2
ps4Audio3dVirtualSpeakerCount: 14

ps4disableAutoHideSplash: 0
ps4videoRecordingFeaturesUsed: 0
ps4contentSearchFeaturesUsed: 0
ps4CompatibilityPS5: 0
ps4GPU800MHz: 1
ps4attribEyeToEyeDistanceSettingVR: 0
ps4IncludedModules: []
ps4attribVROutputEnabled: 0

additionalIl2CppArgs:
scriptingRuntimeVersion: 1
gcIncremental: 0
assemblyVersionValidation: 1
gcWBarrierValidation: 0
apiCompatibilityLevelPerPlatform: {}
m_RenderingPath: 1

XboxOneCapability: []
XboxOneGameRating: {}
XboxOneIsContentPackage: 0
XboxOneEnhancedXboxCompatibilityMode: 0
XboxOneEnableGPUVariability: 1
XboxOneSockets: {}
XboxOneSplashScreen: {fileID: 0}

XboxOneOverrideIdentityName:
XboxOneOverrideIdentityPublisher:
vrEditorSettings:
daydream:
daydreamIconForeground: {fileID: 0}

projectName:
organizationId:
cloudEnabled: 0
enableNativePlatformBackendsForNewInputSystem: 0
disableOldInputManagerSupport: 0
enableNativePlatformBackendsForNewInputSystem: 1
disableOldInputManagerSupport: 1
legacyClampBlendShapeWeights: 0

4
DevProject/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2019.4.7f1
m_EditorVersionWithRevision: 2019.4.7f1 (e992b1a16e65)
m_EditorVersion: 2019.4.19f1
m_EditorVersionWithRevision: 2019.4.19f1 (ca5b14067cec)

10
com.unity.ml-agents.extensions/Documentation~/com.unity.ml-agents.extensions.md


* [Match-3 sensor and actuator](Match3.md)
* [Grid-based sensor](Grid-Sensor.md)
* Physics-based sensors
* [Input System Package Integration](InputActuatorComponent.md)
## Installation
The ML-Agents Extensions package is not currently available in the Package Manager. There are two

This version of the Unity ML-Agents Extensions package is compatible with the
following versions of the Unity Editor:
- 2018.4 and later
- If using the `InputActuatorComponent`
- 2019.4 or later
- install the `com.unity.inputsystem` package version `1.1.0-preview.3` or later.
- Else 2018.4 and later
none
- For the `InputActuatorComponent`
- Limited implementation of `InputControls`
- No way to customize the action space of the `InputActuatorComponent`
## Need Help?
The main [README](https://github.com/Unity-Technologies/ml-agents/tree/release_13_docs/README.md) contains links for contacting the team or getting support.

3
com.unity.ml-agents.extensions/Runtime/Unity.ML-Agents.Extensions.asmdef


"name": "Unity.ML-Agents.Extensions",
"references": [
"Unity.Barracuda",
"Unity.ML-Agents"
"Unity.ML-Agents",
"Unity.ML-Agents.Extensions.Input"
],
"includePlatforms": [],
"excludePlatforms": []

4
com.unity.ml-agents/CHANGELOG.md


- `InferenceDevice.Burst` was added, indicating that Agent's model will be run using Barracuda's Burst backend.
This is the default for new Agents, but existing ones that use `InferenceDevice.CPU` should update to
`InferenceDevice.Burst`. (#4925)
- Add an InputActuatorComponent to allow the generation of Agent action spaces from an InputActionAsset.
Projects wanting to use this feature will need to add the
[Input System Package](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/manual/index.html)
at version 1.1.0-preview.3 or later. (#4881)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- Tensorboard now logs the Environment Reward as both a scalar and a histogram. (#4878)

45
com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs


using System;
using System.Collections.Generic;
using Unity.MLAgents.Policies;
using UnityEngine;
namespace Unity.MLAgents.Actuators

public ActionSpec(int numContinuousActions = 0, int[] discreteBranchSizes = null)
{
m_NumContinuousActions = numContinuousActions;
BranchSizes = discreteBranchSizes;
BranchSizes = discreteBranchSizes ?? Array.Empty<int>();
}
/// <summary>

"ActionSpecs must be all continuous or all discrete."
);
}
}
/// <summary>
/// Combines a list of actions specs and allocates a new array of branch sizes if needed.
/// </summary>
/// <param name="specs">The list of action specs to combine.</param>
/// <returns>An ActionSpec which represents the aggregate of the ActionSpecs passed in.</returns>
public static ActionSpec Combine(params ActionSpec[] specs)
{
var numContinuous = 0;
var numDiscrete = 0;
for (var i = 0; i < specs.Length; i++)
{
var spec = specs[i];
numContinuous += spec.NumContinuousActions;
numDiscrete += spec.NumDiscreteActions;
}
if (numDiscrete <= 0)
{
return MakeContinuous(numContinuous);
}
var branchSizes = new int[numDiscrete];
var offset = 0;
for (var i = 0; i < specs.Length; i++)
{
var spec = specs[i];
if (spec.BranchSizes.Length == 0)
{
continue;
}
var branchSizesLength = spec.BranchSizes.Length;
Array.Copy(spec.BranchSizes,
0,
branchSizes,
offset,
branchSizesLength);
offset += branchSizesLength;
}
return new ActionSpec(numContinuous, branchSizes);
}
}
}

12
com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
namespace Unity.MLAgents.Actuators
{

/// actions for the IActuators in this list.</param>
public void UpdateActions(ActionBuffers actions)
{
Profiler.BeginSample("ActuatorManager.UpdateActions");
Profiler.EndSample();
}
static void UpdateActionArray<T>(ActionSegment<T> sourceActionBuffer, ActionSegment<T> destination)

/// </summary>
public void ApplyHeuristic(in ActionBuffers actionBuffersOut)
{
Profiler.BeginSample("ActuatorManager.ApplyHeuristic");
var continuousStart = 0;
var discreteStart = 0;
for (var i = 0; i < m_Actuators.Count; i++)

continuousStart += numContinuousActions;
discreteStart += numDiscreteActions;
}
Profiler.EndSample();
}
/// <summary>

/// </summary>
public void ExecuteActions()
{
Profiler.BeginSample("ActuatorManager.ExecuteActions");
ReadyActuatorsForExecution();
var continuousStart = 0;
var discreteStart = 0;

var numContinuousActions = actuator.ActionSpec.NumContinuousActions;
var numDiscreteActions = actuator.ActionSpec.NumDiscreteActions;
if (numContinuousActions == 0 && numDiscreteActions == 0)
{
continue;
}
var continuousActions = ActionSegment<float>.Empty;
if (numContinuousActions > 0)
{

continuousStart += numContinuousActions;
discreteStart += numDiscreteActions;
}
Profiler.EndSample();
}
/// <summary>

10
com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs


using UnityEngine.Profiling;
namespace Unity.MLAgents.Actuators
{
/// <summary>

/// <inheritdoc />
public void OnActionReceived(ActionBuffers actionBuffers)
{
ActionBuffers = actionBuffers;
m_ActionReceiver.OnActionReceived(ActionBuffers);
Profiler.BeginSample("VectorActuator.OnActionReceived");
m_ActionBuffers = actionBuffers;
m_ActionReceiver.OnActionReceived(m_ActionBuffers);
Profiler.EndSample();
Profiler.BeginSample("VectorActuator.Heuristic");
Profiler.EndSample();
}
/// <inheritdoc />

8
com.unity.ml-agents/Runtime/Agent.deprecated.cs


using System;
using UnityEngine;
using UnityEngine.Profiling;
namespace Unity.MLAgents
{

[Obsolete("GetAction has been deprecated, please use GetStoredActionBuffers instead.")]
public float[] GetAction()
{
Profiler.BeginSample("Agent.GetAction.Deprecated");
var actionSpec = m_PolicyFactory.BrainParameters.ActionSpec;
// For continuous and discrete actions together, this shouldn't be called because we can only return one.
if (actionSpec.NumContinuousActions > 0 && actionSpec.NumDiscreteActions > 0)

{
return storedAction.ContinuousActions.Array;
}
else
{
return Array.ConvertAll(storedAction.DiscreteActions.Array, x => (float)x);
}
Profiler.EndSample();
return Array.ConvertAll(storedAction.DiscreteActions.Array, x => (float)x);
}
}
}

1
com.unity.ml-agents/Runtime/AssemblyInfo.cs


[assembly: InternalsVisibleTo("Unity.ML-Agents.Editor.Tests")]
[assembly: InternalsVisibleTo("Unity.ML-Agents.Editor")]
[assembly: InternalsVisibleTo("Unity.ML-Agents.Extensions")]
[assembly: InternalsVisibleTo("Unity.ML-Agents.Extensions.Input")]

28
com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs


[HideInInspector, SerializeField]
BrainParameters m_BrainParameters = new BrainParameters();
public delegate void PolicyUpdated(bool isInHeuristicMode);
internal event PolicyUpdated OnPolicyUpdated;
/// <summary>
/// The associated <see cref="Policies.BrainParameters"/> for this behavior.
/// </summary>

get { return m_BehaviorName + "?team=" + TeamId; }
}
void Awake()
{
OnPolicyUpdated += mode => { };
}
internal IPolicy GeneratePolicy(ActionSpec actionSpec, ActuatorManager actuatorManager)
{
switch (m_BehaviorType)

}
}
/// <summary>
/// Query the behavior parameters in order to see if the Agent is running in Heuristic Mode.
/// </summary>
/// <returns>true if the Agent is running in Heuristic mode.</returns>
public bool IsInHeuristicMode()
{
if (BehaviorType == BehaviorType.HeuristicOnly)
{
return true;
}
return BehaviorType == BehaviorType.Default &&
ReferenceEquals(Model, null) &&
(!Academy.IsInitialized ||
Academy.IsInitialized &&
!Academy.Instance.IsCommunicatorOn);
}
internal void UpdateAgentPolicy()
{
var agent = GetComponent<Agent>();

}
agent.ReloadPolicy();
OnPolicyUpdated?.Invoke(IsInHeuristicMode());
}
}
}

46
com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs


using NUnit.Framework;
using Unity.Barracuda;
using UnityEditor;
using UnityEngine.TestTools;
namespace Unity.MLAgents.Tests
{

const string k_continuousONNXPath = "Packages/com.unity.ml-agents/Tests/Editor/TestModels/continuous2vis8vec2action.onnx";
public void Heuristic(in ActionBuffers actionsOut)
{
// No-op

{
bp.GeneratePolicy(actionSpec, new ActuatorManager());
});
}
[Test]
public void TestIsInHeuristicMode()
{
var gameObj = new GameObject();
var bp = gameObj.AddComponent<BehaviorParameters>();
bp.Model = null;
gameObj.AddComponent<Agent>();
bp.BehaviorType = BehaviorType.HeuristicOnly;
Assert.IsTrue(bp.IsInHeuristicMode());
bp.BehaviorType = BehaviorType.Default;
Assert.IsTrue(bp.IsInHeuristicMode());
bp.Model = ScriptableObject.CreateInstance<NNModel>();
Assert.IsFalse(bp.IsInHeuristicMode());
}
[Test]
public void TestPolicyUpdateEventFired()
{
var gameObj = new GameObject();
var bp = gameObj.AddComponent<BehaviorParameters>();
gameObj.AddComponent<Agent>().LazyInitialize();
bp.OnPolicyUpdated += delegate (bool isInHeuristicMode) { Debug.Log($"OnPolicyChanged:{isInHeuristicMode}"); };
bp.BehaviorType = BehaviorType.HeuristicOnly;
LogAssert.Expect(LogType.Log, $"OnPolicyChanged:{true}");
bp.BehaviorType = BehaviorType.Default;
LogAssert.Expect(LogType.Log, $"OnPolicyChanged:{true}");
Assert.Throws<UnityAgentsException>(() =>
{
bp.BehaviorType = BehaviorType.InferenceOnly;
});
bp.Model = AssetDatabase.LoadAssetAtPath<NNModel>(k_continuousONNXPath);
LogAssert.Expect(LogType.Log, $"OnPolicyChanged:{false}");
bp.BehaviorType = BehaviorType.HeuristicOnly;
LogAssert.Expect(LogType.Log, $"OnPolicyChanged:{true}");
}
}
}

2
DevProject/DevProject.sln.DotSettings


<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RL/@EntryIndexedValue">RL</s:String></wpf:ResourceDictionary>

519
DevProject/Packages/packages-lock.json


{
"dependencies": {
"com.unity.2d.sprite": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.2d.tilemap": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.ads": {
"version": "3.6.1",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.analytics": {
"version": "3.3.5",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.barracuda": {
"version": "1.3.0-preview",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.3.4",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.burst": {
"version": "1.3.4",
"depth": 2,
"source": "registry",
"dependencies": {
"com.unity.mathematics": "1.2.1"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.coding": {
"version": "0.1.0-preview.13",
"depth": 0,
"source": "registry",
"dependencies": {
"nuget.moq": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.collab-proxy": {
"version": "1.2.16",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.ext.nunit": {
"version": "1.0.6",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.ide.rider": {
"version": "1.1.4",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.test-framework": "1.1.1"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.ide.vscode": {
"version": "1.2.3",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.inputsystem": {
"version": "1.1.0-preview.3",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.mathematics": {
"version": "1.2.1",
"depth": 3,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.ml-agents": {
"version": "file:../../com.unity.ml-agents",
"depth": 0,
"source": "local",
"dependencies": {
"com.unity.barracuda": "1.3.0-preview",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0"
}
},
"com.unity.ml-agents.extensions": {
"version": "file:../../com.unity.ml-agents.extensions",
"depth": 0,
"source": "local",
"dependencies": {
"com.unity.ml-agents": "1.7.2-preview"
}
},
"com.unity.multiplayer-hlapi": {
"version": "1.0.8",
"depth": 0,
"source": "registry",
"dependencies": {
"nuget.mono-cecil": "0.1.6-preview"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.nuget.mono-cecil": {
"version": "0.1.6-preview.2",
"depth": 1,
"source": "registry",
"dependencies": {
"nuget.mono-cecil": "0.1.6-preview"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.nuget.newtonsoft-json": {
"version": "2.0.0-preview",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.package-manager-doctools": {
"version": "1.7.0-preview",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.package-validation-suite": "0.10.0-preview",
"com.unity.nuget.newtonsoft-json": "2.0.0-preview"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.package-validation-suite": {
"version": "0.19.0-preview",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.nuget.mono-cecil": "0.1.6-preview.2"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.purchasing": {
"version": "2.2.1",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.settings-manager": {
"version": "1.0.1",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.test-framework": {
"version": "1.1.20",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ext.nunit": "1.0.6",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.test-framework.performance": {
"version": "2.2.0-preview",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.test-framework": "1.1.0",
"com.unity.nuget.newtonsoft-json": "2.0.0-preview"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.testtools.codecoverage": {
"version": "1.0.0-pre.3",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.test-framework": "1.0.16",
"com.unity.settings-manager": "1.0.1"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.textmeshpro": {
"version": "2.0.1",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.timeline": {
"version": "1.2.12",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.ugui": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.imgui": "1.0.0"
}
},
"com.unity.xr.legacyinputhelpers": {
"version": "2.1.7",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.xr": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"nuget.castle-core": {
"version": "1.0.1",
"depth": 2,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"nuget.mono-cecil": {
"version": "0.1.6-preview",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"nuget.moq": {
"version": "1.0.0",
"depth": 1,
"source": "registry",
"dependencies": {
"nuget.castle-core": "1.0.1"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.modules.ai": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.androidjni": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.animation": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.assetbundle": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.audio": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.cloth": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics": "1.0.0"
}
},
"com.unity.modules.director": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.animation": "1.0.0"
}
},
"com.unity.modules.imageconversion": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.imgui": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.jsonserialize": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.particlesystem": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.physics": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.physics2d": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.screencapture": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.imageconversion": "1.0.0"
}
},
"com.unity.modules.subsystems": {
"version": "1.0.0",
"depth": 1,
"source": "builtin",
"dependencies": {
"com.unity.modules.jsonserialize": "1.0.0"
}
},
"com.unity.modules.terrain": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.terrainphysics": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.terrain": "1.0.0"
}
},
"com.unity.modules.tilemap": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics2d": "1.0.0"
}
},
"com.unity.modules.ui": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.uielements": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
}
},
"com.unity.modules.umbra": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.unityanalytics": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
}
},
"com.unity.modules.unitywebrequest": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.unitywebrequestassetbundle": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0"
}
},
"com.unity.modules.unitywebrequestaudio": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.audio": "1.0.0"
}
},
"com.unity.modules.unitywebrequesttexture": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0"
}
},
"com.unity.modules.unitywebrequestwww": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0"
}
},
"com.unity.modules.vehicles": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics": "1.0.0"
}
},
"com.unity.modules.video": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0"
}
},
"com.unity.modules.vr": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
},
"com.unity.modules.wind": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.xr": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.subsystems": "1.0.0"
}
}
}
}

57
com.unity.ml-agents.extensions/Documentation~/InputActuatorComponent.md


# Integration of the Input System Package with ML-Agents
## Overview
One area we are always trying to improve is getting developers up and running with ML-Agents. With this in mind,
we have implemented an `InputActuatorComponent`. This component integrates with the
[Input System Package](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/manual/QuickStartGuide.html)
to set up an action space for your `Agent` based on an `InputActionAsset` that is referenced by the
`IInputActionAssetProvider` interface, or the `PlayerInput` component that may be living on your player controlled
`Agent`. This means that if you have code outside of your agent that handles input, you will not need to implement
the Heuristic function in agent as well. The `InputActuatorComponent` will handle this for you. You can now train and
run inference on `Agents` with an action space defined by an `InputActionAsset`.
This implementation includes:
* C# `InputActuatorComponent` you can attach to your Agent.
* Implement the `IInputActionAssetProvider` in the `Componenet` where you handle player input.
* An example environment where the input handling code is not in the Heuristic function of the Agent subclass.
### Feedback
We have only implemented a small subset of `InputControl` types that we thought would cover a large portion of what
most developers would use. Please let us know if you want more control types implemented by posting in the [ML-Agents
forum.](https://forum.unity.com/forums/ml-agents.453/)
We would also like your feedback on the workflow of integrating this into your games. If you run
into workflow issues please let us know in the ML-Agents forums, or if you've discovered a bug,
please file a bug on our GitHub page.
## Getting started
The C# code for the `InputActuatorComponent` exists inside of the extensions package (com.unity.ml-agents.extensions). A good first step would be to familiarize with the extensions package by reading the document [here](com.unity.ml-agents.extensions.md). The second step would be to take a look at how we have implemented the C# code in the example Input Integration scene (located under ML-Agents-Input-Example/Assets/ML-Agents/Examples/PushBlock/). Once you have some familiarity, then the next step would be to add the InputActuatorComponent to your player Agent. The example we have implemented uses C# Events to send information from the Input System.
Additionally, see below for additional technical specifications on the C# code for the InputActuatorComponent.
## Technical specifications for the InputActuatorComponent
### `IInputActionsAssetProvider` Interface
The `InputActuatorComponent` searches for a `Component` that implements
`IInputActionAssetProvider` on the `GameObject` they both are attached to. It is important to note
that if multiple `Components` on your `GameObject` need to access an `InputActionAsset` to handle events,
they will need to share the same instance of the `InputActionAsset` that is returned from the
`IInputActionAssetProvider`.
### `InputActuatorComponent` class
The `InputActuatorComponent` is the bridge between ML-Agents and the Input System.. It allows ML-Agents to
* create an `ActionSpec` for your Agent based on an `InputActionAsset` that comes from an
`IInputActionAssetProvider`.
* send simulated input from a training process or a neural network
* let developers keep their input handling code in one place
This is accomplished by adding the `InputActuatorComponenet` to an Agent which already has the PlayerInput component attached.
### Setting up a scene using the `InputActuatorComponent`
1. Add the `com.unity.inputsystem` version 1.1.0-preview.3 or later to your project via the Package Manager window.
2. If you have already setup an InputActionAsset skip to Step 3, otherwise follow these sub steps:
1. Create an InputActionAsset to allow your Agent to be controlled by the Input System.
2. Handle the events from the Input System where you normally would (i.e. a script external to your Agent class).
3. Add the InputSystemActuatorComponent to the GameObject that has the `PlayerInput` and `Agent` components attached.

3
com.unity.ml-agents.extensions/Editor/Input.meta


fileFormatVersion: 2
guid: 1f773a20e85042999e87f5d3c7b55281
timeCreated: 1613637190

3
com.unity.ml-agents.extensions/Runtime/Input.meta


fileFormatVersion: 2
guid: 1694e881b9ec420ba1c201f0612392d6
timeCreated: 1610754907

3
com.unity.ml-agents.extensions/Tests/Runtime/Input.meta


fileFormatVersion: 2
guid: 27f8e1ce37d7485f814ce50a37101203
timeCreated: 1612908869

40
com.unity.ml-agents/Tests/Editor/Actuators/ActionSpecTests.cs


using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Unity.MLAgents.Actuators;
using UnityEngine.TestTools.Constraints;
using Is = UnityEngine.TestTools.Constraints.Is;
namespace Unity.MLAgents.Tests.Actuators
{
[TestFixture]
public class ActionSpecTests
{
[Test]
public void ActionSpecCombineTest()
{
var as0 = new ActionSpec(3, new[] { 3, 2, 1 });
var as1 = new ActionSpec(1, new[] { 35, 122, 1, 3, 8, 3 });
var as0NumCon = 3;
var as0NumDis = as0.NumDiscreteActions;
var as1NumCon = 1;
var as1NumDis = as1.NumDiscreteActions;
var branchSizes = new List<int>();
branchSizes.AddRange(as0.BranchSizes);
branchSizes.AddRange(as1.BranchSizes);
var asc = ActionSpec.Combine(as0, as1);
Assert.AreEqual(as0NumCon + as1NumCon, asc.NumContinuousActions);
Assert.AreEqual(as0NumDis + as1NumDis, asc.NumDiscreteActions);
Assert.IsTrue(branchSizes.ToArray().SequenceEqual(asc.BranchSizes));
as0 = new ActionSpec(3);
as1 = new ActionSpec(1);
asc = ActionSpec.Combine(as0, as1);
Assert.IsEmpty(asc.BranchSizes);
}
}
}

3
com.unity.ml-agents/Tests/Editor/Actuators/ActionSpecTests.cs.meta


fileFormatVersion: 2
guid: 99d76ec04c944b75bc6b85abfff4ac4e
timeCreated: 1613680505

7
DevProject/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json


{
"m_Name": "Settings",
"m_Path": "ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json",
"m_Dictionary": {
"m_DictionaryValues": []
}
}

26
com.unity.ml-agents.extensions/Editor/Input/InputActuatorComponentEditor.cs


#if MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER
using Unity.MLAgents.Extensions.Input;
using UnityEditor;
namespace Unity.MLAgents.Extensions.Editor.Input
{
[CustomEditor(typeof(InputActuatorComponent))]
internal class InputActuatorComponentEditor : UnityEditor.Editor
{
const string k_ActionSpecName = "m_ActionSpec";
public override void OnInspectorGUI()
{
var so = serializedObject;
so.Update();
InputActuatorComponent o = so.targetObject as InputActuatorComponent;
_ = o.ActionSpec;
EditorGUI.indentLevel++;
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(so.FindProperty(k_ActionSpecName));
EditorGUI.EndDisabledGroup();
EditorGUI.indentLevel--;
}
}
}
#endif // MLA_INPUT_SYSTEM && UNITY_2019_OR_NEWER

3
com.unity.ml-agents.extensions/Editor/Input/InputActuatorComponentEditor.cs.meta


fileFormatVersion: 2
guid: 3435eeef4d1645be8c0f770b68f2ba19
timeCreated: 1613637202

26
com.unity.ml-agents.extensions/Editor/Input/Unity.ML-Agents.Extensions.Editor.Input.asmdef


{
"name": "Unity.ML-Agents.Extensions.Editor.Input",
"references": [
"Unity.ML-Agents",
"Unity.ML-Agents.Extensions.Input",
"Unity.ML-Agents.Editor",
"Unity.InputSystem"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.inputsystem",
"expression": "1.1.0-preview",
"define": "MLA_INPUT_SYSTEM"
}
],
"noEngineReferences": false
}

7
com.unity.ml-agents.extensions/Editor/Input/Unity.ML-Agents.Extensions.Editor.Input.asmdef.meta


fileFormatVersion: 2
guid: 4851f2d02f9f1423a8593f60b1a9cd7e
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

3
com.unity.ml-agents.extensions/Runtime/Input/Adaptors.meta


fileFormatVersion: 2
guid: de3fc3f4fd664e3ab579a102f7fabc88
timeCreated: 1612204931

45
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/ButtonInputActionAdaptor.cs


#if MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER
using Unity.MLAgents.Actuators;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
namespace Unity.MLAgents.Extensions.Input
{
/// <summary>
/// Class that translates data between the a <see cref="UnityEngine.InputSystem.Controls.ButtonControl"/> and
/// the ML-Agents <see cref="ActionBuffers"/> object.
/// </summary>
public class ButtonInputActionAdaptor : IRLActionInputAdaptor
{
/// <summary>
/// TODO this method needs to be more nuanced depending the types of controls that can back it. i.e. TriggerControls
/// are continuous buttons, etc.
/// Currently returns an <see cref="ActionSpec"/> with 1 branch of size 2. One value for not pressed, and one
/// for pressed.
/// </summary>
/// <param name="action">The action associated with this adaptor to help determine the action space.</param>
/// <returns></returns>
public ActionSpec GetActionSpecForInputAction(InputAction action)
{
return ActionSpec.MakeDiscrete(2);
}
/// TODO again this might need to be more nuanced for things like continuous buttons.
/// <inheritdoc cref="IRLActionInputAdaptor.QueueInputEventForAction"/>
public void QueueInputEventForAction(InputAction action, InputControl control, ActionSpec actionSpec, in ActionBuffers actionBuffers)
{
var val = actionBuffers.DiscreteActions[0];
InputSystem.QueueDeltaStateEvent(control, (byte)val);
}
/// <inheritdoc cref="IRLActionInputAdaptor.WriteToHeuristic"/>>
public void WriteToHeuristic(InputAction action, in ActionBuffers actionBuffers)
{
var discreteActions = actionBuffers.DiscreteActions;
var val = action.ReadValue<float>();
discreteActions[0] = (int)val;
}
}
}
#endif // MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER

3
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/ButtonInputActionAdaptor.cs.meta


fileFormatVersion: 2
guid: f3a0fe3f0bd446958c729d6f71e8d00b
timeCreated: 1612373241

35
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/DoubleInputActionAdaptor.cs


#if MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER
using Unity.MLAgents.Actuators;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
namespace Unity.MLAgents.Extensions.Input
{
/// <summary>
/// Translates data from a <see cref="UnityEngine.InputSystem.Controls.DoubleControl"/>.
/// </summary>
public class DoubleInputActionAdaptor : IRLActionInputAdaptor
{
/// <inheritdoc cref="IRLActionInputAdaptor.GetActionSpecForInputAction"/>
public ActionSpec GetActionSpecForInputAction(InputAction action)
{
return ActionSpec.MakeContinuous(1);
}
/// <inheritdoc cref="IRLActionInputAdaptor.QueueInputEventForAction"/>
public void QueueInputEventForAction(InputAction action, InputControl control, ActionSpec actionSpec, in ActionBuffers actionBuffers)
{
var val = actionBuffers.ContinuousActions[0];
InputSystem.QueueDeltaStateEvent(control,(double)val);
}
/// <inheritdoc cref="IRLActionInputAdaptor.WriteToHeuristic"/>
public void WriteToHeuristic(InputAction action, in ActionBuffers actionBuffers)
{
var actions = actionBuffers.ContinuousActions;
var val = (float)action.ReadValue<double>();
actions[0] = val;
}
}
}
#endif // MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER

3
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/DoubleInputActionAdaptor.cs.meta


fileFormatVersion: 2
guid: 14ec2823be0a4b3bbee5490ed4840e9c
timeCreated: 1612574422

35
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/FloatInputActionAdaptor.cs


#if MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER
using Unity.MLAgents.Actuators;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
namespace Unity.MLAgents.Extensions.Input
{
/// <summary>
/// Translates data from any control that extends from <see cref="InputControl{Single}"/>.
/// </summary>
public class FloatInputActionAdaptor : IRLActionInputAdaptor
{
/// <inheritdoc cref="IRLActionInputAdaptor.GetActionSpecForInputAction"/>
public ActionSpec GetActionSpecForInputAction(InputAction action)
{
return ActionSpec.MakeContinuous(1);
}
/// <inheritdoc cref="IRLActionInputAdaptor.QueueInputEventForAction"/>
public void QueueInputEventForAction(InputAction action, InputControl control, ActionSpec actionSpec, in ActionBuffers actionBuffers)
{
var val = actionBuffers.ContinuousActions[0];
InputSystem.QueueDeltaStateEvent(control, val);
}
/// <inheritdoc cref="IRLActionInputAdaptor.WriteToHeuristic"/>
public void WriteToHeuristic(InputAction action, in ActionBuffers actionBuffers)
{
var actions = actionBuffers.ContinuousActions;
var val = action.ReadValue<float>();
actions[0] = val;
}
}
}
#endif // MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER

3
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/FloatInputActionAdaptor.cs.meta


fileFormatVersion: 2
guid: 6c98cc3fdaec4664aae128a05cfe6560
timeCreated: 1612573580

36
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/IntegerInputActionAdaptor.cs


#if MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER
using Unity.MLAgents.Actuators;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
namespace Unity.MLAgents.Extensions.Input
{
/// <summary>
/// Translates data from a <see cref="UnityEngine.InputSystem.Controls.IntegerControl"/>.
/// </summary>
public class IntegerInputActionAdaptor : IRLActionInputAdaptor
{
// TODO need to figure out how we can infer the branch size from here.
/// <inheritdoc cref="IRLActionInputAdaptor.GetActionSpecForInputAction"/>
public ActionSpec GetActionSpecForInputAction(InputAction action)
{
return ActionSpec.MakeDiscrete(2);
}
/// <inheritdoc cref="IRLActionInputAdaptor.QueueInputEventForAction"/>
public void QueueInputEventForAction(InputAction action, InputControl control, ActionSpec actionSpec, in ActionBuffers actionBuffers)
{
var val = actionBuffers.DiscreteActions[0];
InputSystem.QueueDeltaStateEvent(control, val);
}
/// <inheritdoc cref="IRLActionInputAdaptor.WriteToHeuristic"/>
public void WriteToHeuristic(InputAction action, in ActionBuffers actionBuffers)
{
var actions = actionBuffers.DiscreteActions;
var val = action.ReadValue<int>();
actions[0] = val;
}
}
}
#endif // MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER

3
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/IntegerInputActionAdaptor.cs.meta


fileFormatVersion: 2
guid: 592012f9a30847a29c618f0cf8addfdf
timeCreated: 1612572952

44
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/Vector2InputActionAdaptor.cs


#if MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER
using System;
using Unity.MLAgents.Actuators;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
namespace Unity.MLAgents.Extensions.Input
{
/// <summary>
/// Translates data from any control that extends from <see cref="InputControl{Vector2}"/>.
/// </summary>
public class Vector2InputActionAdaptor : IRLActionInputAdaptor
{
/// <inheritdoc cref="IRLActionInputAdaptor.GetActionSpecForInputAction"/>
public ActionSpec GetActionSpecForInputAction(InputAction action)
{
// TODO create the action spec based on what controls back the action
return ActionSpec.MakeContinuous(2);
}
/// <inheritdoc cref="IRLActionInputAdaptor.QueueInputEventForAction"/>
public void QueueInputEventForAction(InputAction action,
InputControl control,
ActionSpec actionSpec,
in ActionBuffers actionBuffers)
{
var x = actionBuffers.ContinuousActions[0];
var y = actionBuffers.ContinuousActions[1];
InputSystem.QueueDeltaStateEvent(control, new Vector2(x, y));
}
/// <inheritdoc cref="IRLActionInputAdaptor.WriteToHeuristic"/>
public void WriteToHeuristic(InputAction action, in ActionBuffers actionBuffers)
{
var value = action.ReadValue<Vector2>();
var continuousActions = actionBuffers.ContinuousActions;
continuousActions[0] = value.x;
continuousActions[1] = value.y;
}
}
}
#endif // MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER

3
com.unity.ml-agents.extensions/Runtime/Input/Adaptors/Vector2InputActionAdaptor.cs.meta


fileFormatVersion: 2
guid: aa311fde3dac44f3b7998bb7fee77225
timeCreated: 1611356491

3
com.unity.ml-agents.extensions/Runtime/Input/AssemblyInfo.cs


using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Unity.ML-Agents.Extensions.Input.Tests.Runtime")]

3
com.unity.ml-agents.extensions/Runtime/Input/AssemblyInfo.cs.meta


fileFormatVersion: 2
guid: 989e62db4b694586bf2c832ce13e2d50
timeCreated: 1612916938

27
com.unity.ml-agents.extensions/Runtime/Input/IInputActionAssetProvider.cs


#if MLA_INPUT_SYSTEM && UNITY_2019_4_OR_NEWER
using UnityEngine.InputSystem;
namespace Unity.MLAgents.Extensions.Input
{
/// <summary>
/// Implement this interface if you are listening to C# events from the generated C# class from the
/// <see cref="InputActionAsset"/>. This interface works with the <see cref="InputActuatorComponent"/> in order
/// to allow ML-Agents to simulate input actions based on the instance of the <see cref="InputActionAsset"/>
/// used to listen to events. If you implement this interface the <see cref="InputActuatorComponent"/> will use
/// what is returned from <see cref="GetInputActionAsset"/> as the asset to base it's simulated input for.
/// Otherwise, the <see cref="InputActuatorComponent"/> will look for the <see cref="PlayerInput"/> component
/// and use the asset from there. If you have multiple components handling PlayerInput on the same GameObject
/// they will need to share the same instance of the <see cref="InputActionAsset"/> in order to get the simulated
/// input.
/// </summary>
public interface IInputActionAssetProvider
{
/// <summary>