├── .editorconfig ├── .gitignore ├── CHANGELOG.md ├── CHANGELOG.md.meta ├── CONTRIBUTING.md ├── Documentation~ ├── README.md └── Unity.AI.MLAgents.api ├── Editor.meta ├── Editor ├── PolicySpecsDrawer.cs ├── PolicySpecsDrawer.cs.meta ├── Unity.AI.MLAgents.Editor.asmdef └── Unity.AI.MLAgents.Editor.asmdef.meta ├── LICENSE.md ├── LICENSE.md.meta ├── README.md ├── README.md.meta ├── Runtime.meta ├── Runtime ├── Academy.cs ├── Academy.cs.meta ├── ActionHashMapUtils.cs ├── ActionHashMapUtils.cs.meta ├── ActuatorJob.cs ├── ActuatorJob.cs.meta ├── ArrayUtils.cs ├── ArrayUtils.cs.meta ├── AssemblyInfo.cs ├── AssemblyInfo.cs.meta ├── EnvironmentParameters.cs ├── EnvironmentParameters.cs.meta ├── MLAgentsException.cs ├── MLAgentsException.cs.meta ├── Policy.meta ├── Policy │ ├── Counter.cs │ ├── Counter.cs.meta │ ├── DecisionRequest.cs │ ├── DecisionRequest.cs.meta │ ├── EpisodeTermination.cs │ ├── EpisodeTermination.cs.meta │ ├── Policy.cs │ └── Policy.cs.meta ├── PolicyProcessor.meta ├── PolicyProcessor │ ├── BarracudaPolicyProcessor.cs │ ├── BarracudaPolicyProcessor.cs.meta │ ├── HeuristicPolicyProcessor.cs │ ├── HeuristicPolicyProcessor.cs.meta │ ├── IPolicyProcessor.cs │ ├── IPolicyProcessor.cs.meta │ ├── NullPolicyProcessor.cs │ ├── NullPolicyProcessor.cs.meta │ ├── RemotePolicyProcessor.cs │ └── RemotePolicyProcessor.cs.meta ├── Remote.meta ├── Remote │ ├── ArgumentParser.cs │ ├── ArgumentParser.cs.meta │ ├── BaseSharedMemory.cs │ ├── BaseSharedMemory.cs.meta │ ├── RLDataOffsets.cs │ ├── RLDataOffsets.cs.meta │ ├── SharedMemoryBody.cs │ ├── SharedMemoryBody.cs.meta │ ├── SharedMemoryCommunicator.cs │ ├── SharedMemoryCommunicator.cs.meta │ ├── SharedMemoryHeader.cs │ └── SharedMemoryHeader.cs.meta ├── SideChannels.meta ├── SideChannels │ ├── EngineConfigurationChannel.cs │ ├── EngineConfigurationChannel.cs.meta │ ├── EnvironmentParametersChannel.cs │ ├── EnvironmentParametersChannel.cs.meta │ ├── FloatPropertiesChannel.cs │ ├── FloatPropertiesChannel.cs.meta │ ├── IncomingMessage.cs │ ├── IncomingMessage.cs.meta │ ├── OutgoingMessage.cs │ ├── OutgoingMessage.cs.meta │ ├── RawBytesChannel.cs │ ├── RawBytesChannel.cs.meta │ ├── SideChannel.cs │ ├── SideChannel.cs.meta │ ├── SideChannelsManager.cs │ ├── SideChannelsManager.cs.meta │ ├── StatsSideChannel.cs │ └── StatsSideChannel.cs.meta ├── StatsRecorder.cs ├── StatsRecorder.cs.meta ├── TimeUtils.cs ├── TimeUtils.cs.meta ├── UI.meta ├── UI │ ├── PolicySpecs.cs │ └── PolicySpecs.cs.meta ├── Unity.AI.MLAgents.asmdef ├── Unity.AI.MLAgents.asmdef.meta ├── Visual.meta └── Visual │ ├── VisualObservationUtility.cs │ └── VisualObservationUtility.cs.meta ├── Samples~ ├── 3DBall.meta ├── 3DBall │ ├── NNModels.meta │ ├── NNModels │ │ ├── 3DBall.onnx │ │ └── 3DBall.onnx.meta │ ├── Prefab.meta │ ├── Prefab │ │ ├── AgentBlue.mat │ │ ├── AgentBlue.mat.meta │ │ ├── Ball.prefab │ │ ├── Ball.prefab.meta │ │ ├── CheckersGray_BC.png │ │ ├── CheckersGray_BC.png.meta │ │ ├── Checkers_Ball.mat │ │ ├── Checkers_Ball.mat.meta │ │ ├── Platform.prefab │ │ └── Platform.prefab.meta │ ├── Scene.meta │ ├── Scene │ │ ├── 3DBall.unity │ │ └── 3DBall.unity.meta │ ├── Script.meta │ └── Script │ │ ├── BalanceBallManager.cs │ │ ├── BalanceBallManager.cs.meta │ │ ├── BallSystem.cs │ │ ├── BallSystem.cs.meta │ │ ├── CameraMovement.cs │ │ └── CameraMovement.cs.meta ├── Basic.meta ├── Basic │ ├── NNModels.meta │ ├── NNModels │ │ ├── Basic.onnx │ │ └── Basic.onnx.meta │ ├── Prefab.meta │ ├── Prefab │ │ ├── AgentBlue.mat │ │ ├── AgentBlue.mat.meta │ │ ├── Basic.prefab │ │ ├── Basic.prefab.meta │ │ ├── Black.mat │ │ ├── Black.mat.meta │ │ ├── Eye.mat │ │ ├── Eye.mat.meta │ │ ├── Green.mat │ │ ├── Green.mat.meta │ │ ├── GridMatFloor.mat │ │ ├── GridMatFloor.mat.meta │ │ ├── GridPatternShader.shader │ │ ├── GridPatternShader.shader.meta │ │ ├── Headband.mat │ │ └── Headband.mat.meta │ ├── Scene.meta │ ├── Scene │ │ ├── Basic.unity │ │ └── Basic.unity.meta │ ├── Script.meta │ └── Script │ │ ├── BasicAgent.cs │ │ ├── BasicAgent.cs.meta │ │ ├── BasicController.cs │ │ └── BasicController.cs.meta ├── PushBlock │ ├── Meshes.meta │ ├── Meshes │ │ ├── AgentBlue.mat │ │ ├── AgentBlue.mat.meta │ │ ├── Checkers_Gray.mat │ │ ├── Checkers_Gray.mat.meta │ │ ├── Eye.mat │ │ ├── Eye.mat.meta │ │ ├── GrayMiddle.mat │ │ ├── GrayMiddle.mat.meta │ │ ├── Green.mat │ │ ├── Green.mat.meta │ │ ├── GridMatFloor.mat │ │ ├── GridMatFloor.mat.meta │ │ ├── GridPatternShaderPushBlock.shader │ │ ├── GridPatternShaderPushBlock.shader.meta │ │ ├── Headband.mat │ │ ├── Headband.mat.meta │ │ ├── PushBlockCourt.fbx │ │ ├── PushBlockCourt.fbx.meta │ │ ├── White.mat │ │ └── White.mat.meta │ ├── NNModels.meta │ ├── NNModels │ │ ├── PushBlock.onnx │ │ └── PushBlock.onnx.meta │ ├── Prefabs.meta │ ├── Prefabs │ │ ├── PushBlockArea.prefab │ │ └── PushBlockArea.prefab.meta │ ├── Scenes.meta │ ├── Scenes │ │ ├── PushBlock.unity │ │ └── PushBlock.unity.meta │ ├── Scripts.meta │ └── Scripts │ │ ├── Block.cs │ │ ├── Block.cs.meta │ │ ├── BlockCollisionSystem.cs │ │ ├── BlockCollisionSystem.cs.meta │ │ ├── PolicySpecsMonoBehavior.cs │ │ ├── PolicySpecsMonoBehavior.cs.meta │ │ ├── PushBlockAction.cs │ │ ├── PushBlockAction.cs.meta │ │ ├── PushBlockCube.cs │ │ ├── PushBlockCube.cs.meta │ │ ├── PushBlockCubeMoveSystem.cs │ │ └── PushBlockCubeMoveSystem.cs.meta ├── StringSideChannel.meta └── StringSideChannel │ ├── RegisterStringLogSideChannel.cs │ └── RegisterStringLogSideChannel.cs.meta ├── Tests.meta ├── Tests ├── Editor.meta └── Editor │ ├── TestArrayUtils.cs │ ├── TestArrayUtils.cs.meta │ ├── TestCounter.cs │ ├── TestCounter.cs.meta │ ├── TestMLAgentsPolicy.cs │ ├── TestMLAgentsPolicy.cs.meta │ ├── TestSharedMemory.cs │ ├── TestSharedMemory.cs.meta │ ├── TestVisualObservationUtility.cs │ ├── TestVisualObservationUtility.cs.meta │ ├── Unity.AI.MLAgents.Tests.asmdef │ └── Unity.AI.MLAgents.Tests.asmdef.meta ├── ml-agents-dots-envs~ ├── mlagents_dots_envs │ ├── __init__.py │ ├── examples │ │ └── example_script.py │ ├── shared_memory │ │ ├── __init__ .py │ │ ├── base_shared_memory.py │ │ ├── rl_data_offsets.py │ │ ├── shared_memory_body.py │ │ ├── shared_memory_communicator.py │ │ └── shared_memory_header.py │ ├── string_side_channel.py │ ├── test │ │ └── test_shared_memory.py │ └── unity_environment.py └── setup.py ├── ml-agents-dots-learn~ ├── mlagents_dots_learn │ ├── __init__.py │ └── dots_learn.py └── setup.py ├── package.json └── package.json.meta /.editorconfig: -------------------------------------------------------------------------------- 1 | ; see http://editorconfig.org/ for docs on this file 2 | 3 | root = true 4 | 5 | [**] 6 | ignore_if_in_header = This code was generated by a tool| 7 | indent_style = space 8 | indent_size = 4 9 | ; uncomment to help with sharing files across os's (i.e. network share or through local vm) 10 | #end_of_line = lf 11 | ; avoid a bom, which causes endless problems with naive text tooling 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | ; keeping auto-format enabled helps avoid merge hell for projects without CI-based format validation 16 | #disable_auto_format = true 17 | 18 | [**.cs] 19 | ; uncomment to enable full formatting of c# files 20 | formatters = generic, uncrustify 21 | 22 | [**.asmdef] 23 | scrape_api = true 24 | 25 | [**/Tests/**.asmdef] 26 | scrape_api = false 27 | 28 | [*.Tests.asmdef] 29 | scrape_api = false 30 | 31 | [**.md] 32 | indent_size = 2 33 | ; trailing whitespace is unfortunately significant in markdown 34 | trim_trailing_whitespace = false 35 | ; uncomment to enable basic formatting of markdown files 36 | #formatters = generic 37 | 38 | [{Makefile,makefile}] 39 | ; tab characters are part of the Makefile format 40 | indent_style = tab 41 | 42 | [**.asmdef] 43 | indent_size = 4 44 | 45 | [**.json] 46 | indent_size = 2 47 | 48 | [**.{vcproj,bat,cmd,xaml,tt,t4,ttinclude}] 49 | end_of_line = crlf 50 | 51 | ; this VS-specific stuff is based on experiments to see how VS will modify a file after it has been manually edited. 52 | ; the settings are meant to closely match what VS does to minimize unnecessary diffs. 53 | [**.{vcxproj,vcxproj.filters}] 54 | indent_style = space 55 | indent_size = 2 56 | end_of_line = crlf 57 | charset = utf-8-bom 58 | trim_trailing_whitespace = true 59 | insert_final_newline = false 60 | ; must be broken out because of 51-char bug (https://github.com/editorconfig/editorconfig-visualstudio/issues/21) 61 | [**.{csproj,pyproj,props,targets}] 62 | indent_style = space 63 | indent_size = 2 64 | end_of_line = crlf 65 | charset = utf-8-bom 66 | trim_trailing_whitespace = true 67 | insert_final_newline = false 68 | [**.{sln,sln.template}] 69 | indent_style = tab 70 | indent_size = 4 71 | end_of_line = crlf 72 | charset = utf-8 73 | trim_trailing_whitespace = true 74 | insert_final_newline = false 75 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignoring the folloging files auto generated by Unity 2 | *.DS_Store 3 | *.idea 4 | *.csproj 5 | *.sln 6 | *.user 7 | *Library 8 | *Logs 9 | *Temp 10 | *obj 11 | .pytest_cache 12 | *__pycache__ 13 | 14 | # Mac hidden files 15 | *.DS_Store 16 | */.ipynb_checkpoints 17 | */.idea 18 | *.pyc 19 | *.idea/misc.xml 20 | *.idea/modules.xml 21 | *.idea/ 22 | *.iml 23 | *.cache 24 | */build/ 25 | */dist/ 26 | *.egg-info* 27 | *.eggs* 28 | *.gitignore.swp 29 | 30 | # Output Artifacts 31 | /results 32 | /results.meta 33 | 34 | # precommit 35 | .mypy_cache 36 | .pre-commit-config.yaml 37 | .pylintrc 38 | .vscode 39 | setup.cfg 40 | setup.cfg.meta 41 | 42 | # API files 43 | *.api 44 | *.api.meta 45 | 46 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this package will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 6 | 7 | ## Unreleased 8 | 9 | ## [0.3.0-preview] - 2020-06-09 10 | 11 | ### Description 12 | - Updated the shared memory communication to be more modular 13 | - Added materials and textures to the 3DBall Sample 14 | - Modified the API to reflect changes made to mlagents_envs version 0.16.0 15 | - Renamed MLAgentsWorld to Policy 16 | 17 | ## [0.2.0-preview] - 2019-02-24 18 | 19 | ### Description 20 | - Added a CHANGELOG.md 21 | - Added a License 22 | - Renamed methods to be Register X rather than Subscribe X 23 | - Renames the `HasTerminated` method to `SetEpisodeStatus` 24 | 25 | -------------------------------------------------------------------------------- /CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 118ac16c2d3b0423db9c2fe79f4d1da6 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | Thank you for your interest in contributing to this project! 4 | To facilitate your contributions, we've outlined a brief set 5 | of guidelines to ensure that your extensions can be easily integrated. 6 | 7 | ## Git Branches 8 | 9 | The main branch corresponds to the most recent version of the project. 10 | 11 | When contributing to the project, please make sure that your Pull Request (PR) 12 | contains the following: 13 | 14 | - Detailed description of the changes performed 15 | - Corresponding changes to documentation and sample environments (if 16 | applicable) 17 | - Summary of the tests performed to validate your changes 18 | - Issue numbers that the PR resolves (if any) 19 | 20 | ## Contributor License Agreements 21 | 22 | When you open a pull request, you will be asked to acknowledge our Contributor 23 | License Agreement. We allow both individual contributions and contributions made 24 | on behalf of companies. We use an open source tool called CLA assistant. 25 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 11ae2763f3ece432e997da8d67fcaa9b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/PolicySpecsDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94a88b2001ca84a0aa8eb12a93dffc6e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Unity.AI.MLAgents.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.AI.MLAgents.Editor", 3 | "references": [ 4 | "Unity.Mathematics", 5 | "Unity.AI.MLAgents", 6 | "Unity.Barracuda" 7 | ], 8 | "includePlatforms": [ 9 | "Editor" 10 | ], 11 | "excludePlatforms": [], 12 | "allowUnsafeCode": false, 13 | "overrideReferences": false, 14 | "precompiledReferences": [], 15 | "autoReferenced": false, 16 | "defineConstraints": [], 17 | "versionDefines": [], 18 | "noEngineReferences": false 19 | } -------------------------------------------------------------------------------- /Editor/Unity.AI.MLAgents.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c273e66ec252e472f9e3f6be33d87f28 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Unity.AI.MLAgents copyright © 2020 Unity Technologies ApS 2 | 3 | Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | 5 | Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions. 6 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a2b45f893a271448b88eab6bc22b91ba 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # ML-Agents DOTS 3 | 4 | This repository is a prototype of a DOTS compatible version of the [ML-Agents](https://github.com/Unity-Technologies/ml-agents/tree/python-packages_0.25.0). It uses the [Data Oriented Tech Stack (DOTS)](https://unity.com/dots) of Unity. 5 | Note that not all features of ML-Agents are supported. For example, it is not possible to use imitation learning or cooperative/adversarial behaviors yet. The API of the DOTS version is different from the ML-Agents API in the Editor, it is the responsibility of the user to update the observations of the Agents since there are no implementation of sensors. 6 | For more information about the API please see the [Documentation](./Documentation~/README.md). 7 | 8 | 9 | [Documentation](./Documentation~/README.md) 10 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 97aeb0f7f51734b588140f6ea2f35206 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a0cd56a68d2b45ca9eb96773192c959 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Academy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ab880b3b1cc2456dad9018e9ff16922 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/ActionHashMapUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca933897f41344db09d36d8c1a91313e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/ActuatorJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a42c8b84d2df146e1ac810b3d33a96c0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/ArrayUtils.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Mathematics; 3 | using System.Text; 4 | 5 | namespace Unity.AI.MLAgents 6 | { 7 | internal static class ArrayUtils 8 | { 9 | public static int Sum(this NativeArray array) 10 | { 11 | int result = 0; 12 | for (int i = 0; i < array.Length; i++) 13 | { 14 | result += array[i]; 15 | } 16 | return result; 17 | } 18 | 19 | /// 20 | /// Returns the sum of all the values of an integer NativeArray that are strictly before 21 | /// a certain index. 22 | /// For example, if index is 0, then the output is always 0 23 | /// If index it 2, then the result is the sum of the first 2 values in the array 24 | /// 25 | public static int CumSumAt(this NativeArray array, int index) 26 | { 27 | int result = 0; 28 | for (int i = 0; i < index; i++) 29 | { 30 | result += array[i]; 31 | } 32 | return result; 33 | } 34 | 35 | public static int IncreaseArraySizeHeuristic(int newSize) 36 | { 37 | return newSize * 2 + 20; 38 | } 39 | 40 | public static int GetTotalTensorSize(this int3 tensorShape) 41 | { 42 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 43 | tensorShape.AssertIsShape(); 44 | #endif 45 | return tensorShape.x * math.max(1, tensorShape.y) * math.max(1, tensorShape.z); 46 | } 47 | 48 | public static int GetDimensions(this int3 tensorShape) 49 | { 50 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 51 | tensorShape.AssertIsShape(); 52 | #endif 53 | if (tensorShape.x == 0) 54 | { 55 | return 0; 56 | } 57 | if (tensorShape.y == 0) 58 | { 59 | return 1; 60 | } 61 | if (tensorShape.z == 0) 62 | { 63 | return 2; 64 | } 65 | return 3; 66 | } 67 | 68 | private static void AssertIsShape(this int3 shape) 69 | { 70 | if (shape.x == 0 && (shape.y != 0 || shape.y != 0)) 71 | { 72 | throw new MLAgentsException( 73 | "Tensor shape cannot have first dimension be zero and other dimensions not be zero" 74 | ); 75 | } 76 | if (shape.y == 0 && shape.z != 0) 77 | { 78 | throw new MLAgentsException( 79 | "Tensor shape cannot have second dimension be zero and third dimensions not be zero" 80 | ); 81 | } 82 | if (shape.x < 0 || shape.y < 0 || shape.z < 0) 83 | { 84 | throw new MLAgentsException( 85 | "Tensor shape cannot have negative dimensions" 86 | ); 87 | } 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Runtime/ArrayUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3b1cf5eeb14d341bd86af7f29f148b8c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Unity.AI.MLAgents.Tests")] 4 | [assembly: InternalsVisibleTo("Unity.AI.MLAgents.Editor")] 5 | -------------------------------------------------------------------------------- /Runtime/AssemblyInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 19cf7257596f34d0480f97ec363161ba 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/EnvironmentParameters.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Unity.AI.MLAgents.SideChannels; 4 | 5 | namespace Unity.AI.MLAgents 6 | { 7 | /// 8 | /// A container for the Environment Parameters that may be modified during training. 9 | /// The keys for those parameters are defined in the trainer configurations and the 10 | /// the values are generated from the training process in features such as Curriculum Learning 11 | /// and Environment Parameter Randomization. 12 | /// 13 | /// One current assumption for all the environment parameters is that they are of type float. 14 | /// 15 | public sealed class EnvironmentParameters 16 | { 17 | /// 18 | /// The side channel that is used to receive the new parameter values. 19 | /// 20 | readonly EnvironmentParametersChannel m_Channel; 21 | 22 | /// 23 | /// Constructor. 24 | /// 25 | internal EnvironmentParameters() 26 | { 27 | m_Channel = new EnvironmentParametersChannel(); 28 | SideChannelManager.RegisterSideChannel(m_Channel); 29 | } 30 | 31 | /// 32 | /// Returns the parameter value for the specified key. Returns the default value provided 33 | /// if this parameter key does not have a value. Only returns a parameter value if it is 34 | /// of type float. 35 | /// 36 | /// The parameter key 37 | /// Default value for this parameter. 38 | /// 39 | public float GetWithDefault(string key, float defaultValue) 40 | { 41 | return m_Channel.GetWithDefault(key, defaultValue); 42 | } 43 | 44 | /// 45 | /// Registers a callback action for the provided parameter key. Will overwrite any 46 | /// existing action for that parameter. The callback will be called whenever the parameter 47 | /// receives a value from the training process. 48 | /// 49 | /// The parameter key 50 | /// The callback action 51 | public void RegisterCallback(string key, Action action) 52 | { 53 | m_Channel.RegisterCallback(key, action); 54 | } 55 | 56 | /// 57 | /// Returns a list of all the parameter keys that have received values. 58 | /// 59 | /// List of parameter keys. 60 | public IList Keys() 61 | { 62 | return m_Channel.ListParameters(); 63 | } 64 | 65 | internal void Dispose() 66 | { 67 | SideChannelManager.UnregisterSideChannel(m_Channel); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Runtime/EnvironmentParameters.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 871ed045f9fa94423a87e84f1a8d615a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/MLAgentsException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Unity.AI.MLAgents 4 | { 5 | /// 6 | /// Contains exceptions specific to ML-Agents. 7 | /// 8 | public class MLAgentsException : Exception 9 | { 10 | /// 11 | /// This exception indicates an error occurred in the ML-Agents package 12 | /// 13 | /// Text message for the error 14 | /// 15 | public MLAgentsException(string message) : base(message) {} 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Runtime/MLAgentsException.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8666d1a86fee84bf4a44549d2560e594 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Policy.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 188f3226902724445b4fcc4c508adc3f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Policy/Counter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Threading; 4 | using Unity.Collections; 5 | using Unity.Collections.LowLevel.Unsafe; 6 | 7 | 8 | namespace Unity.AI.MLAgents 9 | { 10 | internal unsafe struct Counter : IDisposable 11 | { 12 | [NativeDisableUnsafePtrRestriction] 13 | int* m_Counter; 14 | Allocator m_Alloc; 15 | 16 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 17 | internal AtomicSafetyHandle m_Safety; 18 | [NativeSetClassTypeToNullOnSchedule] 19 | internal DisposeSentinel m_DisposeSentinel; 20 | #endif 21 | 22 | public Counter(Allocator alloc) 23 | { 24 | m_Alloc = alloc; 25 | m_Counter = (int*)UnsafeUtility.Malloc(4, 4, m_Alloc); 26 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 27 | DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 0, m_Alloc); 28 | #endif 29 | Count = 0; 30 | } 31 | 32 | public void Dispose() 33 | { 34 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 35 | DisposeSentinel.Dispose(ref m_Safety, ref m_DisposeSentinel); 36 | #endif 37 | UnsafeUtility.Free(m_Counter, m_Alloc); 38 | m_Counter = null; 39 | } 40 | 41 | public int Count 42 | { 43 | get 44 | { 45 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 46 | AtomicSafetyHandle.CheckReadAndThrow(m_Safety); 47 | #endif 48 | return *m_Counter; 49 | } 50 | set 51 | { 52 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 53 | AtomicSafetyHandle.CheckWriteAndThrow(m_Safety); 54 | #endif 55 | *m_Counter = value; 56 | } 57 | } 58 | 59 | public int Increment() 60 | { 61 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 62 | AtomicSafetyHandle.CheckReadAndThrow(m_Safety); 63 | AtomicSafetyHandle.CheckWriteAndThrow(m_Safety); 64 | #endif 65 | return Interlocked.Increment(ref *m_Counter); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Runtime/Policy/Counter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 771903c3f38d24f878e67956113e17c5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Policy/DecisionRequest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 34714dfb9c47f4e17862e445cc2a4c11 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Policy/EpisodeTermination.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: adfe37fbf825d411ca68eb2d3288cf0c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Policy/Policy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d3bc272a74fb942c6ae0978b85a9f4b3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/PolicyProcessor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8f9bda6ea6c434b5c83b88e89f86d373 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/PolicyProcessor/BarracudaPolicyProcessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 660d70ae128d3471d9719521b9f6b1a8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/PolicyProcessor/HeuristicPolicyProcessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bbdb4af50f1d14325b3cdcf83d60d207 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/PolicyProcessor/IPolicyProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Unity.Collections; 3 | using Unity.Collections.LowLevel.Unsafe; 4 | 5 | 6 | namespace Unity.AI.MLAgents 7 | { 8 | /// 9 | /// The interface for a Policy processor. A Policy processor updates the 10 | /// action data of a Policy using the observation data present in it. 11 | /// 12 | public interface IPolicyProcessor : IDisposable 13 | { 14 | /// 15 | /// True if the Policy Processor is connected to the Python process 16 | /// 17 | bool IsConnected {get;} 18 | 19 | /// 20 | /// This method is called once everytime the policy needs to update its action 21 | /// data. The implementation of this mehtod must give new action data to all the 22 | /// agents that requested a decision. 23 | /// 24 | void Process(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Runtime/PolicyProcessor/IPolicyProcessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36c9b9c8340e449159335cb6a960afc4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/PolicyProcessor/NullPolicyProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Unity.Collections; 3 | using Unity.Collections.LowLevel.Unsafe; 4 | 5 | 6 | namespace Unity.AI.MLAgents 7 | { 8 | internal class NullPolicyProcessor : IPolicyProcessor 9 | { 10 | private Policy m_Policy; 11 | 12 | public bool IsConnected {get {return false;}} 13 | 14 | internal NullPolicyProcessor(Policy policy) 15 | { 16 | this.m_Policy = policy; 17 | } 18 | 19 | public void Process() 20 | { 21 | } 22 | 23 | public void Dispose() 24 | { 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Runtime/PolicyProcessor/NullPolicyProcessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eed74bf08879d4edeaa493d4218a9e9c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/PolicyProcessor/RemotePolicyProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Unity.Collections; 3 | using Unity.Collections.LowLevel.Unsafe; 4 | using Unity.AI.MLAgents.SideChannels; 5 | 6 | 7 | namespace Unity.AI.MLAgents 8 | { 9 | internal class RemotePolicyProcessor : IPolicyProcessor 10 | { 11 | private Policy m_Policy; 12 | private SharedMemoryCommunicator m_Communicator; 13 | private string m_PolicyId; 14 | 15 | public bool IsConnected {get {return true;}} 16 | 17 | internal RemotePolicyProcessor(Policy policy, string policyId, SharedMemoryCommunicator com) 18 | { 19 | this.m_Policy = policy; 20 | this.m_Communicator = com; 21 | this.m_PolicyId = policyId; 22 | } 23 | 24 | public void Process() 25 | { 26 | m_Communicator.WritePolicy(m_PolicyId, m_Policy); 27 | m_Communicator.SetUnityReady(); 28 | m_Communicator.WaitForPython(); 29 | AnswerQuery(); 30 | m_Communicator.LoadPolicy(m_PolicyId, m_Policy); 31 | } 32 | 33 | public void Dispose() 34 | { 35 | } 36 | 37 | private void AnswerQuery() 38 | { 39 | while (m_Communicator.ReadAndClearQueryCommand()) 40 | { 41 | SideChannelManager.ProcessSideChannelData(m_Communicator.ReadAndClearSideChannelData()); 42 | m_Communicator.WriteSideChannelData(SideChannelManager.GetSideChannelMessage()); 43 | m_Communicator.SetUnityReady(); 44 | m_Communicator.WaitForPython(); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Runtime/PolicyProcessor/RemotePolicyProcessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 857fd439abb904fa492a86209ce79611 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Remote.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2187bf4b29e2e441ab6d144d657b0b63 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Remote/ArgumentParser.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | 4 | namespace Unity.AI.MLAgents 5 | { 6 | internal static class ArgumentParser 7 | { 8 | private const string k_MemoryFileArgument = "--memory-path"; 9 | private const string k_MemoryFilesDirectory = "ml-agents"; 10 | private const string k_DefaultFileName = "default"; 11 | 12 | /// 13 | /// Used to read Python-provided environment parameters. Will return the 14 | /// string corresponding to the path to the shared memory file. 15 | /// 16 | /// Path to the shared memroy file or null if no file is available 17 | public static string ReadSharedMemoryPathFromArgs() 18 | { 19 | var args = System.Environment.GetCommandLineArgs(); 20 | for (var i = 0; i < args.Length; i++) 21 | { 22 | if (args[i] == k_MemoryFileArgument) 23 | { 24 | return args[i + 1]; 25 | } 26 | } 27 | #if UNITY_EDITOR 28 | // Try connecting on the default shared memory file 29 | var path = Path.Combine( 30 | Path.GetTempPath(), 31 | k_MemoryFilesDirectory, 32 | k_DefaultFileName); 33 | if (File.Exists(path)) 34 | { 35 | return path; 36 | } 37 | return null; 38 | #else 39 | // This is an executable, so we don't try to connect if no argument was passed. 40 | return null; 41 | #endif 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Runtime/Remote/ArgumentParser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b77549559992f4c7cb03a4582833b484 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Remote/BaseSharedMemory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 99dfe452c5cce44bbbd076a80d854480 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Remote/RLDataOffsets.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5fcb53fda770e4b75902dcdd9d68b01f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Remote/SharedMemoryBody.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0d0d51f55e1644c48cf8e72e3bd6998 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Remote/SharedMemoryCommunicator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 25d0d8e58dedf405696420ba0a897414 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Remote/SharedMemoryHeader.cs: -------------------------------------------------------------------------------- 1 | namespace Unity.AI.MLAgents 2 | { 3 | /// 4 | /// Always created by Python 5 | /// 6 | internal class SharedMemoryHeader : BaseSharedMemory 7 | { 8 | private const int k_MajorVersion = 0; 9 | private const int k_MinorVersion = 3; 10 | private const int k_BugVersion = 2; 11 | 12 | public SharedMemoryHeader(string fileName) : base(fileName, false) {} 13 | 14 | public bool Active 15 | { 16 | get 17 | { 18 | if (!CanEdit) 19 | { 20 | return false; 21 | } 22 | return !GetBool(15); 23 | } 24 | } 25 | 26 | public int FileNumber 27 | { 28 | get { return GetInt(16); } 29 | set { SetInt(16, value); } 30 | } 31 | 32 | public bool Blocked 33 | { 34 | get { return GetBool(12); } 35 | } 36 | 37 | new public void Close() 38 | { 39 | if (CanEdit) 40 | { 41 | SetBool(15, true); 42 | } 43 | base.Close(); 44 | } 45 | 46 | public void MarkUnityBlocked() 47 | { 48 | SetBool(12, true); 49 | } 50 | 51 | public void UnblockPython() 52 | { 53 | SetBool(13, false); 54 | } 55 | 56 | public bool ReadAndClearResetCommand() 57 | { 58 | if (!CanEdit) 59 | { 60 | return false; 61 | } 62 | var result = GetBool(14); 63 | SetBool(14, false); 64 | return result; 65 | } 66 | 67 | public bool ReadAndClearQueryCommand() 68 | { 69 | if (!CanEdit) 70 | { 71 | return false; 72 | } 73 | var result = GetBool(28); 74 | SetBool(28, false); 75 | return result; 76 | } 77 | 78 | public int SideChannelBufferSize 79 | { 80 | get { return GetInt(20); } 81 | set { SetInt(20, value); } 82 | } 83 | 84 | public int RLDataBufferSize 85 | { 86 | get { return GetInt(24); } 87 | set { SetInt(24, value); } 88 | } 89 | 90 | public bool CheckVersion() 91 | { 92 | int major = GetInt(0); 93 | SetInt(0, k_MajorVersion); 94 | int minor = GetInt(4); 95 | SetInt(4, k_MinorVersion); 96 | int bug = GetInt(8); 97 | SetInt(8, k_BugVersion); 98 | if (major != k_MajorVersion || minor != k_MinorVersion || bug != k_BugVersion) 99 | { 100 | return false; 101 | } 102 | return true; 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Runtime/Remote/SharedMemoryHeader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52f60edd6340142e79967efed81b7042 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/SideChannels.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3373ffc27c55141a388b32b1aad73756 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/SideChannels/EngineConfigurationChannel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using Unity.Entities; 4 | 5 | namespace Unity.AI.MLAgents.SideChannels 6 | { 7 | /// 8 | /// Side channel that supports modifying attributes specific to the Unity Engine. 9 | /// 10 | internal class EngineConfigurationChannel : SideChannel 11 | { 12 | private enum ConfigurationType : int 13 | { 14 | ScreenResolution = 0, 15 | QualityLevel = 1, 16 | TimeScale = 2, 17 | TargetFrameRate = 3, 18 | CaptureFrameRate = 4 19 | } 20 | 21 | const string k_EngineConfigId = "e951342c-4f7e-11ea-b238-784f4387d1f7"; 22 | 23 | /// 24 | /// Initializes the side channel. The constructor is internal because only one instance is 25 | /// supported at a time, and is created by the Academy. 26 | /// 27 | internal EngineConfigurationChannel() 28 | { 29 | ChannelId = new Guid(k_EngineConfigId); 30 | } 31 | 32 | /// 33 | protected override void OnMessageReceived(IncomingMessage msg) 34 | { 35 | var messageType = (ConfigurationType)msg.ReadInt32(); 36 | switch (messageType) 37 | { 38 | case ConfigurationType.ScreenResolution: 39 | var width = msg.ReadInt32(); 40 | var height = msg.ReadInt32(); 41 | Screen.SetResolution(width, height, false); 42 | break; 43 | case ConfigurationType.QualityLevel: 44 | var qualityLevel = msg.ReadInt32(); 45 | QualitySettings.SetQualityLevel(qualityLevel, true); 46 | break; 47 | case ConfigurationType.TimeScale: 48 | var timeScale = msg.ReadFloat32(); 49 | timeScale = Mathf.Clamp(timeScale, 1f, 100f); 50 | Time.timeScale = timeScale; 51 | SetSimulationGroupTime(); 52 | break; 53 | case ConfigurationType.TargetFrameRate: 54 | var targetFrameRate = msg.ReadInt32(); 55 | Application.targetFrameRate = targetFrameRate; 56 | break; 57 | case ConfigurationType.CaptureFrameRate: 58 | var captureFrameRate = msg.ReadInt32(); 59 | Time.captureFramerate = captureFrameRate; 60 | SetSimulationGroupTime(); 61 | break; 62 | default: 63 | Debug.LogWarning( 64 | "Unknown engine configuration received from Python. Make sure" + 65 | " your Unity and Python versions are compatible."); 66 | break; 67 | } 68 | } 69 | 70 | private void SetSimulationGroupTime() 71 | { 72 | var simGroup = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem(); 73 | if (Time.captureDeltaTime > 0) 74 | { 75 | TimeUtils.EnableFixedRateWithRepeat(simGroup, Time.captureDeltaTime, (int)Time.timeScale + 1); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Runtime/SideChannels/EngineConfigurationChannel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 18ccdf3ce76784f2db68016fa284c33f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/SideChannels/EnvironmentParametersChannel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using UnityEngine; 4 | 5 | namespace Unity.AI.MLAgents.SideChannels 6 | { 7 | /// 8 | /// Lists the different data types supported. 9 | /// 10 | internal enum EnvironmentDataTypes 11 | { 12 | Float = 0 13 | } 14 | 15 | /// 16 | /// A side channel that manages the environment parameter values from Python. Currently 17 | /// limited to parameters of type float. 18 | /// 19 | internal class EnvironmentParametersChannel : SideChannel 20 | { 21 | Dictionary m_Parameters = new Dictionary(); 22 | Dictionary> m_RegisteredActions = 23 | new Dictionary>(); 24 | 25 | const string k_EnvParamsId = "534c891e-810f-11ea-a9d0-822485860400"; 26 | 27 | /// 28 | /// Initializes the side channel. The constructor is internal because only one instance is 29 | /// supported at a time, and is created by the Academy. 30 | /// 31 | internal EnvironmentParametersChannel() 32 | { 33 | ChannelId = new Guid(k_EnvParamsId); 34 | } 35 | 36 | /// 37 | protected override void OnMessageReceived(IncomingMessage msg) 38 | { 39 | var key = msg.ReadString(); 40 | var type = msg.ReadInt32(); 41 | if ((int)EnvironmentDataTypes.Float == type) 42 | { 43 | var value = msg.ReadFloat32(); 44 | 45 | m_Parameters[key] = value; 46 | 47 | Action action; 48 | m_RegisteredActions.TryGetValue(key, out action); 49 | action?.Invoke(value); 50 | } 51 | else 52 | { 53 | Debug.LogWarning("EnvironmentParametersChannel received an unknown data type."); 54 | } 55 | } 56 | 57 | /// 58 | /// Returns the parameter value associated with the provided key. Returns the default 59 | /// value if one doesn't exist. 60 | /// 61 | /// Parameter key. 62 | /// Default value to return. 63 | /// 64 | public float GetWithDefault(string key, float defaultValue) 65 | { 66 | float valueOut; 67 | bool hasKey = m_Parameters.TryGetValue(key, out valueOut); 68 | return hasKey ? valueOut : defaultValue; 69 | } 70 | 71 | /// 72 | /// Registers a callback for the associated parameter key. Will overwrite any existing 73 | /// actions for this parameter key. 74 | /// 75 | /// The parameter key. 76 | /// The callback. 77 | public void RegisterCallback(string key, Action action) 78 | { 79 | m_RegisteredActions[key] = action; 80 | } 81 | 82 | /// 83 | /// Returns all parameter keys that have a registered value. 84 | /// 85 | /// 86 | public IList ListParameters() 87 | { 88 | return new List(m_Parameters.Keys); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Runtime/SideChannels/EnvironmentParametersChannel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a849760d5bec946b884984e35c66fcfa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/SideChannels/FloatPropertiesChannel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | 4 | namespace Unity.AI.MLAgents.SideChannels 5 | { 6 | /// 7 | /// Side channel that is comprised of a collection of float variables. 8 | /// 9 | public class FloatPropertiesChannel : SideChannel 10 | { 11 | Dictionary m_FloatProperties = new Dictionary(); 12 | Dictionary> m_RegisteredActions = new Dictionary>(); 13 | private const string k_FloatPropertiesDefaultId = "60ccf7d0-4f7e-11ea-b238-784f4387d1f7"; 14 | 15 | /// 16 | /// Initializes the side channel with the provided channel ID. 17 | /// 18 | /// ID for the side channel. 19 | public FloatPropertiesChannel(Guid channelId = default(Guid)) 20 | { 21 | if (channelId == default(Guid)) 22 | { 23 | ChannelId = new Guid(k_FloatPropertiesDefaultId); 24 | } 25 | else 26 | { 27 | ChannelId = channelId; 28 | } 29 | } 30 | 31 | /// 32 | protected override void OnMessageReceived(IncomingMessage msg) 33 | { 34 | var key = msg.ReadString(); 35 | var value = msg.ReadFloat32(); 36 | 37 | m_FloatProperties[key] = value; 38 | 39 | Action action; 40 | m_RegisteredActions.TryGetValue(key, out action); 41 | action?.Invoke(value); 42 | } 43 | 44 | /// 45 | /// Sets one of the float properties of the environment. This data will be sent to Python. 46 | /// 47 | /// The string identifier of the property. 48 | /// The float value of the property. 49 | public void Set(string key, float value) 50 | { 51 | m_FloatProperties[key] = value; 52 | using (var msgOut = new OutgoingMessage()) 53 | { 54 | msgOut.WriteString(key); 55 | msgOut.WriteFloat32(value); 56 | QueueMessageToSend(msgOut); 57 | } 58 | 59 | Action action; 60 | m_RegisteredActions.TryGetValue(key, out action); 61 | action?.Invoke(value); 62 | } 63 | 64 | /// 65 | /// Get an Environment property with a default value. If there is a value for this property, 66 | /// it will be returned, otherwise, the default value will be returned. 67 | /// 68 | /// The string identifier of the property. 69 | /// The default value of the property. 70 | /// 71 | public float GetWithDefault(string key, float defaultValue) 72 | { 73 | float valueOut; 74 | bool hasKey = m_FloatProperties.TryGetValue(key, out valueOut); 75 | return hasKey ? valueOut : defaultValue; 76 | } 77 | 78 | /// 79 | /// Registers an action to be performed everytime the property is changed. 80 | /// 81 | /// The string identifier of the property. 82 | /// The action that ill be performed. Takes a float as input. 83 | public void RegisterCallback(string key, Action action) 84 | { 85 | m_RegisteredActions[key] = action; 86 | } 87 | 88 | /// 89 | /// Returns a list of all the string identifiers of the properties currently present. 90 | /// 91 | /// The list of string identifiers 92 | public IList Keys() 93 | { 94 | return new List(m_FloatProperties.Keys); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Runtime/SideChannels/FloatPropertiesChannel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 452f8b3c01c4642aba645dcf0b6bfc6e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/SideChannels/IncomingMessage.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.CompilerServices; 3 | using System; 4 | using System.IO; 5 | using System.Text; 6 | 7 | namespace Unity.AI.MLAgents.SideChannels 8 | { 9 | /// 10 | /// Utility class for reading the data sent to the SideChannel. 11 | /// 12 | public class IncomingMessage : IDisposable 13 | { 14 | byte[] m_Data; 15 | Stream m_Stream; 16 | BinaryReader m_Reader; 17 | 18 | /// 19 | /// Construct an IncomingMessage from the byte array. 20 | /// 21 | /// 22 | public IncomingMessage(byte[] data) 23 | { 24 | m_Data = data; 25 | m_Stream = new MemoryStream(data); 26 | m_Reader = new BinaryReader(m_Stream); 27 | } 28 | 29 | /// 30 | /// Read a boolean value from the message. 31 | /// 32 | /// Default value to use if the end of the message is reached. 33 | /// 34 | public bool ReadBoolean(bool defaultValue = false) 35 | { 36 | return CanReadMore() ? m_Reader.ReadBoolean() : defaultValue; 37 | } 38 | 39 | /// 40 | /// Read an integer value from the message. 41 | /// 42 | /// Default value to use if the end of the message is reached. 43 | /// 44 | public int ReadInt32(int defaultValue = 0) 45 | { 46 | return CanReadMore() ? m_Reader.ReadInt32() : defaultValue; 47 | } 48 | 49 | /// 50 | /// Read a float value from the message. 51 | /// 52 | /// Default value to use if the end of the message is reached. 53 | /// 54 | public float ReadFloat32(float defaultValue = 0.0f) 55 | { 56 | return CanReadMore() ? m_Reader.ReadSingle() : defaultValue; 57 | } 58 | 59 | /// 60 | /// Read a string value from the message. 61 | /// 62 | /// Default value to use if the end of the message is reached. 63 | /// 64 | public string ReadString(string defaultValue = default) 65 | { 66 | if (!CanReadMore()) 67 | { 68 | return defaultValue; 69 | } 70 | 71 | var strLength = ReadInt32(); 72 | var str = Encoding.ASCII.GetString(m_Reader.ReadBytes(strLength)); 73 | return str; 74 | } 75 | 76 | /// 77 | /// Reads a list of floats from the message. The length of the list is stored in the message. 78 | /// 79 | /// Default value to use if the end of the message is reached. 80 | /// 81 | public IList ReadFloatList(IList defaultValue = default) 82 | { 83 | if (!CanReadMore()) 84 | { 85 | return defaultValue; 86 | } 87 | 88 | var len = ReadInt32(); 89 | var output = new float[len]; 90 | for (var i = 0; i < len; i++) 91 | { 92 | output[i] = ReadFloat32(); 93 | } 94 | 95 | return output; 96 | } 97 | 98 | /// 99 | /// Gets the original data of the message. Note that this will return all of the data, 100 | /// even if part of it has already been read. 101 | /// 102 | /// 103 | public byte[] GetRawBytes() 104 | { 105 | return m_Data; 106 | } 107 | 108 | /// 109 | /// Clean up the internal storage. 110 | /// 111 | public void Dispose() 112 | { 113 | m_Reader?.Dispose(); 114 | m_Stream?.Dispose(); 115 | } 116 | 117 | /// 118 | /// Whether or not there is more data left in the stream that can be read. 119 | /// 120 | /// 121 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 122 | bool CanReadMore() 123 | { 124 | return m_Stream.Position < m_Stream.Length; 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Runtime/SideChannels/IncomingMessage.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8043cec65aeb4ec09db1d25ad694328 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/SideChannels/OutgoingMessage.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace Unity.AI.MLAgents.SideChannels 7 | { 8 | /// 9 | /// Utility class for forming the data that is sent to the SideChannel. 10 | /// 11 | public class OutgoingMessage : IDisposable 12 | { 13 | BinaryWriter m_Writer; 14 | MemoryStream m_Stream; 15 | 16 | /// 17 | /// Create a new empty OutgoingMessage. 18 | /// 19 | public OutgoingMessage() 20 | { 21 | m_Stream = new MemoryStream(); 22 | m_Writer = new BinaryWriter(m_Stream); 23 | } 24 | 25 | /// 26 | /// Clean up the internal storage. 27 | /// 28 | public void Dispose() 29 | { 30 | m_Writer?.Dispose(); 31 | m_Stream?.Dispose(); 32 | } 33 | 34 | /// 35 | /// Write a boolean value to the message. 36 | /// 37 | /// 38 | public void WriteBoolean(bool b) 39 | { 40 | m_Writer.Write(b); 41 | } 42 | 43 | /// 44 | /// Write an interger value to the message. 45 | /// 46 | /// 47 | public void WriteInt32(int i) 48 | { 49 | m_Writer.Write(i); 50 | } 51 | 52 | /// 53 | /// Write a float values to the message. 54 | /// 55 | /// 56 | public void WriteFloat32(float f) 57 | { 58 | m_Writer.Write(f); 59 | } 60 | 61 | /// 62 | /// Write a string value to the message. 63 | /// 64 | /// 65 | public void WriteString(string s) 66 | { 67 | var stringEncoded = Encoding.ASCII.GetBytes(s); 68 | m_Writer.Write(stringEncoded.Length); 69 | m_Writer.Write(stringEncoded); 70 | } 71 | 72 | /// 73 | /// Write a list or array of floats to the message. 74 | /// 75 | /// 76 | public void WriteFloatList(IList floatList) 77 | { 78 | WriteInt32(floatList.Count); 79 | foreach (var f in floatList) 80 | { 81 | WriteFloat32(f); 82 | } 83 | } 84 | 85 | /// 86 | /// Overwrite the message with a specific byte array. 87 | /// 88 | /// 89 | public void SetRawBytes(byte[] data) 90 | { 91 | // Reset first. Set the length to zero so that if there's more data than we're going to 92 | // write, we don't have any of the original data. 93 | m_Stream.Seek(0, SeekOrigin.Begin); 94 | m_Stream.SetLength(0); 95 | 96 | // Then append the data. Increase the capacity if needed (but don't shrink it). 97 | m_Stream.Capacity = (m_Stream.Capacity < data.Length) ? data.Length : m_Stream.Capacity; 98 | m_Stream.Write(data, 0, data.Length); 99 | } 100 | 101 | /// 102 | /// Read the byte array of the message. 103 | /// 104 | /// 105 | internal byte[] ToByteArray() 106 | { 107 | return m_Stream.ToArray(); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Runtime/SideChannels/OutgoingMessage.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a007135a9a1e49849eb2d295f4c3879 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/SideChannels/RawBytesChannel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | 4 | namespace Unity.AI.MLAgents.SideChannels 5 | { 6 | /// 7 | /// Side channel for managing raw bytes of data. It is up to the clients of this side channel 8 | /// to interpret the messages. 9 | /// 10 | public class RawBytesChannel : SideChannel 11 | { 12 | List m_MessagesReceived = new List(); 13 | 14 | /// 15 | /// RawBytesChannel provides a way to exchange raw byte arrays between Unity and Python. 16 | /// 17 | /// The identifier for the RawBytesChannel. Must be 18 | /// the same on Python and Unity. 19 | public RawBytesChannel(Guid channelId) 20 | { 21 | ChannelId = channelId; 22 | } 23 | 24 | /// 25 | protected override void OnMessageReceived(IncomingMessage msg) 26 | { 27 | m_MessagesReceived.Add(msg.GetRawBytes()); 28 | } 29 | 30 | /// 31 | /// Sends the byte array message to the Python side channel. The message will be sent 32 | /// alongside the simulation step. 33 | /// 34 | /// The byte array of data to send to Python. 35 | public void SendRawBytes(byte[] data) 36 | { 37 | using (var msg = new OutgoingMessage()) 38 | { 39 | msg.SetRawBytes(data); 40 | QueueMessageToSend(msg); 41 | } 42 | } 43 | 44 | /// 45 | /// Gets the messages that were sent by python since the last call to 46 | /// GetAndClearReceivedMessages. 47 | /// 48 | /// a list of byte array messages that Python has sent. 49 | public IList GetAndClearReceivedMessages() 50 | { 51 | var result = new List(); 52 | result.AddRange(m_MessagesReceived); 53 | m_MessagesReceived.Clear(); 54 | return result; 55 | } 56 | 57 | /// 58 | /// Gets the messages that were sent by python since the last call to 59 | /// GetAndClearReceivedMessages. Note that the messages received will not 60 | /// be cleared with a call to GetReceivedMessages. 61 | /// 62 | /// a list of byte array messages that Python has sent. 63 | public IList GetReceivedMessages() 64 | { 65 | var result = new List(); 66 | result.AddRange(m_MessagesReceived); 67 | return result; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Runtime/SideChannels/RawBytesChannel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40b01e9cdbfd94865b54ebeb4e5aeaa5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/SideChannels/SideChannel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | 4 | namespace Unity.AI.MLAgents.SideChannels 5 | { 6 | /// 7 | /// Side channels provide an alternative mechanism of sending/receiving data from Unity 8 | /// to Python that is outside of the traditional machine learning loop. ML-Agents provides 9 | /// some specific implementations of side channels, but users can create their own. 10 | /// 11 | /// To create your own, you'll need to create two, new mirrored classes, one in Unity (by 12 | /// extending ) and another in Python by extending a Python class 13 | /// also called SideChannel. Then, within your project, use 14 | /// and 15 | /// to register and unregister your 16 | /// custom side channel. 17 | /// 18 | public abstract class SideChannel 19 | { 20 | // The list of messages (byte arrays) that need to be sent to Python via the communicator. 21 | // Should only ever be read and cleared by a ICommunicator object. 22 | internal List MessageQueue = new List(); 23 | 24 | /// 25 | /// An int identifier for the SideChannel. Ensures that there is only ever one side channel 26 | /// of each type. Ensure the Unity side channels will be linked to their Python equivalent. 27 | /// 28 | /// The integer identifier of the SideChannel. 29 | public Guid ChannelId 30 | { 31 | get; 32 | protected set; 33 | } 34 | 35 | internal void ProcessMessage(byte[] msg) 36 | { 37 | using (var incomingMsg = new IncomingMessage(msg)) 38 | { 39 | OnMessageReceived(incomingMsg); 40 | } 41 | } 42 | 43 | /// 44 | /// Is called by the communicator every time a message is received from Python by the SideChannel. 45 | /// Can be called multiple times per simulation step if multiple messages were sent. 46 | /// 47 | /// The incoming message. 48 | protected abstract void OnMessageReceived(IncomingMessage msg); 49 | 50 | /// 51 | /// Queues a message to be sent to Python during the next simulation step. 52 | /// 53 | /// The byte array of data to be sent to Python. 54 | protected void QueueMessageToSend(OutgoingMessage msg) 55 | { 56 | MessageQueue.Add(msg.ToByteArray()); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Runtime/SideChannels/SideChannel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 77b7d19dd6ce343eeba907540b5a2286 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/SideChannels/SideChannelsManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ccc0d134445f947349c68a6d07e3cdc2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/SideChannels/StatsSideChannel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Unity.AI.MLAgents.SideChannels 3 | { 4 | /// 5 | /// A Side Channel for sending data. 6 | /// 7 | internal class StatsSideChannel : SideChannel 8 | { 9 | const string k_StatsSideChannelDefaultId = "a1d8f7b7-cec8-50f9-b78b-d3e165a78520"; 10 | 11 | /// 12 | /// Initializes the side channel. The constructor is internal because only one instance is 13 | /// supported at a time. 14 | /// 15 | internal StatsSideChannel() 16 | { 17 | ChannelId = new Guid(k_StatsSideChannelDefaultId); 18 | } 19 | 20 | /// 21 | /// Add a stat value for reporting. 22 | /// 23 | /// The stat name. 24 | /// The stat value. 25 | /// How multiple values should be treated. 26 | public void AddStat(string key, float value, StatAggregationMethod aggregationMethod) 27 | { 28 | using (var msg = new OutgoingMessage()) 29 | { 30 | msg.WriteString(key); 31 | msg.WriteFloat32(value); 32 | msg.WriteInt32((int)aggregationMethod); 33 | QueueMessageToSend(msg); 34 | } 35 | } 36 | 37 | /// 38 | protected override void OnMessageReceived(IncomingMessage msg) 39 | { 40 | throw new MLAgentsException("StatsSideChannel should never receive messages."); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Runtime/SideChannels/StatsSideChannel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 83a07fdb9e8f04536908a51447dfe548 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/StatsRecorder.cs: -------------------------------------------------------------------------------- 1 | using Unity.AI.MLAgents.SideChannels; 2 | 3 | namespace Unity.AI.MLAgents 4 | { 5 | /// 6 | /// Determines the behavior of how multiple stats within the same summary period are combined. 7 | /// 8 | public enum StatAggregationMethod 9 | { 10 | /// 11 | /// Values within the summary period are averaged before reporting. 12 | /// Note that values from the same C# environment in the same step may replace each other. 13 | /// 14 | Average = 0, 15 | 16 | /// 17 | /// Only the most recent value is reported. 18 | /// To avoid conflicts when training with multiple concurrent environments, only 19 | /// stats from worker index 0 will be tracked. 20 | /// 21 | MostRecent = 1 22 | } 23 | 24 | /// 25 | /// Add stats (key-value pairs) for reporting. These values will sent these to a StatsReporter 26 | /// instance, which means the values will appear in the TensorBoard summary, as well as trainer 27 | /// gauges. You can nest stats in TensorBoard by adding "/" in the name (e.g. "Agent/Health" 28 | /// and "Agent/Wallet"). Note that stats are only written to TensorBoard each summary_frequency 29 | /// steps (a trainer configuration). If a stat is received multiple times, within that period 30 | /// then the values will be aggregated using the provided. 31 | /// 32 | public sealed class StatsRecorder 33 | { 34 | /// 35 | /// The side channel that is used to receive the new parameter values. 36 | /// 37 | readonly StatsSideChannel m_Channel; 38 | 39 | /// 40 | /// Constructor. 41 | /// 42 | internal StatsRecorder() 43 | { 44 | m_Channel = new StatsSideChannel(); 45 | SideChannelManager.RegisterSideChannel(m_Channel); 46 | } 47 | 48 | /// 49 | /// Add a stat value for reporting. 50 | /// 51 | /// The stat name. 52 | /// 53 | /// The stat value. You can nest stats in TensorBoard by using "/". 54 | /// 55 | /// 56 | /// How multiple values sent in the same summary window should be treated. 57 | /// 58 | public void Add( 59 | string key, 60 | float value, 61 | StatAggregationMethod aggregationMethod = StatAggregationMethod.Average) 62 | { 63 | m_Channel.AddStat(key, value, aggregationMethod); 64 | } 65 | 66 | internal void Dispose() 67 | { 68 | SideChannelManager.UnregisterSideChannel(m_Channel); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Runtime/StatsRecorder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d532c153975b42a1a1b0fb322ccd79b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/TimeUtils.cs: -------------------------------------------------------------------------------- 1 | using Unity.Entities; 2 | using Unity.Core; 3 | 4 | namespace Unity.AI.MLAgents 5 | { 6 | public static class TimeUtils 7 | { 8 | /// 9 | /// Configure the given ComponentSystemGroup to update at a fixed timestep, given by timeStep. 10 | /// The group will be updated multiple times. 11 | /// 12 | /// The group whose UpdateCallback will be configured with a fixed time step update call 13 | /// The fixed time step (in seconds) 14 | /// How many times the system will be updated per updates 15 | public static void EnableFixedRateWithRepeat(ComponentSystemGroup group, float timeStep, int numberOfRepeat) 16 | { 17 | var manager = new FixedRateRepeatManager(timeStep, numberOfRepeat); 18 | group.FixedRateManager = manager; 19 | } 20 | 21 | /// 22 | /// Disable fixed rate updates on the given group, by setting the UpdateCallback to null. 23 | /// 24 | /// The group whose UpdateCallback to set to null. 25 | public static void DisableFixedRate(ComponentSystemGroup group) 26 | { 27 | group.FixedRateManager = null; 28 | } 29 | } 30 | 31 | internal class FixedRateRepeatManager : IFixedRateManager 32 | { 33 | protected int m_NumberOfRepeat; 34 | protected int m_CurrentRepeat; 35 | protected float m_FixedTimeStep; 36 | protected double m_LastFixedUpdateTime; 37 | protected int m_FixedUpdateCount; 38 | protected bool m_DidPushTime; 39 | 40 | internal FixedRateRepeatManager(float fixedStep, int numberOfRepeat) 41 | { 42 | m_FixedTimeStep = fixedStep; 43 | m_NumberOfRepeat = numberOfRepeat; 44 | m_CurrentRepeat = 0; 45 | } 46 | 47 | public float Timestep 48 | { 49 | get { return m_FixedTimeStep; } 50 | set { m_FixedTimeStep = value; } 51 | } 52 | 53 | public bool ShouldGroupUpdate(ComponentSystemGroup group) 54 | { 55 | // if this is true, means we're being called a second or later time in a loop 56 | if (m_DidPushTime) 57 | { 58 | group.World.PopTime(); 59 | } 60 | 61 | var elapsedTime = group.World.Time.ElapsedTime; 62 | if (m_LastFixedUpdateTime == 0.0) 63 | m_LastFixedUpdateTime = elapsedTime - m_FixedTimeStep; 64 | 65 | if (m_CurrentRepeat < m_NumberOfRepeat) 66 | { 67 | // Note that m_FixedTimeStep of 0.0f will never update 68 | m_LastFixedUpdateTime += m_FixedTimeStep; 69 | m_FixedUpdateCount++; 70 | m_CurrentRepeat++; 71 | } 72 | else 73 | { 74 | m_CurrentRepeat = 0; 75 | m_DidPushTime = false; 76 | return false; 77 | } 78 | 79 | group.World.PushTime(new TimeData( 80 | elapsedTime: m_LastFixedUpdateTime, 81 | deltaTime: m_FixedTimeStep)); 82 | 83 | m_DidPushTime = true; 84 | return true; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Runtime/TimeUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 839be50520a14428a8ab3158fc8a00c2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/UI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a35da4016e5b462490817452ec230e6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/UI/PolicySpecs.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 129c8e71a2ae643e895432d018242474 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Unity.AI.MLAgents.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.AI.MLAgents", 3 | "references": [ 4 | "Unity.Entities", 5 | "Unity.Jobs", 6 | "Unity.Mathematics", 7 | "Unity.Collections", 8 | "Unity.Barracuda" 9 | ], 10 | "includePlatforms": [], 11 | "excludePlatforms": [], 12 | "allowUnsafeCode": true, 13 | "overrideReferences": false, 14 | "precompiledReferences": [], 15 | "autoReferenced": true, 16 | "defineConstraints": [], 17 | "versionDefines": [], 18 | "noEngineReferences": false 19 | } -------------------------------------------------------------------------------- /Runtime/Unity.AI.MLAgents.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b11ccf19319f4aaab7ffaaec3247df6 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Visual.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 90fd5f19c82c347a390f96c71f2a79ad 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Visual/VisualObservationUtility.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using UnityEngine; 3 | 4 | namespace Unity.AI.MLAgents 5 | { 6 | public static class VisualObservationUtility 7 | { 8 | /// 9 | /// Generates a NativeArray of floats corresponding to the camera's visual input. 10 | /// The Array will be of total size ( height x width x 3 ) 11 | /// Each pixel will correspond to three consecutive floats in the order [red, green, blue] 12 | /// 13 | /// The camera used to collect the visual data 14 | /// The width of the generated image 15 | /// The height of the generated image 16 | /// the Allocator for the Native array 17 | /// A native array of floats containing the image data from the camera 18 | public static NativeArray GetVisObs(Camera camera, int width, int height, Allocator allocator = Allocator.Temp) 19 | { 20 | if (camera != null) 21 | { 22 | var texture = ObservationToTexture(camera, width, height); 23 | return TextureToNativeArray(texture, allocator); 24 | } 25 | return new NativeArray(0, allocator, NativeArrayOptions.ClearMemory); 26 | } 27 | 28 | private static NativeArray TextureToNativeArray(Texture2D texture, Allocator allocator) 29 | { 30 | var width = texture.width; 31 | var height = texture.height; 32 | var arr = new NativeArray(width * height * 3, allocator, NativeArrayOptions.UninitializedMemory); 33 | 34 | var texturePixels = texture.GetPixels32(); 35 | for (var h = height - 1; h >= 0; h--) 36 | { 37 | for (var w = 0; w < width; w++) 38 | { 39 | var currentPixel = texturePixels[(height - h - 1) * width + w]; 40 | // For Color32, the r, g and b values are between 0 and 255. 41 | arr[h * width * 3 + w * 3 + 0] = currentPixel.r / 255.0f; 42 | arr[h * width * 3 + w * 3 + 1] = currentPixel.g / 255.0f; 43 | arr[h * width * 3 + w * 3 + 2] = currentPixel.b / 255.0f; 44 | } 45 | } 46 | return arr; 47 | } 48 | 49 | private static Texture2D ObservationToTexture(Camera obsCamera, int width, int height) 50 | { 51 | var texture2D = new Texture2D(width, height, TextureFormat.RGB24, false); 52 | var oldRec = obsCamera.rect; 53 | obsCamera.rect = new Rect(0f, 0f, 1f, 1f); 54 | var depth = 24; 55 | var format = RenderTextureFormat.Default; 56 | var readWrite = RenderTextureReadWrite.Default; 57 | 58 | var tempRt = 59 | RenderTexture.GetTemporary(width, height, depth, format, readWrite); 60 | 61 | var prevActiveRt = RenderTexture.active; 62 | var prevCameraRt = obsCamera.targetTexture; 63 | 64 | // render to offscreen texture (readonly from CPU side) 65 | RenderTexture.active = tempRt; 66 | obsCamera.targetTexture = tempRt; 67 | 68 | obsCamera.Render(); 69 | 70 | texture2D.ReadPixels(new Rect(0, 0, texture2D.width, texture2D.height), 0, 0); 71 | 72 | obsCamera.targetTexture = prevCameraRt; 73 | obsCamera.rect = oldRec; 74 | RenderTexture.active = prevActiveRt; 75 | RenderTexture.ReleaseTemporary(tempRt); 76 | return texture2D; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Runtime/Visual/VisualObservationUtility.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91d7dc81f3a824e67ac77a4b3b1d22d3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/3DBall.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 12a2249bd238b47a6b934f635430c208 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/3DBall/NNModels.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b664b43d47fd8448db10f18f0f3ebaa0 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/3DBall/NNModels/3DBall.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/ml-agents-dots/75d2e493822d5bb3da7a8713c50b61ab90fcfe7b/Samples~/3DBall/NNModels/3DBall.onnx -------------------------------------------------------------------------------- /Samples~/3DBall/NNModels/3DBall.onnx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c8a4864432694d5abde4f7e947aafe9 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3} 11 | optimizeModel: 1 12 | forceArbitraryBatchSize: 1 13 | treatErrorsAsWarnings: 0 14 | importMode: 1 15 | -------------------------------------------------------------------------------- /Samples~/3DBall/Prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8cca7bdec2c144e4a82ea8014145f00f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/3DBall/Prefab/AgentBlue.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: AgentBlue 11 | m_Shader: {fileID: 47, guid: 0000000000000000f000000000000000, type: 0} 12 | m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 0 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | - _SpecGlossMap: 59 | m_Texture: {fileID: 0} 60 | m_Scale: {x: 1, y: 1} 61 | m_Offset: {x: 0, y: 0} 62 | m_Floats: 63 | - _BumpScale: 1 64 | - _Cutoff: 0.5 65 | - _DetailNormalMapScale: 1 66 | - _DstBlend: 0 67 | - _GlossMapScale: 1 68 | - _Glossiness: 0.5 69 | - _GlossyReflections: 0 70 | - _Metallic: 0 71 | - _Mode: 0 72 | - _OcclusionStrength: 1 73 | - _Parallax: 0.02 74 | - _SmoothnessTextureChannel: 0 75 | - _SpecularHighlights: 0 76 | - _SrcBlend: 1 77 | - _UVSec: 0 78 | - _ZWrite: 1 79 | m_Colors: 80 | - _Color: {r: 0.12941177, g: 0.5882353, b: 0.9529412, a: 1} 81 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 82 | -------------------------------------------------------------------------------- /Samples~/3DBall/Prefab/AgentBlue.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 33f0f679cefac4390a9d0b8e37b09f18 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/3DBall/Prefab/Ball.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 46c9069f688754349bdfc97d56ac7968 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples~/3DBall/Prefab/CheckersGray_BC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/ml-agents-dots/75d2e493822d5bb3da7a8713c50b61ab90fcfe7b/Samples~/3DBall/Prefab/CheckersGray_BC.png -------------------------------------------------------------------------------- /Samples~/3DBall/Prefab/CheckersGray_BC.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce9b138d9fc6a4451aeb0b8f911cc314 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 10 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 3 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | forceMaximumCompressionQuality_BC6H_BC7: 0 73 | spriteSheet: 74 | serializedVersion: 2 75 | sprites: [] 76 | outline: [] 77 | physicsShape: [] 78 | bones: [] 79 | spriteID: 80 | internalID: 0 81 | vertices: [] 82 | indices: 83 | edges: [] 84 | weights: [] 85 | secondaryTextures: [] 86 | spritePackingTag: 87 | pSDRemoveMatte: 0 88 | pSDShowRemoveMatteOption: 0 89 | userData: 90 | assetBundleName: 91 | assetBundleVariant: 92 | -------------------------------------------------------------------------------- /Samples~/3DBall/Prefab/Checkers_Ball.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: Checkers_Ball 11 | m_Shader: {fileID: 47, guid: 0000000000000000f000000000000000, type: 0} 12 | m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 0 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 2, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 2800000, guid: ce9b138d9fc6a4451aeb0b8f911cc314, type: 3} 44 | m_Scale: {x: 2, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | - _SpecGlossMap: 59 | m_Texture: {fileID: 0} 60 | m_Scale: {x: 1, y: 1} 61 | m_Offset: {x: 0, y: 0} 62 | m_Floats: 63 | - _BumpScale: 1 64 | - _Cutoff: 0.5 65 | - _DetailNormalMapScale: 1 66 | - _DstBlend: 0 67 | - _GlossMapScale: 1 68 | - _Glossiness: 0.5 69 | - _GlossyReflections: 0 70 | - _Metallic: 0 71 | - _Mode: 0 72 | - _OcclusionStrength: 1 73 | - _Parallax: 0.02 74 | - _SmoothnessTextureChannel: 0 75 | - _SpecularHighlights: 0 76 | - _SrcBlend: 1 77 | - _UVSec: 0 78 | - _ZWrite: 1 79 | m_Colors: 80 | - _Color: {r: 1, g: 1, b: 1, a: 1} 81 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 82 | -------------------------------------------------------------------------------- /Samples~/3DBall/Prefab/Checkers_Ball.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad75f7e658dba41d7bdc89f031d25aee 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/3DBall/Prefab/Platform.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c9aecd39f81f4a2d91dfebe7c29b81f 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples~/3DBall/Scene.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3931a85b5b679449da7a25e5403c15bd 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/3DBall/Scene/3DBall.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eddd1cf2ae96b477a845d33c13b39a6f 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples~/3DBall/Script.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec3f80a578a584bd8985f83ff16caac4 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/3DBall/Script/BalanceBallManager.cs: -------------------------------------------------------------------------------- 1 | using Unity.Entities; 2 | using Unity.Collections; 3 | using Unity.Mathematics; 4 | using Unity.Transforms; 5 | using UnityEngine; 6 | using Random = UnityEngine.Random; 7 | using Unity.AI.MLAgents; 8 | 9 | public class BalanceBallManager : MonoBehaviour 10 | { 11 | public PolicySpecs MyPolicySpecs; 12 | 13 | public int NumberBalls = 1000; 14 | 15 | private EntityManager manager; 16 | public GameObject prefabPlatform; 17 | public GameObject prefabBall; 18 | private Entity _prefabEntityPlatform; 19 | private Entity _prefabEntityBall; 20 | int currentIndex; 21 | 22 | NativeArray entitiesP; 23 | NativeArray entitiesB; 24 | BlobAssetStore blob; 25 | 26 | 27 | void Awake() 28 | { 29 | var policy = MyPolicySpecs.GetPolicy(); 30 | var ballSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem(); 31 | ballSystem.Enabled = true; 32 | ballSystem.BallPolicy = policy; 33 | 34 | manager = World.DefaultGameObjectInjectionWorld.EntityManager; 35 | 36 | blob = new BlobAssetStore(); 37 | GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blob); 38 | _prefabEntityPlatform = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefabPlatform, settings); 39 | _prefabEntityBall = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefabBall, settings); 40 | 41 | Spawn(NumberBalls); 42 | 43 | Academy.Instance.OnEnvironmentReset = () => 44 | { 45 | foreach(Entity e in entitiesP) 46 | { 47 | manager.DestroyEntity(e); 48 | } 49 | entitiesP.Dispose(); 50 | foreach(Entity e in entitiesB) 51 | { 52 | manager.DestroyEntity(e); 53 | } 54 | entitiesB.Dispose(); 55 | Spawn(NumberBalls); 56 | }; 57 | 58 | } 59 | 60 | void Spawn(int amount) 61 | { 62 | entitiesP = new NativeArray(amount, Allocator.Persistent); 63 | entitiesB = new NativeArray(amount, Allocator.Persistent); 64 | manager.Instantiate(_prefabEntityPlatform, entitiesP); 65 | manager.Instantiate(_prefabEntityBall, entitiesB); 66 | for (int i = 0; i < amount; i++) 67 | { 68 | float3 position = new float3((currentIndex % 10) - 5, (currentIndex / 10 % 10) - 5, currentIndex / 100) * 5f; 69 | float valX = Random.Range(-0.1f, 0.1f); 70 | float valZ = Random.Range(-0.1f, 0.1f); 71 | manager.SetComponentData(entitiesP[i], 72 | new Translation 73 | { 74 | Value = position 75 | }); 76 | manager.SetComponentData(entitiesB[i], 77 | new Translation 78 | { 79 | Value = position + new float3(0, 0.2f, 0) 80 | }); 81 | 82 | manager.SetComponentData(entitiesP[i], 83 | new Rotation 84 | { 85 | Value = quaternion.EulerXYZ(valX, 0, valZ) 86 | }); 87 | manager.AddComponent(entitiesP[i]); 88 | manager.SetComponentData(entitiesP[i], new AgentData { 89 | BallResetPosition = position + new float3(0, 0.2f, 0), 90 | BallRef = entitiesB[i], 91 | StepCount = 0 92 | }); 93 | manager.AddComponent(entitiesP[i]); 94 | currentIndex++; 95 | } 96 | currentIndex = 0; 97 | } 98 | 99 | void OnDestroy() 100 | { 101 | entitiesP.Dispose(); 102 | entitiesB.Dispose(); 103 | blob.Dispose(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Samples~/3DBall/Script/BalanceBallManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 99c8505fda4844b5b8a9505d069fdd8c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/3DBall/Script/BallSystem.cs: -------------------------------------------------------------------------------- 1 | using Unity.Entities; 2 | using Unity.Jobs; 3 | using Unity.Mathematics; 4 | using Unity.Transforms; 5 | using Unity.AI.MLAgents; 6 | using Unity.Collections; 7 | using Unity.Physics; 8 | 9 | 10 | public struct AgentData : IComponentData 11 | { 12 | public float3 BallResetPosition; 13 | public Entity BallRef; 14 | public int StepCount; 15 | } 16 | 17 | public struct Actuator : IComponentData 18 | { 19 | public float2 Value; 20 | } 21 | 22 | public class BallSystem : JobComponentSystem 23 | { 24 | private const int maxStep = 1000; 25 | private const int decisionPeriod = 5; 26 | private int stepIndex = 0; 27 | 28 | private struct RotateJob : IActuatorJob 29 | { 30 | public ComponentDataFromEntity ComponentDataFromEntity; 31 | public void Execute(ActuatorEvent ev) 32 | { 33 | var a = ev.GetContinuousAction(); 34 | ComponentDataFromEntity[ev.Entity] = a; 35 | } 36 | } 37 | 38 | public Policy BallPolicy; 39 | 40 | 41 | // Update is called once per frame 42 | protected override JobHandle OnUpdate(JobHandle inputDeps) 43 | { 44 | 45 | if (!BallPolicy.IsCreated){ 46 | return inputDeps; 47 | } 48 | stepIndex++; 49 | if (stepIndex % decisionPeriod == 0) 50 | { 51 | return inputDeps; 52 | } 53 | 54 | var policy = BallPolicy; 55 | 56 | ComponentDataFromEntity TranslationFromEntity = GetComponentDataFromEntity(isReadOnly: false); 57 | ComponentDataFromEntity VelFromEntity = GetComponentDataFromEntity(isReadOnly: false); 58 | inputDeps = Entities 59 | .WithNativeDisableParallelForRestriction(TranslationFromEntity) 60 | .WithNativeDisableParallelForRestriction(VelFromEntity) 61 | .ForEach((Entity entity, ref Rotation rot, ref AgentData agentData) => 62 | { 63 | 64 | var ballPos = TranslationFromEntity[agentData.BallRef].Value; 65 | var ballVel = VelFromEntity[agentData.BallRef].Linear; 66 | var platformVel = VelFromEntity[entity]; 67 | bool taskFailed = false; 68 | bool interruption = false; 69 | if (ballPos.y - agentData.BallResetPosition.y < -0.7f) 70 | { 71 | taskFailed = true; 72 | agentData.StepCount = 0; 73 | } 74 | if (agentData.StepCount > maxStep) 75 | { 76 | interruption = true; 77 | agentData.StepCount = 0; 78 | } 79 | if (!interruption && !taskFailed) 80 | { 81 | policy.RequestDecision(entity) 82 | .SetObservation(0, rot.Value) 83 | .SetObservation(1, ballPos - agentData.BallResetPosition) 84 | .SetObservation(2, ballVel) 85 | .SetObservation(3, platformVel.Angular) 86 | .SetReward((0.1f)); 87 | } 88 | if (taskFailed) 89 | { 90 | policy.EndEpisode(entity) 91 | .SetObservation(0, rot.Value) 92 | .SetObservation(1, ballPos - agentData.BallResetPosition) 93 | .SetObservation(2, ballVel) 94 | .SetObservation(3, platformVel.Angular) 95 | .SetReward(-1f); 96 | } 97 | else if (interruption) 98 | { 99 | policy.InterruptEpisode(entity) 100 | .SetObservation(0, rot.Value) 101 | .SetObservation(1, ballPos - agentData.BallResetPosition) 102 | .SetObservation(2, ballVel) 103 | .SetObservation(3, platformVel.Angular) 104 | .SetReward((0.1f)); 105 | } 106 | if (interruption || taskFailed) 107 | { 108 | VelFromEntity[agentData.BallRef] = new PhysicsVelocity(); 109 | TranslationFromEntity[agentData.BallRef] = new Translation { Value = agentData.BallResetPosition }; 110 | rot.Value = quaternion.identity; 111 | } 112 | agentData.StepCount++; 113 | 114 | }).Schedule(inputDeps); 115 | 116 | var reactiveJob = new RotateJob 117 | { 118 | ComponentDataFromEntity = GetComponentDataFromEntity(isReadOnly: false) 119 | }; 120 | inputDeps = reactiveJob.Schedule(policy, inputDeps); 121 | 122 | inputDeps = Entities.ForEach((ref Actuator act, ref Rotation rotation) => 123 | { 124 | var rot = math.mul(rotation.Value, quaternion.Euler(0.05f * new float3(act.Value.x, 0, act.Value.y))); 125 | rotation.Value = rot; 126 | }).Schedule(inputDeps); 127 | 128 | return inputDeps; 129 | } 130 | 131 | protected override void OnDestroy() 132 | { 133 | BallPolicy.Dispose(); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /Samples~/3DBall/Script/BallSystem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1ba9999f5aec492781540b10a9ab8f0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/3DBall/Script/CameraMovement.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class CameraMovement : MonoBehaviour 6 | { 7 | private Vector3 startPosition; 8 | [Range(0,100)] 9 | public float slider = 0f; 10 | public float slide_max = 80; 11 | public bool move; 12 | private float delta; 13 | // Start is called before the first frame update 14 | void Start() 15 | { 16 | startPosition = transform.position; 17 | } 18 | 19 | // Update is called once per frame 20 | void Update() 21 | { 22 | transform.position = startPosition + slider * new Vector3(-1, 1, -1); 23 | if (move) 24 | { 25 | slider += delta; 26 | if (slider < slide_max) 27 | { 28 | delta += 0.001f; 29 | delta = Mathf.Min(delta, 0.1f); 30 | } 31 | else 32 | { 33 | delta -= 0.001f; 34 | delta = Mathf.Max(delta, 0f); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Samples~/3DBall/Script/CameraMovement.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed23ff8a527af4aabb6097c5c6f09b52 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/Basic.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b72621d7b1c954759b39bb937e1de892 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/NNModels.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00df137c606b940009c15e4dedbd5ec3 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/NNModels/Basic.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/ml-agents-dots/75d2e493822d5bb3da7a8713c50b61ab90fcfe7b/Samples~/Basic/NNModels/Basic.onnx -------------------------------------------------------------------------------- /Samples~/Basic/NNModels/Basic.onnx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01fce3502cfd844588e26966f46bd378 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3} 11 | optimizeModel: 1 12 | forceArbitraryBatchSize: 1 13 | treatErrorsAsWarnings: 0 14 | importMode: 1 15 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2a567984dd3bf486c8e395388ea79a4f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/AgentBlue.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: AgentBlue 10 | m_Shader: {fileID: 47, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | - _SpecGlossMap: 58 | m_Texture: {fileID: 0} 59 | m_Scale: {x: 1, y: 1} 60 | m_Offset: {x: 0, y: 0} 61 | m_Floats: 62 | - _BumpScale: 1 63 | - _Cutoff: 0.5 64 | - _DetailNormalMapScale: 1 65 | - _DstBlend: 0 66 | - _GlossMapScale: 1 67 | - _Glossiness: 0.5 68 | - _GlossyReflections: 0 69 | - _Metallic: 0 70 | - _Mode: 0 71 | - _OcclusionStrength: 1 72 | - _Parallax: 0.02 73 | - _SmoothnessTextureChannel: 0 74 | - _SpecularHighlights: 0 75 | - _SrcBlend: 1 76 | - _UVSec: 0 77 | - _ZWrite: 1 78 | m_Colors: 79 | - _Color: {r: 0.12941177, g: 0.5882353, b: 0.9529412, a: 1} 80 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 81 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/AgentBlue.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c20798deaf8f43bb8d90030ed4f0914 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/Basic.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5eb289873aca4f5a8cc59c7464ab7c1 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/Black.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Black 10 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | m_Floats: 58 | - _BumpScale: 1 59 | - _Cutoff: 0.5 60 | - _DetailNormalMapScale: 1 61 | - _DstBlend: 0 62 | - _GlossMapScale: 1 63 | - _Glossiness: 0 64 | - _GlossyReflections: 1 65 | - _Metallic: 0 66 | - _Mode: 0 67 | - _OcclusionStrength: 1 68 | - _Parallax: 0.02 69 | - _SmoothnessTextureChannel: 0 70 | - _SpecularHighlights: 1 71 | - _SrcBlend: 1 72 | - _UVSec: 0 73 | - _ZWrite: 1 74 | m_Colors: 75 | - _Color: {r: 0.048, g: 0.048, b: 0.048, a: 1} 76 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 77 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/Black.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e11d8bba580449b8b3072e83e1129e9 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/Eye.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Eye 10 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: _ALPHATEST_ON _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: 2450 16 | stringTagMap: 17 | RenderType: TransparentCutout 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 10912, guid: 0000000000000000f000000000000000, type: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | m_Floats: 59 | - _BumpScale: 1 60 | - _Cutoff: 0.5 61 | - _DetailNormalMapScale: 1 62 | - _DstBlend: 0 63 | - _GlossMapScale: 1 64 | - _Glossiness: 0.5 65 | - _GlossyReflections: 0 66 | - _Metallic: 0 67 | - _Mode: 1 68 | - _OcclusionStrength: 1 69 | - _Parallax: 0.02 70 | - _SmoothnessTextureChannel: 0 71 | - _SpecularHighlights: 0 72 | - _SrcBlend: 1 73 | - _UVSec: 0 74 | - _ZWrite: 1 75 | m_Colors: 76 | - _Color: {r: 0.058823526, g: 0.058823526, b: 0.058823526, a: 1} 77 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 78 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/Eye.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3dce853bd3b804de2b51fde36713764d 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/Green.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Green 10 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | m_Floats: 58 | - _BumpScale: 1 59 | - _Cutoff: 0.5 60 | - _DetailNormalMapScale: 1 61 | - _DstBlend: 0 62 | - _GlossMapScale: 1 63 | - _Glossiness: 0.5 64 | - _GlossyReflections: 0 65 | - _Metallic: 0 66 | - _Mode: 0 67 | - _OcclusionStrength: 1 68 | - _Parallax: 0.02 69 | - _SmoothnessTextureChannel: 0 70 | - _SpecularHighlights: 0 71 | - _SrcBlend: 1 72 | - _UVSec: 0 73 | - _ZWrite: 1 74 | m_Colors: 75 | - _Color: {r: 0.40392157, g: 0.7372549, b: 0.41960785, a: 1} 76 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 77 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/Green.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf5f59aeb71624a65a29bdb02a5f182d 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/GridMatFloor.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: GridMatFloor 11 | m_Shader: {fileID: 4800000, guid: 1532902b4ade9470093a5cc101d0620b, type: 3} 12 | m_ShaderKeywords: 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 0 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | m_Floats: 59 | - _BumpScale: 1 60 | - _Cutoff: 0.5 61 | - _DetailNormalMapScale: 1 62 | - _DrawU: 1 63 | - _DrawV: 1 64 | - _DstBlend: 0 65 | - _GlossMapScale: 1 66 | - _Glossiness: 0 67 | - _GlossyReflections: 1 68 | - _GridSize: 6 69 | - _LineOffset: 0.5 70 | - _LineSize: 0.02 71 | - _Metallic: 0 72 | - _Mode: 0 73 | - _OcclusionStrength: 1 74 | - _Offset: 0 75 | - _Parallax: 0.02 76 | - _RepeatCount: 5 77 | - _SelectCell: 0 78 | - _SelectedCellX: 0 79 | - _SelectedCellY: 0 80 | - _SmoothnessTextureChannel: 0 81 | - _Spacing: 0.5 82 | - _SpecularHighlights: 1 83 | - _SrcBlend: 1 84 | - _UVSec: 0 85 | - _ZWrite: 1 86 | m_Colors: 87 | - _CellColor: {r: 0.116, g: 0.116, b: 0.116, a: 1} 88 | - _Color: {r: 0.935151, g: 0.9705882, b: 0.3282872, a: 0} 89 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 90 | - _LineColor: {r: 0.15686275, g: 0.15686275, b: 0.15686275, a: 1} 91 | - _SelectedColor: {r: 0.1586206, g: 1, b: 0, a: 1} 92 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/GridMatFloor.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c64855d2cf4740ef977b23f2780883a 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/GridPatternShader.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: upgraded instancing buffer 'Props' to new syntax. 2 | 3 | Shader "ML-Agents/GridPattern" { 4 | Properties { 5 | _LineColor ("Line Color", Color) = (1,1,1,1) 6 | _CellColor ("Cell Color", Color) = (0,0,0,0) 7 | // _SelectedColor ("Selected Color", Color) = (1,0,0,1) 8 | [PerRendererData] _MainTex ("Albedo (RGB)", 2D) = "white" {} 9 | [IntRange] _GridSize("Grid Size", Range(1,100)) = 10 10 | _LineSize("Line Size", Range(0,1)) = 0.15 11 | // [FloatRange] _LineOffset("Line Offset", Range(0,1)) = 0 12 | [IntRange] _DrawU("Draw U Toggle ( 0 = False , 1 = True )", Range(0,1)) = 1 13 | [IntRange] _DrawV("Draw V Toggle ( 0 = False , 1 = True )", Range(0,1)) = 1 14 | // [IntRange] _SelectCell("Select Cell Toggle ( 0 = False , 1 = True )", Range(0,1)) = 0.0 15 | // [IntRange] _SelectedCellX("Selected Cell X", Range(0,100)) = 0.0 16 | // [IntRange] _SelectedCellY("Selected Cell Y", Range(0,100)) = 0.0 17 | } 18 | SubShader { 19 | Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" } 20 | LOD 200 21 | 22 | 23 | CGPROGRAM 24 | // Physically based Standard lighting model, and enable shadows on all light types 25 | #pragma surface surf Standard fullforwardshadows 26 | 27 | // Use shader model 3.0 target, to get nicer looking lighting 28 | #pragma target 3.0 29 | 30 | sampler2D _MainTex; 31 | 32 | struct Input { 33 | float2 uv_MainTex; 34 | }; 35 | 36 | half _Glossiness = 0.0; 37 | half _Metallic = 0.0; 38 | float4 _LineColor; 39 | float4 _CellColor; 40 | // float4 _SelectedColor; 41 | 42 | float _GridSize; 43 | // float _LineOffset; 44 | float _LineSize; 45 | 46 | float _DrawU; 47 | float _DrawV; 48 | // float _SelectCell; 49 | // float _SelectedCellX; 50 | // float _SelectedCellY; 51 | 52 | // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. 53 | // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. 54 | // #pragma instancing_options assumeuniformscaling 55 | UNITY_INSTANCING_BUFFER_START(Props) 56 | // put more per-instance properties here 57 | UNITY_INSTANCING_BUFFER_END(Props) 58 | 59 | void surf (Input IN, inout SurfaceOutputStandard o) { 60 | // Albedo comes from a texture tinted by color 61 | 62 | float2 uv = IN.uv_MainTex; 63 | 64 | // _SelectedCellX = floor(_SelectedCellX); 65 | // _SelectedCellY = floor(_SelectedCellY); 66 | 67 | fixed4 c = float4(0.0,0.0,0.0,0.0); 68 | 69 | float brightness = 1.0; 70 | 71 | float gsize = floor(_GridSize); 72 | 73 | 74 | 75 | gsize += _LineSize; 76 | 77 | float2 id; 78 | 79 | id.x = floor(uv.x/(1.0/gsize)); 80 | // id.y = floor(uv.y/(1.0/gsize)); 81 | id.y = floor(uv.y/(1.0/gsize)); 82 | 83 | float4 color = _CellColor; 84 | brightness = _CellColor.w; 85 | 86 | // //This checks that the cell is currently selected if the Select Cell slider is set to 1 ( True ) 87 | // if (round(_SelectCell) == 1.0 && id.x == _SelectedCellX && id.y == _SelectedCellY) 88 | // { 89 | // brightness = _SelectedColor.w; 90 | // color = _SelectedColor; 91 | // } 92 | 93 | // if (frac(uv.x*gsize) <= _LineSize || frac(uv.y*gsize) <= _LineSize) 94 | // { 95 | // brightness = _LineColor.w; 96 | // color = _LineColor; 97 | // } 98 | if(round(_DrawU) == 1.0) 99 | { 100 | if (frac(uv.x*gsize) <= _LineSize) 101 | { 102 | // if (frac(uv.x*gsize) <= _LineSize) 103 | // { 104 | brightness = _LineColor.w; 105 | color = _LineColor; 106 | } 107 | } 108 | if(round(_DrawV) == 1.0) 109 | { 110 | if (frac(uv.y*gsize) <= _LineSize) 111 | { 112 | brightness = _LineColor.w; 113 | color = _LineColor; 114 | } 115 | } 116 | // // if (round(uv.x*gsize) == .8) 117 | // // if (uv.x >= _LineOffset) 118 | // if (uv.x >= .2 && uv.x <= .3) 119 | // { 120 | // brightness = _LineColor.w; 121 | // color = _LineColor; 122 | // // color = _CellColor; 123 | // // brightness = _CellColor.w; 124 | // } 125 | 126 | // if (frac(uv.x*gsize) <= _LineSize && frac(uv.y*gsize) <= _LineSize) 127 | // { 128 | // // brightness = _LineColor.w; 129 | // // color = _LineColor; 130 | // color = _CellColor; 131 | // brightness = _CellColor.w; 132 | // } 133 | 134 | 135 | // if (frac(uv.x*gsize/_LineOffset) <= _LineSize) 136 | // { 137 | // brightness = _LineColor.w; 138 | // color = _LineColor; 139 | // } 140 | // if (frac(uv.x*gsize/.5) <= _LineSize || fradc(uv.y*gsize) <= _LineSize) 141 | // { 142 | // brightness = _LineColor.w; 143 | // color = _LineColor; 144 | // } 145 | 146 | 147 | //Clip transparent spots using alpha cutout 148 | if (brightness == 0.0) { 149 | clip(c.a - 1.0); 150 | } 151 | 152 | 153 | o.Albedo = float4( color.x*brightness,color.y*brightness,color.z*brightness,brightness); 154 | // Metallic and smoothness come from slider variables 155 | o.Metallic = 0.0; 156 | o.Smoothness = 0.0; 157 | o.Alpha = 0.0; 158 | } 159 | ENDCG 160 | } 161 | FallBack "Diffuse" 162 | } 163 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/GridPatternShader.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1532902b4ade9470093a5cc101d0620b 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/Headband.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Headband 10 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | m_Floats: 58 | - _BumpScale: 1 59 | - _Cutoff: 0.5 60 | - _DetailNormalMapScale: 1 61 | - _DstBlend: 0 62 | - _GlossMapScale: 1 63 | - _Glossiness: 1 64 | - _GlossyReflections: 1 65 | - _Metallic: 0 66 | - _Mode: 0 67 | - _OcclusionStrength: 1 68 | - _Parallax: 0.02 69 | - _SmoothnessTextureChannel: 0 70 | - _SpecularHighlights: 1 71 | - _SrcBlend: 1 72 | - _UVSec: 0 73 | - _ZWrite: 1 74 | m_Colors: 75 | - _Color: {r: 0.98039216, g: 0.6509804, b: 0.16078432, a: 1} 76 | - _EmissionColor: {r: 0.98039216, g: 0.6509804, b: 0.16078432, a: 1} 77 | -------------------------------------------------------------------------------- /Samples~/Basic/Prefab/Headband.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 565ac6aa5eb734469a5711c85569401d 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Scene.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7340e1be92ce742d995c4ac560727270 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Scene/Basic.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf1d119a8748d406e90ecb623b45f92f 3 | timeCreated: 1504127824 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Script.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 41b80e96538bc462ebaa5289bc49ee06 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Basic/Script/BasicAgent.cs: -------------------------------------------------------------------------------- 1 | using Unity.AI.MLAgents; 2 | using Unity.Entities; 3 | using Unity.Collections; 4 | using UnityEngine; 5 | 6 | public class BasicAgent : MonoBehaviour 7 | { 8 | public PolicySpecs BasicSpecs; 9 | private Policy m_Policy; 10 | private Entity m_Entity; 11 | private NativeHashMap m_DiscreteAction; 12 | 13 | public float timeBetweenDecisionsAtInference; 14 | float m_TimeSinceDecision; 15 | public int m_Position; 16 | const int k_SmallGoalPosition = 7; 17 | const int k_LargeGoalPosition = 17; 18 | public GameObject largeGoal; 19 | public GameObject smallGoal; 20 | const int k_MinPosition = 0; 21 | const int k_MaxPosition = 20; 22 | public const int k_Extents = k_MaxPosition - k_MinPosition; 23 | 24 | void BeginEpisode() 25 | { 26 | m_Position = 10; 27 | transform.position = new Vector3(m_Position - 10f, 0f, 0f); 28 | smallGoal.transform.position = new Vector3(k_SmallGoalPosition - 10f, 0f, 0f); 29 | largeGoal.transform.position = new Vector3(k_LargeGoalPosition - 10f, 0f, 0f); 30 | } 31 | 32 | // Start is called before the first frame update 33 | void Start() 34 | { 35 | m_Entity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(); 36 | m_Policy = BasicSpecs.GetPolicy(); 37 | m_DiscreteAction = new NativeHashMap(1, Allocator.Persistent); 38 | if (BasicSpecs.PolicyProcessorType == PolicyProcessorType.None){ 39 | m_Policy.RegisterPolicyWithHeuristic(BasicSpecs.Name, discreteHeuristic:() => { return 1; }); 40 | } 41 | 42 | Academy.Instance.OnEnvironmentReset += BeginEpisode; 43 | BeginEpisode(); 44 | } 45 | 46 | void FixedUpdate() 47 | { 48 | if (Academy.Instance.IsCommunicatorOn) 49 | { 50 | StepAgent(); 51 | } 52 | else 53 | { 54 | if (m_TimeSinceDecision >= timeBetweenDecisionsAtInference) 55 | { 56 | StepAgent(); 57 | m_TimeSinceDecision = 0f; 58 | } 59 | else 60 | { 61 | m_TimeSinceDecision += Time.fixedDeltaTime; 62 | } 63 | } 64 | } 65 | 66 | void StepAgent() 67 | { 68 | // Request a Decision for all agents 69 | m_Policy.RequestDecision(m_Entity) 70 | .SetObservation(0, m_Position) 71 | .SetReward(-0.01f); 72 | 73 | // Get the action 74 | m_Policy.GenerateDiscreteActionHashMap(m_DiscreteAction); 75 | int action = 0; 76 | m_DiscreteAction.TryGetValue(m_Entity, out action); 77 | 78 | 79 | // Apply the action 80 | if (action == 1) 81 | { 82 | m_Position -= 1; 83 | } 84 | if (action == 2) 85 | { 86 | m_Position += 1; 87 | } 88 | if (m_Position < k_MinPosition) { m_Position = k_MinPosition; } 89 | if (m_Position > k_MaxPosition) { m_Position = k_MaxPosition; } 90 | gameObject.transform.position = new Vector3(m_Position - 10f, 0f, 0f); 91 | 92 | // See if the Agent terminated 93 | if (m_Position == k_SmallGoalPosition) 94 | { 95 | m_Policy.EndEpisode(m_Entity) 96 | .SetObservation(0, m_Position) 97 | .SetReward(0.1f); 98 | BeginEpisode(); 99 | } 100 | 101 | if (m_Position == k_LargeGoalPosition) 102 | { 103 | m_Policy.EndEpisode(m_Entity) 104 | .SetObservation(0, m_Position) 105 | .SetReward(1f); 106 | BeginEpisode(); 107 | } 108 | } 109 | 110 | void OnDestroy() 111 | { 112 | m_Policy.Dispose(); 113 | m_DiscreteAction.Dispose(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Samples~/Basic/Script/BasicAgent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 166098905c67d4471b4885f780316c5f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/Basic/Script/BasicController.cs: -------------------------------------------------------------------------------- 1 | // using UnityEngine; 2 | // using UnityEngine.SceneManagement; 3 | // using MLAgents; 4 | 5 | // /// 6 | // /// An example of how to use ML-Agents without inheriting from the Agent class. 7 | // /// Observations are generated by the attached SensorComponent, and the actions 8 | // /// are retrieved from the Agent. 9 | // /// 10 | // public class BasicController : MonoBehaviour 11 | // { 12 | // public float timeBetweenDecisionsAtInference; 13 | // float m_TimeSinceDecision; 14 | // [HideInInspector] 15 | // public int m_Position; 16 | // const int k_SmallGoalPosition = 7; 17 | // const int k_LargeGoalPosition = 17; 18 | // public GameObject largeGoal; 19 | // public GameObject smallGoal; 20 | // const int k_MinPosition = 0; 21 | // const int k_MaxPosition = 20; 22 | // public const int k_Extents = k_MaxPosition - k_MinPosition; 23 | 24 | // Agent m_Agent; 25 | 26 | 27 | // public void OnEnable() 28 | // { 29 | // m_Agent = GetComponent(); 30 | // m_Position = 10; 31 | // transform.position = new Vector3(m_Position - 10f, 0f, 0f); 32 | // smallGoal.transform.position = new Vector3(k_SmallGoalPosition - 10f, 0f, 0f); 33 | // largeGoal.transform.position = new Vector3(k_LargeGoalPosition - 10f, 0f, 0f); 34 | // } 35 | 36 | // /// 37 | // /// Controls the movement of the GameObject based on the actions received. 38 | // /// 39 | // /// 40 | // public void ApplyAction(float[] vectorAction) 41 | // { 42 | // var movement = (int)vectorAction[0]; 43 | 44 | // var direction = 0; 45 | 46 | // switch (movement) 47 | // { 48 | // case 1: 49 | // direction = -1; 50 | // break; 51 | // case 2: 52 | // direction = 1; 53 | // break; 54 | // } 55 | 56 | // m_Position += direction; 57 | // if (m_Position < k_MinPosition) { m_Position = k_MinPosition; } 58 | // if (m_Position > k_MaxPosition) { m_Position = k_MaxPosition; } 59 | 60 | // gameObject.transform.position = new Vector3(m_Position - 10f, 0f, 0f); 61 | 62 | // m_Agent.AddReward(-0.01f); 63 | 64 | // if (m_Position == k_SmallGoalPosition) 65 | // { 66 | // m_Agent.AddReward(0.1f); 67 | // m_Agent.EndEpisode(); 68 | // ResetAgent(); 69 | // } 70 | 71 | // if (m_Position == k_LargeGoalPosition) 72 | // { 73 | // m_Agent.AddReward(1f); 74 | // m_Agent.EndEpisode(); 75 | // ResetAgent(); 76 | // } 77 | // } 78 | 79 | // public void ResetAgent() 80 | // { 81 | // // This is a very inefficient way to reset the scene. Used here for testing. 82 | // SceneManager.LoadScene(SceneManager.GetActiveScene().name); 83 | // m_Agent = null; // LoadScene only takes effect at the next Update. 84 | // // We set the Agent to null to avoid using the Agent before the reload 85 | // } 86 | 87 | // public void FixedUpdate() 88 | // { 89 | // WaitTimeInference(); 90 | // } 91 | 92 | // void WaitTimeInference() 93 | // { 94 | // if (m_Agent == null) 95 | // { 96 | // return; 97 | // } 98 | // if (Academy.Instance.IsCommunicatorOn) 99 | // { 100 | // // Apply the previous step's actions 101 | // ApplyAction(m_Agent.GetAction()); 102 | // m_Agent?.RequestDecision(); 103 | // } 104 | // else 105 | // { 106 | // if (m_TimeSinceDecision >= timeBetweenDecisionsAtInference) 107 | // { 108 | // // Apply the previous step's actions 109 | // ApplyAction(m_Agent.GetAction()); 110 | 111 | // m_TimeSinceDecision = 0f; 112 | // m_Agent?.RequestDecision(); 113 | // } 114 | // else 115 | // { 116 | // m_TimeSinceDecision += Time.fixedDeltaTime; 117 | // } 118 | // } 119 | // } 120 | // } 121 | -------------------------------------------------------------------------------- /Samples~/Basic/Script/BasicController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 624480a72e46148118ab2e2d89b537de 3 | timeCreated: 1503355437 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e806d68316eff0e46a3fda372ae42c44 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/AgentBlue.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: AgentBlue 10 | m_Shader: {fileID: 47, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | - _SpecGlossMap: 58 | m_Texture: {fileID: 0} 59 | m_Scale: {x: 1, y: 1} 60 | m_Offset: {x: 0, y: 0} 61 | m_Floats: 62 | - _BumpScale: 1 63 | - _Cutoff: 0.5 64 | - _DetailNormalMapScale: 1 65 | - _DstBlend: 0 66 | - _GlossMapScale: 1 67 | - _Glossiness: 0.5 68 | - _GlossyReflections: 0 69 | - _Metallic: 0 70 | - _Mode: 0 71 | - _OcclusionStrength: 1 72 | - _Parallax: 0.02 73 | - _SmoothnessTextureChannel: 0 74 | - _SpecularHighlights: 0 75 | - _SrcBlend: 1 76 | - _UVSec: 0 77 | - _ZWrite: 1 78 | m_Colors: 79 | - _Color: {r: 0.12941177, g: 0.5882353, b: 0.9529412, a: 1} 80 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 81 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/AgentBlue.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0bfb83bd246c4dd899e8a8421543682 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/Checkers_Gray.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Checkers_Gray 10 | m_Shader: {fileID: 47, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _METALLICGLOSSMAP _NORMALMAP _SPECULARHIGHLIGHTS_OFF 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 2800000, guid: c4b43567aafd8a040b34a6a86ce60ad9, type: 3} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 2800000, guid: c922805328ab07d4396783401534201b, type: 3} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 2800000, guid: 0dbde4b748147ad46bb2c40602273db7, type: 3} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 2800000, guid: 0dbde4b748147ad46bb2c40602273db7, type: 3} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | - _SpecGlossMap: 58 | m_Texture: {fileID: 0} 59 | m_Scale: {x: 1, y: 1} 60 | m_Offset: {x: 0, y: 0} 61 | m_Floats: 62 | - _BumpScale: 1 63 | - _Cutoff: 0.5 64 | - _DetailNormalMapScale: 1 65 | - _DstBlend: 0 66 | - _GlossMapScale: 1 67 | - _Glossiness: 0.5 68 | - _GlossyReflections: 0 69 | - _Metallic: 0 70 | - _Mode: 0 71 | - _OcclusionStrength: 1 72 | - _Parallax: 0.02 73 | - _SmoothnessTextureChannel: 0 74 | - _SpecularHighlights: 0 75 | - _SrcBlend: 1 76 | - _UVSec: 0 77 | - _ZWrite: 1 78 | m_Colors: 79 | - _Color: {r: 1, g: 1, b: 1, a: 1} 80 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 81 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/Checkers_Gray.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 61a93c64e51db41bda9ca7982cdd2530 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/Eye.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Eye 10 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: _ALPHATEST_ON _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: 2450 16 | stringTagMap: 17 | RenderType: TransparentCutout 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 10912, guid: 0000000000000000f000000000000000, type: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | m_Floats: 59 | - _BumpScale: 1 60 | - _Cutoff: 0.5 61 | - _DetailNormalMapScale: 1 62 | - _DstBlend: 0 63 | - _GlossMapScale: 1 64 | - _Glossiness: 0.5 65 | - _GlossyReflections: 0 66 | - _Metallic: 0 67 | - _Mode: 1 68 | - _OcclusionStrength: 1 69 | - _Parallax: 0.02 70 | - _SmoothnessTextureChannel: 0 71 | - _SpecularHighlights: 0 72 | - _SrcBlend: 1 73 | - _UVSec: 0 74 | - _ZWrite: 1 75 | m_Colors: 76 | - _Color: {r: 0.058823526, g: 0.058823526, b: 0.058823526, a: 1} 77 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 78 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/Eye.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ecfc93a082b0144adbd512ee0270ffe3 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/GrayMiddle.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: GrayMiddle 10 | m_Shader: {fileID: 47, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | - _SpecGlossMap: 58 | m_Texture: {fileID: 0} 59 | m_Scale: {x: 1, y: 1} 60 | m_Offset: {x: 0, y: 0} 61 | m_Floats: 62 | - _BumpScale: 1 63 | - _Cutoff: 0.5 64 | - _DetailNormalMapScale: 1 65 | - _DstBlend: 0 66 | - _GlossMapScale: 1 67 | - _Glossiness: 0.5 68 | - _GlossyReflections: 0 69 | - _Metallic: 0 70 | - _Mode: 0 71 | - _OcclusionStrength: 1 72 | - _Parallax: 0.02 73 | - _SmoothnessTextureChannel: 0 74 | - _SpecularHighlights: 0 75 | - _SrcBlend: 1 76 | - _UVSec: 0 77 | - _ZWrite: 1 78 | m_Colors: 79 | - _Color: {r: 0.39215687, g: 0.39215687, b: 0.39215687, a: 1} 80 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 81 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/GrayMiddle.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c9164eab2ce734c6bae506847dd99ccb 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/Green.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Green 10 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | m_Floats: 58 | - _BumpScale: 1 59 | - _Cutoff: 0.5 60 | - _DetailNormalMapScale: 1 61 | - _DstBlend: 0 62 | - _GlossMapScale: 1 63 | - _Glossiness: 0.5 64 | - _GlossyReflections: 0 65 | - _Metallic: 0 66 | - _Mode: 0 67 | - _OcclusionStrength: 1 68 | - _Parallax: 0.02 69 | - _SmoothnessTextureChannel: 0 70 | - _SpecularHighlights: 0 71 | - _SrcBlend: 1 72 | - _UVSec: 0 73 | - _ZWrite: 1 74 | m_Colors: 75 | - _Color: {r: 0.40392157, g: 0.7372549, b: 0.41960785, a: 1} 76 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 77 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/Green.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f3081d319b34a45b798e2a9667fba8de 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/GridMatFloor.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: GridMatFloor 11 | m_Shader: {fileID: 4800000, guid: d73f3945ac27941cc81e994636d9c461, type: 3} 12 | m_ShaderKeywords: 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 0 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | m_Floats: 59 | - _BumpScale: 1 60 | - _Cutoff: 0.5 61 | - _DetailNormalMapScale: 1 62 | - _DrawU: 1 63 | - _DrawV: 1 64 | - _DstBlend: 0 65 | - _GlossMapScale: 1 66 | - _Glossiness: 0 67 | - _GlossyReflections: 1 68 | - _GridSize: 6 69 | - _LineOffset: 0.5 70 | - _LineSize: 0.02 71 | - _Metallic: 0 72 | - _Mode: 0 73 | - _OcclusionStrength: 1 74 | - _Offset: 0 75 | - _Parallax: 0.02 76 | - _RepeatCount: 5 77 | - _SelectCell: 0 78 | - _SelectedCellX: 0 79 | - _SelectedCellY: 0 80 | - _SmoothnessTextureChannel: 0 81 | - _Spacing: 0.5 82 | - _SpecularHighlights: 1 83 | - _SrcBlend: 1 84 | - _UVSec: 0 85 | - _ZWrite: 1 86 | m_Colors: 87 | - _CellColor: {r: 0.116, g: 0.116, b: 0.116, a: 1} 88 | - _Color: {r: 0.935151, g: 0.9705882, b: 0.3282872, a: 0} 89 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 90 | - _LineColor: {r: 0.15686275, g: 0.15686275, b: 0.15686275, a: 1} 91 | - _SelectedColor: {r: 0.1586206, g: 1, b: 0, a: 1} 92 | m_BuildTextureStacks: [] 93 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/GridMatFloor.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf93576e936bf411a96a701ee902f878 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/GridPatternShaderPushBlock.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: upgraded instancing buffer 'Props' to new syntax. 2 | 3 | Shader "ML-Agents/GridPatternPushBlock" { 4 | Properties { 5 | _LineColor ("Line Color", Color) = (1,1,1,1) 6 | _CellColor ("Cell Color", Color) = (0,0,0,0) 7 | // _SelectedColor ("Selected Color", Color) = (1,0,0,1) 8 | [PerRendererData] _MainTex ("Albedo (RGB)", 2D) = "white" {} 9 | [IntRange] _GridSize("Grid Size", Range(1,100)) = 10 10 | _LineSize("Line Size", Range(0,1)) = 0.15 11 | // [FloatRange] _LineOffset("Line Offset", Range(0,1)) = 0 12 | [IntRange] _DrawU("Draw U Toggle ( 0 = False , 1 = True )", Range(0,1)) = 1 13 | [IntRange] _DrawV("Draw V Toggle ( 0 = False , 1 = True )", Range(0,1)) = 1 14 | // [IntRange] _SelectCell("Select Cell Toggle ( 0 = False , 1 = True )", Range(0,1)) = 0.0 15 | // [IntRange] _SelectedCellX("Selected Cell X", Range(0,100)) = 0.0 16 | // [IntRange] _SelectedCellY("Selected Cell Y", Range(0,100)) = 0.0 17 | } 18 | SubShader { 19 | Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" } 20 | LOD 200 21 | 22 | 23 | CGPROGRAM 24 | // Physically based Standard lighting model, and enable shadows on all light types 25 | #pragma surface surf Standard fullforwardshadows 26 | 27 | // Use shader model 3.0 target, to get nicer looking lighting 28 | #pragma target 3.0 29 | 30 | sampler2D _MainTex; 31 | 32 | struct Input { 33 | float2 uv_MainTex; 34 | }; 35 | 36 | half _Glossiness = 0.0; 37 | half _Metallic = 0.0; 38 | float4 _LineColor; 39 | float4 _CellColor; 40 | // float4 _SelectedColor; 41 | 42 | float _GridSize; 43 | // float _LineOffset; 44 | float _LineSize; 45 | 46 | float _DrawU; 47 | float _DrawV; 48 | // float _SelectCell; 49 | // float _SelectedCellX; 50 | // float _SelectedCellY; 51 | 52 | // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. 53 | // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. 54 | // #pragma instancing_options assumeuniformscaling 55 | UNITY_INSTANCING_BUFFER_START(Props) 56 | // put more per-instance properties here 57 | UNITY_INSTANCING_BUFFER_END(Props) 58 | 59 | void surf (Input IN, inout SurfaceOutputStandard o) { 60 | // Albedo comes from a texture tinted by color 61 | 62 | float2 uv = IN.uv_MainTex; 63 | 64 | // _SelectedCellX = floor(_SelectedCellX); 65 | // _SelectedCellY = floor(_SelectedCellY); 66 | 67 | fixed4 c = float4(0.0,0.0,0.0,0.0); 68 | 69 | float brightness = 1.0; 70 | 71 | float gsize = floor(_GridSize); 72 | 73 | 74 | 75 | gsize += _LineSize; 76 | 77 | float2 id; 78 | 79 | id.x = floor(uv.x/(1.0/gsize)); 80 | // id.y = floor(uv.y/(1.0/gsize)); 81 | id.y = floor(uv.y/(1.0/gsize)); 82 | 83 | float4 color = _CellColor; 84 | brightness = _CellColor.w; 85 | 86 | // //This checks that the cell is currently selected if the Select Cell slider is set to 1 ( True ) 87 | // if (round(_SelectCell) == 1.0 && id.x == _SelectedCellX && id.y == _SelectedCellY) 88 | // { 89 | // brightness = _SelectedColor.w; 90 | // color = _SelectedColor; 91 | // } 92 | 93 | // if (frac(uv.x*gsize) <= _LineSize || frac(uv.y*gsize) <= _LineSize) 94 | // { 95 | // brightness = _LineColor.w; 96 | // color = _LineColor; 97 | // } 98 | if(round(_DrawU) == 1.0) 99 | { 100 | if (frac(uv.x*gsize) <= _LineSize) 101 | { 102 | // if (frac(uv.x*gsize) <= _LineSize) 103 | // { 104 | brightness = _LineColor.w; 105 | color = _LineColor; 106 | } 107 | } 108 | if(round(_DrawV) == 1.0) 109 | { 110 | if (frac(uv.y*gsize) <= _LineSize) 111 | { 112 | brightness = _LineColor.w; 113 | color = _LineColor; 114 | } 115 | } 116 | // // if (round(uv.x*gsize) == .8) 117 | // // if (uv.x >= _LineOffset) 118 | // if (uv.x >= .2 && uv.x <= .3) 119 | // { 120 | // brightness = _LineColor.w; 121 | // color = _LineColor; 122 | // // color = _CellColor; 123 | // // brightness = _CellColor.w; 124 | // } 125 | 126 | // if (frac(uv.x*gsize) <= _LineSize && frac(uv.y*gsize) <= _LineSize) 127 | // { 128 | // // brightness = _LineColor.w; 129 | // // color = _LineColor; 130 | // color = _CellColor; 131 | // brightness = _CellColor.w; 132 | // } 133 | 134 | 135 | // if (frac(uv.x*gsize/_LineOffset) <= _LineSize) 136 | // { 137 | // brightness = _LineColor.w; 138 | // color = _LineColor; 139 | // } 140 | // if (frac(uv.x*gsize/.5) <= _LineSize || fradc(uv.y*gsize) <= _LineSize) 141 | // { 142 | // brightness = _LineColor.w; 143 | // color = _LineColor; 144 | // } 145 | 146 | 147 | //Clip transparent spots using alpha cutout 148 | if (brightness == 0.0) { 149 | clip(c.a - 1.0); 150 | } 151 | 152 | 153 | o.Albedo = float4( color.x*brightness,color.y*brightness,color.z*brightness,brightness); 154 | // Metallic and smoothness come from slider variables 155 | o.Metallic = 0.0; 156 | o.Smoothness = 0.0; 157 | o.Alpha = 0.0; 158 | } 159 | ENDCG 160 | } 161 | FallBack "Diffuse" 162 | } 163 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/GridPatternShaderPushBlock.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d73f3945ac27941cc81e994636d9c461 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/Headband.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Headband 10 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | m_Floats: 58 | - _BumpScale: 1 59 | - _Cutoff: 0.5 60 | - _DetailNormalMapScale: 1 61 | - _DstBlend: 0 62 | - _GlossMapScale: 1 63 | - _Glossiness: 1 64 | - _GlossyReflections: 1 65 | - _Metallic: 0 66 | - _Mode: 0 67 | - _OcclusionStrength: 1 68 | - _Parallax: 0.02 69 | - _SmoothnessTextureChannel: 0 70 | - _SpecularHighlights: 1 71 | - _SrcBlend: 1 72 | - _UVSec: 0 73 | - _ZWrite: 1 74 | m_Colors: 75 | - _Color: {r: 0.98039216, g: 0.6509804, b: 0.16078432, a: 1} 76 | - _EmissionColor: {r: 0.98039216, g: 0.6509804, b: 0.16078432, a: 1} 77 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/Headband.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a50a8f9fa5ce42e3b30f698ba287d81 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/PushBlockCourt.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/ml-agents-dots/75d2e493822d5bb3da7a8713c50b61ab90fcfe7b/Samples~/PushBlock/Meshes/PushBlockCourt.fbx -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/PushBlockCourt.fbx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c639386c12f5f7841892163a199dfacc 3 | ModelImporter: 4 | serializedVersion: 22 5 | fileIDToRecycleName: 6 | 100000: GoalArea 7 | 100002: Ground 8 | 100004: //RootNode 9 | 100006: WallsOuter 10 | 400000: GoalArea 11 | 400002: Ground 12 | 400004: //RootNode 13 | 400006: WallsOuter 14 | 2100000: rep_WhiteWalls 15 | 2100002: rep_Floor 16 | 2100004: rep_Checkers 17 | 2300000: GoalArea 18 | 2300002: Ground 19 | 2300004: WallsOuter 20 | 3300000: GoalArea 21 | 3300002: Ground 22 | 3300004: WallsOuter 23 | 4300000: WallsOuter 24 | 4300002: Ground 25 | 4300004: GoalArea 26 | externalObjects: 27 | - first: 28 | type: UnityEngine:Material 29 | assembly: UnityEngine.CoreModule 30 | name: rep_Checkers 31 | second: {fileID: 2100000, guid: 36c7baa347d68f347a9aa9698aa1bcdd, type: 2} 32 | - first: 33 | type: UnityEngine:Material 34 | assembly: UnityEngine.CoreModule 35 | name: rep_Floor 36 | second: {fileID: 2100000, guid: bc723809e6ff3174fad3e774cae1aed0, type: 2} 37 | - first: 38 | type: UnityEngine:Material 39 | assembly: UnityEngine.CoreModule 40 | name: rep_WhiteWalls 41 | second: {fileID: 2100000, guid: 6a39c0407dd85684384bf0277294e9b6, type: 2} 42 | materials: 43 | importMaterials: 1 44 | materialName: 0 45 | materialSearch: 1 46 | materialLocation: 1 47 | animations: 48 | legacyGenerateAnimations: 4 49 | bakeSimulation: 0 50 | resampleCurves: 1 51 | optimizeGameObjects: 0 52 | motionNodeName: 53 | rigImportErrors: 54 | rigImportWarnings: 55 | animationImportErrors: 56 | animationImportWarnings: 57 | animationRetargetingWarnings: 58 | animationDoRetargetingWarnings: 0 59 | importAnimatedCustomProperties: 0 60 | animationCompression: 1 61 | animationRotationError: 0.5 62 | animationPositionError: 0.5 63 | animationScaleError: 0.5 64 | animationWrapMode: 0 65 | extraExposedTransformPaths: [] 66 | extraUserProperties: [] 67 | clipAnimations: [] 68 | isReadable: 1 69 | meshes: 70 | lODScreenPercentages: [] 71 | globalScale: 1 72 | meshCompression: 0 73 | addColliders: 0 74 | importVisibility: 1 75 | importBlendShapes: 1 76 | importCameras: 1 77 | importLights: 1 78 | swapUVChannels: 0 79 | generateSecondaryUV: 1 80 | useFileUnits: 1 81 | optimizeMeshForGPU: 1 82 | keepQuads: 0 83 | weldVertices: 1 84 | preserveHierarchy: 0 85 | indexFormat: 0 86 | secondaryUVAngleDistortion: 8 87 | secondaryUVAreaDistortion: 15.000001 88 | secondaryUVHardAngle: 88 89 | secondaryUVPackMargin: 4 90 | useFileScale: 1 91 | tangentSpace: 92 | normalSmoothAngle: 60 93 | normalImportMode: 0 94 | tangentImportMode: 3 95 | normalCalculationMode: 4 96 | importAnimation: 1 97 | copyAvatar: 0 98 | humanDescription: 99 | serializedVersion: 2 100 | human: [] 101 | skeleton: [] 102 | armTwist: 0.5 103 | foreArmTwist: 0.5 104 | upperLegTwist: 0.5 105 | legTwist: 0.5 106 | armStretch: 0.05 107 | legStretch: 0.05 108 | feetSpacing: 0 109 | rootMotionBoneName: 110 | rootMotionBoneRotation: {x: 0, y: 0, z: 0, w: 1} 111 | hasTranslationDoF: 0 112 | hasExtraRoot: 0 113 | skeletonHasParents: 1 114 | lastHumanDescriptionAvatarSource: {instanceID: 0} 115 | animationType: 0 116 | humanoidOversampling: 1 117 | additionalBone: 0 118 | userData: 119 | assetBundleName: 120 | assetBundleVariant: 121 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/White.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: White 10 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF 12 | m_LightmapFlags: 4 13 | m_EnableInstancingVariants: 0 14 | m_DoubleSidedGI: 0 15 | m_CustomRenderQueue: -1 16 | stringTagMap: {} 17 | disabledShaderPasses: [] 18 | m_SavedProperties: 19 | serializedVersion: 3 20 | m_TexEnvs: 21 | - _BumpMap: 22 | m_Texture: {fileID: 0} 23 | m_Scale: {x: 1, y: 1} 24 | m_Offset: {x: 0, y: 0} 25 | - _DetailAlbedoMap: 26 | m_Texture: {fileID: 0} 27 | m_Scale: {x: 1, y: 1} 28 | m_Offset: {x: 0, y: 0} 29 | - _DetailMask: 30 | m_Texture: {fileID: 0} 31 | m_Scale: {x: 1, y: 1} 32 | m_Offset: {x: 0, y: 0} 33 | - _DetailNormalMap: 34 | m_Texture: {fileID: 0} 35 | m_Scale: {x: 1, y: 1} 36 | m_Offset: {x: 0, y: 0} 37 | - _EmissionMap: 38 | m_Texture: {fileID: 0} 39 | m_Scale: {x: 1, y: 1} 40 | m_Offset: {x: 0, y: 0} 41 | - _MainTex: 42 | m_Texture: {fileID: 0} 43 | m_Scale: {x: 1, y: 1} 44 | m_Offset: {x: 0, y: 0} 45 | - _MetallicGlossMap: 46 | m_Texture: {fileID: 0} 47 | m_Scale: {x: 1, y: 1} 48 | m_Offset: {x: 0, y: 0} 49 | - _OcclusionMap: 50 | m_Texture: {fileID: 0} 51 | m_Scale: {x: 1, y: 1} 52 | m_Offset: {x: 0, y: 0} 53 | - _ParallaxMap: 54 | m_Texture: {fileID: 0} 55 | m_Scale: {x: 1, y: 1} 56 | m_Offset: {x: 0, y: 0} 57 | m_Floats: 58 | - _BumpScale: 1 59 | - _Cutoff: 0.5 60 | - _DetailNormalMapScale: 1 61 | - _DstBlend: 0 62 | - _GlossMapScale: 1 63 | - _Glossiness: 0.5 64 | - _GlossyReflections: 0 65 | - _Metallic: 0 66 | - _Mode: 0 67 | - _OcclusionStrength: 1 68 | - _Parallax: 0.02 69 | - _SmoothnessTextureChannel: 0 70 | - _SpecularHighlights: 0 71 | - _SrcBlend: 1 72 | - _UVSec: 0 73 | - _ZWrite: 1 74 | m_Colors: 75 | - _Color: {r: 0.9254902, g: 0.9372549, b: 0.9411765, a: 1} 76 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 77 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Meshes/White.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f732c5c04cad549f3bae8d2f7ddda1f5 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/NNModels.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5855121f0ded74dad8e1dd15a8bcdca1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PushBlock/NNModels/PushBlock.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/ml-agents-dots/75d2e493822d5bb3da7a8713c50b61ab90fcfe7b/Samples~/PushBlock/NNModels/PushBlock.onnx -------------------------------------------------------------------------------- /Samples~/PushBlock/NNModels/PushBlock.onnx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a0ac265a037249a18ef934c145167d1 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3} 11 | optimizeModel: 1 12 | forceArbitraryBatchSize: 1 13 | treatErrorsAsWarnings: 0 14 | importMode: 1 15 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d2b9d5547d934200a786212743850c4 3 | folderAsset: yes 4 | timeCreated: 1514922259 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Prefabs/PushBlockArea.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 03bcc81e249714a22bb411dddcc5d15e 3 | timeCreated: 1515023875 4 | licenseType: Free 5 | NativeFormatImporter: 6 | externalObjects: {} 7 | mainObjectFileID: 100100000 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9da26ec059778432080bf5fa24374960 3 | folderAsset: yes 4 | timeCreated: 1516234013 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scenes/PushBlock.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ae8cc75939e3e4d07a79c8c6a08b54f4 3 | timeCreated: 1506808980 4 | licenseType: Pro 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca44e3d53154a4ff0a1279be30b23bdf 3 | folderAsset: yes 4 | timeCreated: 1514922284 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/Block.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Unity.Entities; 5 | using Unity.Mathematics; 6 | 7 | 8 | 9 | [GenerateAuthoringComponent] 10 | public struct Block : IComponentData 11 | { 12 | public Entity PushingAgent; 13 | public Entity TargetZone; 14 | } 15 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/Block.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 87e19a30f2498445eb9f43d10a947bc6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/BlockCollisionSystem.cs: -------------------------------------------------------------------------------- 1 | using Unity.Entities; 2 | using Unity.Jobs; 3 | using Unity.Burst; 4 | using Unity.Physics.Systems; 5 | using Unity.Physics; 6 | using UnityEngine; 7 | using Unity.Collections; 8 | 9 | 10 | 11 | public class BlockCollisionSystem : JobComponentSystem{ 12 | 13 | [ReadOnly] BuildPhysicsWorld buildPhysicsWorldSystem; 14 | [ReadOnly] StepPhysicsWorld stepPhysicsWorldSystem; 15 | 16 | protected override void OnCreate() 17 | { 18 | buildPhysicsWorldSystem = World.GetOrCreateSystem(); 19 | stepPhysicsWorldSystem = World.GetOrCreateSystem(); 20 | } 21 | protected override JobHandle OnUpdate(JobHandle inputDeps) { 22 | inputDeps = JobHandle.CombineDependencies( 23 | inputDeps, 24 | stepPhysicsWorldSystem.FinalSimulationJobHandle); 25 | 26 | buildPhysicsWorldSystem.AddInputDependency(inputDeps); 27 | 28 | var ecb = new EntityCommandBuffer(Allocator.TempJob); 29 | var triggerJob = new CollisionEventJob{ 30 | entityCommandBuffer = ecb, 31 | BlockData = GetComponentDataFromEntity(isReadOnly : true), 32 | AgentData = GetComponentDataFromEntity(isReadOnly : false), 33 | }; 34 | inputDeps = triggerJob.Schedule( 35 | stepPhysicsWorldSystem.Simulation, ref buildPhysicsWorldSystem.PhysicsWorld, inputDeps); 36 | inputDeps.Complete(); 37 | ecb.Playback(EntityManager); 38 | ecb.Dispose(); 39 | 40 | return inputDeps; 41 | } 42 | 43 | public struct CollisionEventJob : ITriggerEventsJob { 44 | 45 | // This looks at all of the collisions of the block. There is probably a better way to do this 46 | public EntityCommandBuffer entityCommandBuffer; 47 | [ReadOnly] public ComponentDataFromEntity BlockData; 48 | public ComponentDataFromEntity AgentData; 49 | 50 | public void Execute(TriggerEvent triggerEvent){ 51 | Entity A = triggerEvent.EntityA; 52 | Entity B = triggerEvent.EntityB; 53 | 54 | if ((!BlockData.HasComponent(A)) && (!BlockData.HasComponent(B))) 55 | { 56 | // The collision does not involve a block 57 | return; 58 | } 59 | 60 | 61 | if (BlockData.HasComponent(A)) 62 | { 63 | // Swap the two entities 64 | A = triggerEvent.EntityB; 65 | B = triggerEvent.EntityA; 66 | } 67 | 68 | var blockData = BlockData[B]; 69 | 70 | if (blockData.TargetZone == A) 71 | { 72 | var pushAgent = AgentData[blockData.PushingAgent]; 73 | pushAgent.status = PushBlockStatus.Success; 74 | AgentData[blockData.PushingAgent] = pushAgent; 75 | } 76 | 77 | } 78 | 79 | } 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/BlockCollisionSystem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a8103b0b7b65409bb04addae273d562 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/PolicySpecsMonoBehavior.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Unity.AI.MLAgents; 5 | using Unity.Entities; 6 | using Unity.Mathematics; 7 | 8 | public class PolicySpecsMonoBehavior : MonoBehaviour 9 | { 10 | 11 | public PolicySpecs PushBlockPolicySpecs; 12 | 13 | // Start is called before the first frame update 14 | void Start() 15 | { 16 | Policy pushBlockPolicy = PushBlockPolicySpecs.GetPolicy(); 17 | if (PushBlockPolicySpecs.PolicyProcessorType == PolicyProcessorType.None){ 18 | pushBlockPolicy.RegisterPolicyWithHeuristic(PushBlockPolicySpecs.Name, discreteHeuristic:() => { 19 | 20 | int forward = 1; 21 | if (Input.GetKey(KeyCode.W)){ forward = 2;} 22 | else if (Input.GetKey(KeyCode.S)){ forward = 0;} 23 | int rotate = 1; 24 | if (Input.GetKey(KeyCode.D)){ rotate = 2;} 25 | else if (Input.GetKey(KeyCode.A)){ rotate = 0;} 26 | return new PushBlockAction(forward,rotate); 27 | }); 28 | } 29 | foreach (var w in World.All){ 30 | var s = w.GetExistingSystem(); 31 | if (s != null){ 32 | s.PushBlockPolicy = pushBlockPolicy; 33 | } 34 | } 35 | } 36 | 37 | // Update is called once per frame 38 | void Update() 39 | { 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/PolicySpecsMonoBehavior.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6bd493c7ae18045ccb6134fc2523aeec 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/PushBlockAction.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Unity.Entities; 5 | 6 | [GenerateAuthoringComponent] 7 | public struct PushBlockAction: IComponentData{ 8 | public PushBlockAction(int f, int r) 9 | { 10 | Forward = f; 11 | Rotate = r; 12 | } 13 | public int Forward; 14 | public int Rotate; 15 | } 16 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/PushBlockAction.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3b5d8182673104f47ae26ce9de3af751 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/PushBlockCube.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Unity.Entities; 5 | using Unity.Mathematics; 6 | 7 | public enum PushBlockStatus 8 | { 9 | UnInitialized, 10 | Ongoing, 11 | Success, 12 | } 13 | 14 | [GenerateAuthoringComponent] 15 | public struct PushBlockCube : IComponentData 16 | { 17 | public Entity block; 18 | public Entity goal; 19 | public PushBlockStatus status; 20 | public float3 resetPosition; 21 | public int stepCount; 22 | } 23 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/PushBlockCube.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5abb34fbcbc1c4c04b2a7f16910b97a0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/PushBlock/Scripts/PushBlockCubeMoveSystem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55c4c18ee305a446cba5854e7e672484 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/StringSideChannel.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: edef85907d2dc4633b016a9fc778d0bc 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/StringSideChannel/RegisterStringLogSideChannel.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using Unity.AI.MLAgents.SideChannels; 4 | 5 | public class RegisterStringLogSideChannel : MonoBehaviour 6 | { 7 | StringLogSideChannel stringChannel; 8 | public void Awake() 9 | { 10 | stringChannel = new StringLogSideChannel(); 11 | 12 | SideChannelManager.RegisterSideChannel(stringChannel); 13 | 14 | Application.logMessageReceived += stringChannel.SendDebugStatementToPython; 15 | } 16 | 17 | public void OnDestroy() 18 | { 19 | Application.logMessageReceived -= stringChannel.SendDebugStatementToPython; 20 | } 21 | 22 | public void Update() 23 | { 24 | if (Input.GetKeyDown(KeyCode.Space)) 25 | { 26 | Debug.LogError("This is a fake error. Space bar was pressed."); 27 | } 28 | } 29 | } 30 | 31 | 32 | public class StringLogSideChannel : SideChannel 33 | { 34 | public StringLogSideChannel() 35 | { 36 | ChannelId = new Guid("621f0a70-4f87-11ea-a6bf-784f4387d1f7"); 37 | } 38 | 39 | protected override void OnMessageReceived(IncomingMessage message) 40 | { 41 | var receivedString = message.ReadString(); 42 | Debug.Log("From Python : " + receivedString); 43 | } 44 | 45 | public void SendDebugStatementToPython(string logString, string stackTrace, LogType type) 46 | { 47 | if (type == LogType.Error) 48 | { 49 | var message = new OutgoingMessage(); 50 | var stringToSend = type.ToString() + ": " + logString + "\n" + stackTrace; 51 | message.WriteString(stringToSend); 52 | base.QueueMessageToSend(message); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Samples~/StringSideChannel/RegisterStringLogSideChannel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a8c14eb95c5147e1bb50913a09db5c6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec08742da491e4ca19cd65ae9243960e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Tests/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52c1d0b0b21bb4d5fafc2177a262c396 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Tests/Editor/TestArrayUtils.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Collections; 3 | using Unity.Mathematics; 4 | 5 | namespace Unity.AI.MLAgents.Tests.Editor 6 | { 7 | public class TestArrayUtils 8 | { 9 | [Test] 10 | public void TestSum() 11 | { 12 | var testArray = new NativeArray(0, Allocator.Persistent); 13 | Assert.AreEqual(0, testArray.Sum()); 14 | testArray.Dispose(); 15 | testArray = new NativeArray(1, Allocator.Persistent); 16 | Assert.AreEqual(0, testArray.Sum()); 17 | testArray.Dispose(); 18 | testArray = new NativeArray(1, Allocator.Persistent); 19 | testArray[0] = 33; 20 | Assert.AreEqual(33, testArray.Sum()); 21 | testArray.Dispose(); 22 | 23 | for (int capacity = 2; capacity < 300; capacity++) 24 | { 25 | testArray = new NativeArray(capacity, Allocator.Persistent); 26 | for (int i = 0; i < capacity; i++) 27 | { 28 | testArray[i] = i; 29 | } 30 | Assert.AreEqual(capacity * (capacity - 1) / 2, testArray.Sum()); 31 | testArray.Dispose(); 32 | } 33 | } 34 | 35 | [Test] 36 | public void TestCumSumAt() 37 | { 38 | var testArray = new NativeArray(0, Allocator.Persistent); 39 | Assert.AreEqual(0, testArray.CumSumAt(0)); 40 | testArray.Dispose(); 41 | testArray = new NativeArray(1, Allocator.Persistent); 42 | Assert.AreEqual(0, testArray.CumSumAt(0)); 43 | testArray.Dispose(); 44 | testArray = new NativeArray(1, Allocator.Persistent); 45 | testArray[0] = 33; 46 | Assert.AreEqual(0, testArray.CumSumAt(0)); 47 | Assert.AreEqual(33, testArray.CumSumAt(1)); 48 | testArray.Dispose(); 49 | 50 | int capacity = 300; 51 | testArray = new NativeArray(capacity, Allocator.Persistent); 52 | for (int i = 0; i < capacity; i++) 53 | { 54 | testArray[i] = i; 55 | } 56 | for (int i = 2; i < capacity; i++) 57 | { 58 | Assert.AreEqual(i * (i - 1) / 2, testArray.CumSumAt(i)); 59 | } 60 | 61 | Assert.Throws(() => testArray.CumSumAt(capacity * 2)); 62 | testArray.Dispose(); 63 | } 64 | 65 | [Test] 66 | public void TestIncreaseArraySizeHeuristic() 67 | { 68 | for (int reqCapacity = 0; reqCapacity < 20; reqCapacity++) 69 | { 70 | int actualCapacity = ArrayUtils.IncreaseArraySizeHeuristic(reqCapacity); 71 | Assert.Greater(actualCapacity, reqCapacity); 72 | } 73 | } 74 | 75 | [Test] 76 | public void TestGetTotalTensorSize() 77 | { 78 | Assert.AreEqual(new int3(0, 0, 0).GetTotalTensorSize(), 0); 79 | Assert.AreEqual(new int3(1, 1, 1).GetTotalTensorSize(), 1); 80 | Assert.AreEqual(new int3(3, 0, 0).GetTotalTensorSize(), 3); 81 | Assert.AreEqual(new int3(4, 1, 0).GetTotalTensorSize(), 4); 82 | Assert.AreEqual(new int3(4, 2, 0).GetTotalTensorSize(), 8); 83 | } 84 | 85 | [Test] 86 | public void TestGetDimensions() 87 | { 88 | Assert.AreEqual(new int3(0, 0, 0).GetDimensions(), 0); 89 | Assert.AreEqual(new int3(1, 1, 1).GetDimensions(), 3); 90 | Assert.AreEqual(new int3(3, 0, 0).GetDimensions(), 1); 91 | Assert.AreEqual(new int3(4, 1, 0).GetDimensions(), 2); 92 | Assert.AreEqual(new int3(4, 2, 0).GetDimensions(), 2); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Tests/Editor/TestArrayUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: abca7c6cceb99430ea51ac38da9ee5c1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests/Editor/TestCounter.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Collections; 3 | using Unity.Jobs; 4 | 5 | namespace Unity.AI.MLAgents.Tests.Editor 6 | { 7 | public class TestCounter 8 | { 9 | [Test] 10 | public void TestCounterSingleThread() 11 | { 12 | var c = new Counter(Allocator.Persistent); 13 | Assert.AreEqual(0, c.Count); 14 | Assert.AreEqual(1, c.Increment()); 15 | c.Count = 0; 16 | Assert.AreEqual(0, c.Count); 17 | Assert.AreEqual(1, c.Increment()); 18 | Assert.AreEqual(1, c.Count); 19 | c.Dispose(); 20 | } 21 | 22 | struct CountingJob : IJobParallelFor 23 | { 24 | public Counter Counter; 25 | public void Execute(int i) 26 | { 27 | Counter.Increment(); 28 | } 29 | } 30 | 31 | 32 | [Test] 33 | public void TestCounterJob() 34 | { 35 | var c = new Counter(Allocator.Persistent); 36 | 37 | var job = new CountingJob { Counter = c }; 38 | foreach (int expectedValue in new int[] {10, 2000}) 39 | { 40 | c.Count = 0; 41 | job.Schedule(expectedValue, 64).Complete(); 42 | Assert.AreEqual(c.Count, expectedValue); 43 | } 44 | c.Dispose(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Tests/Editor/TestCounter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f16370c10cf134365863563219e2be16 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests/Editor/TestMLAgentsPolicy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d098ee5770e44e71bd3f52e694a0f31 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests/Editor/TestSharedMemory.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using UnityEngine; 3 | using System.IO; 4 | using Unity.AI.MLAgents; 5 | using Unity.Collections; 6 | using Unity.Mathematics; 7 | 8 | namespace Unity.AI.MLAgents.Tests.Editor 9 | { 10 | public class TestSharedMemory 11 | { 12 | [Test] 13 | public void TestBaseSharedMemory() 14 | { 15 | var filePath = Path.Combine(Path.GetTempPath(), "ml-agents", "test"); 16 | File.Delete(filePath); 17 | 18 | var sm0 = new BaseSharedMemory("test", true, 256); 19 | var sm1 = new BaseSharedMemory("test", false); 20 | 21 | var newOffset = sm0.SetInt(0, 3); 22 | Assert.AreEqual(newOffset, sizeof(int)); 23 | Assert.AreEqual(3, sm1.GetInt(0)); 24 | 25 | newOffset = sm0.SetFloat(0, 3f); 26 | Assert.AreEqual(newOffset, sizeof(float)); 27 | Assert.AreEqual(3f, sm1.GetFloat(0)); 28 | 29 | newOffset = sm0.SetBool(0, true); 30 | Assert.AreEqual(newOffset, sizeof(bool)); 31 | Assert.AreEqual(true, sm1.GetBool(0)); 32 | 33 | newOffset = sm0.SetString(0, "foo"); 34 | Assert.AreEqual("foo", sm1.GetString(0)); 35 | sm1.SetString(newOffset, "bar"); 36 | Assert.AreEqual("bar", sm0.GetString(newOffset)); 37 | 38 | Assert.AreEqual(sm0.GetBytes(0, 8), sm1.GetBytes(0, 8)); 39 | 40 | var src = new NativeArray(3, Allocator.Temp); 41 | src[1] = new int4(1, 2, 3, 4); 42 | sm0.SetArray(0, src, 3 * 16); 43 | var dst = new NativeArray(3, Allocator.Temp); 44 | sm1.GetArray(0, dst, 3 * 16); 45 | Assert.AreEqual(dst[1], new int4(1, 2, 3, 4)); 46 | src.Dispose(); 47 | dst.Dispose(); 48 | 49 | sm0.Close(); 50 | 51 | Assert.True(File.Exists(filePath)); 52 | sm1.Delete(); 53 | Assert.False(File.Exists(filePath)); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Tests/Editor/TestSharedMemory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b8fc7af6aeaca481fa495aa0b8991130 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests/Editor/TestVisualObservationUtility.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Collections; 3 | using UnityEngine; 4 | 5 | namespace Unity.AI.MLAgents.Tests.Editor 6 | { 7 | public class TestVisualObservationUtility 8 | { 9 | [Test] 10 | public void TestGetVisObs() 11 | { 12 | int width = 80; 13 | int height = 30; 14 | 15 | var agentGo1 = new GameObject("TestAgent"); 16 | var cam = agentGo1.AddComponent(); 17 | 18 | var array = VisualObservationUtility.GetVisObs(cam, width, height, Allocator.Persistent); 19 | 20 | Assert.AreEqual(array.Length, width * height * 3); 21 | array.Dispose(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Tests/Editor/TestVisualObservationUtility.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1ce689088c8b423193f8d4086b9d38e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests/Editor/Unity.AI.MLAgents.Tests.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.AI.MLAgents.Tests", 3 | "references": [ 4 | "Unity.Entities", 5 | "Unity.Jobs", 6 | "Unity.Burst", 7 | "Unity.Mathematics", 8 | "Unity.Transforms", 9 | "Unity.Collections", 10 | "Unity.AI.MLAgents", 11 | "Unity.Entities.Tests", 12 | "Unity.Entities.Editor.Tests" 13 | ], 14 | "optionalUnityReferences": [ 15 | "TestAssemblies" 16 | ], 17 | "includePlatforms": [ 18 | "Editor" 19 | ], 20 | "excludePlatforms": [], 21 | "allowUnsafeCode": false, 22 | "overrideReferences": false, 23 | "precompiledReferences": [], 24 | "autoReferenced": false, 25 | "defineConstraints": [], 26 | "versionDefines": [] 27 | } -------------------------------------------------------------------------------- /Tests/Editor/Unity.AI.MLAgents.Tests.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0911bdfaefe4430e9ccc4b94ed7490f 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /ml-agents-dots-envs~/mlagents_dots_envs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/ml-agents-dots/75d2e493822d5bb3da7a8713c50b61ab90fcfe7b/ml-agents-dots-envs~/mlagents_dots_envs/__init__.py -------------------------------------------------------------------------------- /ml-agents-dots-envs~/mlagents_dots_envs/examples/example_script.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import argparse 3 | from mlagents_dots_envs.unity_environment import UnityEnvironment 4 | from mlagents_envs.side_channel.engine_configuration_channel import ( 5 | EngineConfigurationChannel, 6 | ) 7 | from mlagents_envs.side_channel.environment_parameters_channel import ( 8 | EnvironmentParametersChannel, 9 | ) 10 | from mlagents_envs.logging_util import set_log_level, DEBUG 11 | 12 | 13 | set_log_level(DEBUG) 14 | 15 | 16 | def perform_steps(n): 17 | for _ in range(n): 18 | s = "" 19 | for name, specs in env.behavior_specs.items(): 20 | s += ( 21 | name 22 | + " : " 23 | + str(len(env.get_steps(name)[0])) 24 | + " : " 25 | + str(len(env.get_steps(name)[1])) 26 | + "|" 27 | ) 28 | env.set_actions( 29 | name, np.ones((len(env.get_steps(name)[0]), specs.action_size)) 30 | ) 31 | print(s) 32 | env.step() 33 | 34 | 35 | if __name__ == "__main__": 36 | parser = argparse.ArgumentParser() 37 | parser.add_argument( 38 | "--env", default=None, type=str, help="The width of the image to display." 39 | ) 40 | args = parser.parse_args() 41 | 42 | sc = EngineConfigurationChannel() 43 | sc2 = EnvironmentParametersChannel() 44 | env = UnityEnvironment(file_name=args.env, side_channels=[sc, sc2]) 45 | sc.set_configuration_parameters() 46 | 47 | print("RESET") 48 | env.reset() 49 | 50 | perform_steps(100) 51 | 52 | print("RESET") 53 | env.reset() 54 | 55 | sc2.set_float_parameter("test", 2) 56 | sc2.set_float_parameter("test2", 2) 57 | sc2.set_float_parameter("test3", 2) 58 | 59 | perform_steps(100) 60 | 61 | env.close() 62 | -------------------------------------------------------------------------------- /ml-agents-dots-envs~/mlagents_dots_envs/shared_memory/__init__ .py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/ml-agents-dots/75d2e493822d5bb3da7a8713c50b61ab90fcfe7b/ml-agents-dots-envs~/mlagents_dots_envs/shared_memory/__init__ .py -------------------------------------------------------------------------------- /ml-agents-dots-envs~/mlagents_dots_envs/shared_memory/shared_memory_communicator.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | import uuid 4 | from typing import Tuple, Dict 5 | 6 | from mlagents_dots_envs.shared_memory.shared_memory_header import SharedMemoryHeader 7 | from mlagents_dots_envs.shared_memory.shared_memory_body import SharedMemoryBody 8 | 9 | from mlagents_envs.exception import UnityCommunicationException 10 | from mlagents_envs.base_env import ( 11 | DecisionSteps, 12 | TerminalSteps, 13 | BehaviorSpec, 14 | ActionTuple, 15 | ) 16 | 17 | 18 | class SharedMemoryCommunicator: 19 | FILE_DEFAULT = "default" 20 | 21 | def __init__(self, use_default: bool = False, timeout_wait: int = 60): 22 | if use_default: 23 | file_name = self.FILE_DEFAULT 24 | else: 25 | file_name = str(uuid.uuid1()) 26 | while os.path.exists(file_name): 27 | file_name = str(uuid.uuid1()) 28 | self._base_file_name = file_name 29 | self._master_mem = SharedMemoryHeader(file_name=file_name) 30 | self._current_file_number = self._master_mem.file_number 31 | self._data_mem = SharedMemoryBody( 32 | file_name + "_" * self._current_file_number, 33 | create_file=True, 34 | copy_from=None, 35 | side_channel_buffer_size=4, 36 | rl_data_buffer_size=0, 37 | ) 38 | self._timeout_wait = timeout_wait 39 | 40 | @property 41 | def communicator_id(self): 42 | return self._base_file_name 43 | 44 | def close(self): 45 | self._master_mem.close() 46 | self._data_mem.delete() 47 | 48 | @property 49 | def active(self) -> bool: 50 | return self._master_mem.active 51 | 52 | def write_side_channel_data(self, data: bytearray) -> None: 53 | capacity = self._master_mem.side_channel_size 54 | if len(data) >= capacity - 4: # need 4 bytes for an integer size 55 | new_capacity = 2 * len(data) + 20 56 | self._current_file_number += 1 57 | self._master_mem.file_number = self._current_file_number 58 | tmp = self._data_mem 59 | self._data_mem = SharedMemoryBody( 60 | self._base_file_name + "_" * self._current_file_number, 61 | create_file=True, 62 | copy_from=tmp, 63 | side_channel_buffer_size=new_capacity, 64 | rl_data_buffer_size=self._master_mem.rl_data_size, 65 | ) 66 | tmp.close() 67 | # Unity is responsible for destroying the old file 68 | self._master_mem.side_channel_size = new_capacity 69 | self._data_mem.side_channel_data = data 70 | 71 | def read_and_clear_side_channel_data(self) -> bytearray: 72 | result = self._data_mem.side_channel_data 73 | self._data_mem.side_channel_data = bytearray() 74 | return result 75 | 76 | def give_unity_control(self, reset: bool = False, query: bool = False) -> None: 77 | self._master_mem.mark_python_blocked() 78 | if query: 79 | self._master_mem.mark_query() 80 | if reset: 81 | self._master_mem.mark_reset() 82 | self._master_mem.unblock_unity() 83 | 84 | def wait_for_unity(self): 85 | iteration = 0 86 | check_timeout_iteration = 1000 87 | t0 = time.time() 88 | while self._master_mem.blocked and self._master_mem.active: 89 | if iteration % check_timeout_iteration == 0: 90 | if time.time() - t0 > self._timeout_wait: 91 | self.close() 92 | self._master_mem.delete() 93 | raise TimeoutError("The Unity Environment took too long to respond") 94 | iteration += 1 95 | if not self._master_mem.active: 96 | try: 97 | self._master_mem.check_version() 98 | finally: 99 | self._master_mem.delete() 100 | self._data_mem.delete() 101 | raise UnityCommunicationException("Communicator has stopped.") 102 | while self._current_file_number < self._master_mem.file_number: 103 | # the file is out of date 104 | self._data_mem.delete() 105 | self._current_file_number += 1 106 | self._data_mem = SharedMemoryBody( 107 | self._base_file_name + "_" * self._current_file_number, 108 | side_channel_buffer_size=self._master_mem.side_channel_size, 109 | rl_data_buffer_size=self._master_mem.rl_data_size, 110 | ) 111 | 112 | def get_steps(self, key: str) -> Tuple[DecisionSteps, TerminalSteps]: 113 | return ( 114 | self._data_mem.get_decision_steps(key), 115 | self._data_mem.get_terminal_steps(key), 116 | ) 117 | 118 | def get_n_decisions_requested(self, key: str) -> int: 119 | return self._data_mem.get_n_decisions_requested(key) 120 | 121 | def set_actions(self, key: str, data: ActionTuple) -> None: 122 | self._data_mem.set_actions(key, data) 123 | 124 | @property 125 | def num_behaviors(self) -> int: 126 | return self._data_mem.num_behaviors 127 | 128 | def generate_specs(self) -> Dict[str, BehaviorSpec]: 129 | return self._data_mem.generate_specs() 130 | -------------------------------------------------------------------------------- /ml-agents-dots-envs~/mlagents_dots_envs/shared_memory/shared_memory_header.py: -------------------------------------------------------------------------------- 1 | import os 2 | import glob 3 | from mlagents_dots_envs.shared_memory.base_shared_memory import BaseSharedMemory 4 | 5 | 6 | class SharedMemoryHeader(BaseSharedMemory): 7 | """ 8 | Always created by Python 9 | File organization: 10 | - 3 ints : major, minor, bug version 11 | - bool : True if Simulation is blocked 12 | - bool : True if Python is blocked 13 | - bool : True if Python commanded a reset 14 | - bool : True if Simulation or Python ordered closing the communication 15 | - int : The number of times the communication file changed 16 | - int : Communication file "side channel" size in bytes 17 | - int : Communication file "RL section" size in bytes 18 | """ 19 | 20 | SIZE = 29 21 | VERSION = (0, 3, 2) 22 | 23 | def __init__( 24 | self, file_name: str, side_channel_size: int = 0, rl_data_size: int = 0 25 | ): 26 | 27 | super(SharedMemoryHeader, self).__init__( 28 | file_name, create_file=True, size=self.SIZE 29 | ) 30 | for f in glob.glob(self._file_path + "_*"): 31 | # Removing all the future files in case they were not correctly created 32 | os.remove(f) 33 | offset = 0 34 | offset = self.set_int(offset, self.VERSION[0]) 35 | offset = self.set_int(offset, self.VERSION[1]) 36 | offset = self.set_int(offset, self.VERSION[2]) 37 | offset = self.set_bool(offset, False) 38 | offset = self.set_bool(offset, False) 39 | offset = self.set_bool(offset, False) 40 | offset = self.set_bool(offset, False) 41 | offset = self.set_int(offset, 1) 42 | offset = self.set_int(offset, side_channel_size) 43 | offset = self.set_int(offset, rl_data_size) 44 | offset = self.set_bool(offset, False) 45 | 46 | @property 47 | def active(self) -> bool: 48 | offset = 15 49 | closed, _ = self.get_bool(offset) 50 | return not closed 51 | 52 | @property 53 | def file_number(self) -> int: 54 | offset = 16 55 | result, _ = self.get_int(offset) 56 | return result 57 | 58 | @file_number.setter 59 | def file_number(self, value: int) -> None: 60 | offset = 16 61 | self.set_int(offset, value) 62 | 63 | def close(self): 64 | if self.accessor is not None: 65 | offset = 15 66 | self.set_bool(offset, True) 67 | super(SharedMemoryHeader, self).close() 68 | 69 | def mark_python_blocked(self): 70 | offset = 13 71 | self.set_bool(offset, True) 72 | 73 | @property 74 | def blocked(self) -> bool: 75 | offset = 13 76 | result, _ = self.get_bool(offset) 77 | return result 78 | 79 | def unblock_unity(self): 80 | offset = 12 81 | self.set_bool(offset, False) 82 | 83 | def mark_reset(self): 84 | offset = 14 85 | self.set_bool(offset, True) 86 | 87 | def mark_query(self): 88 | offset = 28 89 | self.set_bool(offset, True) 90 | 91 | @property 92 | def side_channel_size(self) -> int: 93 | offset = 20 94 | result, _ = self.get_int(offset) 95 | return result 96 | 97 | @side_channel_size.setter 98 | def side_channel_size(self, value: int) -> None: 99 | offset = 20 100 | self.set_int(offset, value) 101 | 102 | @property 103 | def rl_data_size(self) -> int: 104 | offset = 24 105 | result, _ = self.get_int(offset) 106 | return result 107 | 108 | @rl_data_size.setter 109 | def rl_data_size(self, value: int) -> None: 110 | offset = 24 111 | self.set_int(offset, value) 112 | 113 | def check_version(self): 114 | offset = 0 115 | major, offset = self.get_int(offset) 116 | minor, offset = self.get_int(offset) 117 | bug, offset = self.get_int(offset) 118 | if (major, minor, bug) != self.VERSION: 119 | raise Exception( 120 | "Incompatible versions of communicator between " 121 | + f"Unity {major}.{minor}.{bug} and Python " 122 | f"{self.VERSION[0]}.{self.VERSION[1]}.{self.VERSION[2]}" 123 | ) 124 | -------------------------------------------------------------------------------- /ml-agents-dots-envs~/mlagents_dots_envs/string_side_channel.py: -------------------------------------------------------------------------------- 1 | from mlagents_envs.side_channel.side_channel import ( 2 | SideChannel, 3 | IncomingMessage, 4 | OutgoingMessage, 5 | ) 6 | import uuid 7 | 8 | 9 | # Create the StringLogChannel class 10 | class StringLogChannel(SideChannel): 11 | def __init__(self) -> None: 12 | super().__init__(uuid.UUID("621f0a70-4f87-11ea-a6bf-784f4387d1f7")) 13 | 14 | def on_message_received(self, msg: IncomingMessage) -> None: 15 | """ 16 | Note: We must implement this method of the SideChannel interface to 17 | receive messages from Unity 18 | """ 19 | # We simply read a string from the message and print it. 20 | print(msg.read_string()) 21 | 22 | def send_string(self, data: str) -> None: 23 | # Add the string to an OutgoingMessage 24 | msg = OutgoingMessage() 25 | msg.write_string(data) 26 | # We call this method to queue the data we want to send 27 | super().queue_message_to_send(msg) 28 | -------------------------------------------------------------------------------- /ml-agents-dots-envs~/mlagents_dots_envs/test/test_shared_memory.py: -------------------------------------------------------------------------------- 1 | import os 2 | import tempfile 3 | import numpy as np 4 | from mlagents_dots_envs.shared_memory.base_shared_memory import BaseSharedMemory 5 | 6 | 7 | def test_shared_memory(): 8 | file_path = os.path.join(tempfile.gettempdir(), "ml-agents", "test") 9 | 10 | sm0 = BaseSharedMemory("test", True, 256) 11 | sm1 = BaseSharedMemory("test", False) 12 | 13 | new_offset = sm0.set_int(0, 3) 14 | val, off = sm1.get_int(0) 15 | assert off == new_offset 16 | assert val == 3 17 | 18 | new_offset = sm0.set_float(0, 3) 19 | val, off = sm1.get_float(0) 20 | assert off == new_offset 21 | assert val == 3 22 | 23 | new_offset = sm0.set_bool(0, True) 24 | val, off = sm1.get_bool(0) 25 | assert off == new_offset 26 | assert val 27 | 28 | sm0.set_string(0, "foo") 29 | assert sm1.get_string(0)[0] == "foo" 30 | off = sm1.set_string(0, "bar") 31 | assert sm0.get_string(0)[0] == "bar" 32 | assert off == sm0.get_string(0)[1] 33 | 34 | src = np.array([1, 2, 3, 4], dtype=np.float32) 35 | sm0.set_ndarray(0, src) 36 | dst = sm1.get_ndarray(0, (4,), np.float32) 37 | assert np.array_equal(src, dst) 38 | 39 | sm0.close() 40 | assert os.path.exists(file_path) 41 | sm1.delete() 42 | assert not os.path.exists(file_path) 43 | -------------------------------------------------------------------------------- /ml-agents-dots-envs~/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup( 4 | name="mlagents_dots_envs", 5 | version="0.2.0-preview", 6 | description="Unity Machine Learning Agents Interface for DOTS", 7 | url="https://github.com/Unity-Technologies/ml-agents-dots", 8 | author="Unity Technologies", 9 | author_email="ML-Agents@unity3d.com", 10 | classifiers=[ 11 | "Intended Audience :: Developers", 12 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 13 | "Programming Language :: Python :: 3.6", 14 | "Programming Language :: Python :: 3.7", 15 | ], 16 | packages=find_packages( 17 | exclude=["*.tests", "*.tests.*", "tests.*", "tests", "examples"] 18 | ), 19 | zip_safe=False, 20 | install_requires=["mlagents_envs>=0.14.1"], 21 | python_requires=">=3.6", 22 | ) 23 | -------------------------------------------------------------------------------- /ml-agents-dots-learn~/mlagents_dots_learn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/ml-agents-dots/75d2e493822d5bb3da7a8713c50b61ab90fcfe7b/ml-agents-dots-learn~/mlagents_dots_learn/__init__.py -------------------------------------------------------------------------------- /ml-agents-dots-learn~/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup( 4 | name="mlagents_dots_learn", 5 | version="0.2.0-preview", 6 | description="Unity Machine Learning Agents Learner for DOTS", 7 | url="https://github.com/Unity-Technologies/ml-agents-dots", 8 | author="Unity Technologies", 9 | author_email="ML-Agents@unity3d.com", 10 | classifiers=[ 11 | "Intended Audience :: Developers", 12 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 13 | "Programming Language :: Python :: 3.6", 14 | "Programming Language :: Python :: 3.7", 15 | ], 16 | packages=find_packages( 17 | exclude=["*.tests", "*.tests.*", "tests.*", "tests", "examples"] 18 | ), 19 | zip_safe=False, 20 | install_requires=["mlagents_dots_envs>=0.2.0-preview", "mlagents>=0.25.0"], 21 | python_requires=">=3.6", 22 | entry_points={ 23 | "console_scripts": ["mlagents-dots-learn=mlagents_dots_learn.dots_learn:main"] 24 | }, 25 | ) 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.unity.ai.mlagents", 3 | "displayName": "DOTS ML-Agents", 4 | "version": "0.3.0-preview", 5 | "unity": "2019.3", 6 | "description": "Add interactivity to your game with ML-Agents trained using Deep Reinforcement Learning.", 7 | "dependencies": { 8 | "com.unity.barracuda": "2.0.0-pre.3", 9 | "com.unity.entities": "0.7.0-preview.19", 10 | "com.unity.jobs": "0.2.6-preview.13", 11 | "com.unity.mathematics": "1.1.0", 12 | "com.unity.collections": "0.6.0-preview.9" 13 | }, 14 | "samples": [ 15 | { 16 | "displayName":"3DBall", 17 | "description": "A thousands platforms trying to balance a ball", 18 | "createSeparatePackage": false, 19 | "path":"Samples~/3DBall" 20 | }, 21 | { 22 | "displayName":"Basic", 23 | "description": "Example of a MonoBehavior example integrated with the package", 24 | "createSeparatePackage": false, 25 | "path":"Samples~/Basic" 26 | }, 27 | { 28 | "displayName":"String Side Channel", 29 | "description": "An example of how to create and register side channels for communication with Python", 30 | "createSeparatePackage": false, 31 | "path":"Samples~/StringSideChannel" 32 | }, 33 | { 34 | "displayName":"Push The Block", 35 | "description": "An example of an Agent learning to push a block in a goal zone", 36 | "createSeparatePackage": false, 37 | "path":"Samples~/PushBlock" 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69b55ea773edb4e2db6545eaf7610245 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------