diff --git a/UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta b/UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta index 2a461c7267..3163a0cdcb 100644 --- a/UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta +++ b/UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta @@ -8,23 +8,99 @@ PluginImporter: isPreloaded: 0 isOverridable: 0 platformData: + - first: + '': Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude Linux: 0 + Exclude Linux64: 0 + Exclude LinuxUniversal: 0 + Exclude OSXUniversal: 0 + Exclude Win: 0 + Exclude Win64: 0 + Exclude iOS: 1 + - first: + Android: Android + second: + enabled: 0 + settings: + CPU: ARMv7 - first: Any: second: - enabled: 1 + enabled: 0 settings: {} - first: Editor: Editor second: - enabled: 0 + enabled: 1 settings: + CPU: AnyCPU DefaultValueInitialized: true + OS: AnyOS + - first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Linux + second: + enabled: 1 + settings: + CPU: x86 + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: x86_64 + - first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: {} + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU - first: Windows Store Apps: WindowsStoreApps second: enabled: 0 settings: CPU: AnyCPU + - first: + iPhone: iOS + second: + enabled: 0 + settings: + CompileFlags: + FrameworkDependencies: userData: assetBundleName: assetBundleVariant: diff --git a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs index e266ac4935..bf738cbd7a 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs @@ -2,6 +2,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: mlagents/envs/communicator_objects/unity_to_external.proto // + +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX + #pragma warning disable 1591 #region Designer generated code @@ -128,3 +131,6 @@ protected override UnityToExternalClient NewInstance(ClientBaseConfiguration con } } #endregion + +#endif + diff --git a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs index 4a1b2fde10..f35cb8c60e 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs @@ -1,4 +1,6 @@ +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX using Grpc.Core; +#endif using System.IO; using System.Threading; using System.Threading.Tasks; @@ -16,9 +18,10 @@ public class RPCCommunicator : Communicator /// If true, the communication is active. bool m_isOpen; +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX /// The Unity to External client. UnityToExternal.UnityToExternalClient m_client; - +#endif /// The communicator parameters sent at construction CommunicatorParameters m_communicatorParameters; @@ -41,6 +44,7 @@ public RPCCommunicator(CommunicatorParameters communicatorParameters) public UnityInput Initialize(UnityOutput unityOutput, out UnityInput unityInput) { +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX m_isOpen = true; var channel = new Channel( "localhost:"+m_communicatorParameters.port, @@ -57,6 +61,10 @@ public UnityInput Initialize(UnityOutput unityOutput, #endif #endif return result.UnityInput; +#else + throw new UnityAgentsException( + "You cannot perform training on this platform."); +#endif } /// @@ -64,6 +72,7 @@ public UnityInput Initialize(UnityOutput unityOutput, /// public void Close() { +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX if (!m_isOpen) { return; @@ -78,6 +87,10 @@ public void Close() { return; } +#else + throw new UnityAgentsException( + "You cannot perform training on this platform."); +#endif } /// @@ -87,6 +100,7 @@ public void Close() /// The UnityOutput to be sent. public UnityInput Exchange(UnityOutput unityOutput) { +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX if (!m_isOpen) { return null; @@ -109,6 +123,10 @@ public UnityInput Exchange(UnityOutput unityOutput) m_isOpen = false; return null; } +#else + throw new UnityAgentsException( + "You cannot perform training on this platform."); +#endif } /// diff --git a/UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs b/UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs index bd13e1751a..a2e6ca6f0e 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs @@ -1,5 +1,4 @@ using Google.Protobuf; -using Grpc.Core; using System.Net.Sockets; using UnityEngine; using MLAgents.CommunicatorObjects; diff --git a/protobuf-definitions/README.md b/protobuf-definitions/README.md index 5141828f42..bc4ca01e92 100644 --- a/protobuf-definitions/README.md +++ b/protobuf-definitions/README.md @@ -26,3 +26,15 @@ On Windows & Linux: [See here](https://github.com/google/protobuf/blob/master/sr 1. Install pre-requisites. 2. Un-comment line 4 in `make.bat`, and set to correct Grpc.Tools sub-directory. 3. Run `make.bat` +4. In the generated `UnityToExternalGrpc.cs` file in the `UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects` folder, you will need to add the following to the beginning of the file + +```csharp +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +``` + and the following line to the end + + ```csharp + #endif + ``` +This is to make sure the generated code does not try to access the Grpc library +on platforms that are not supported by Grpc.