Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 78 additions & 2 deletions UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: mlagents/envs/communicator_objects/unity_to_external.proto
// </auto-generated>

# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX

#pragma warning disable 1591
#region Designer generated code

Expand Down Expand Up @@ -128,3 +131,6 @@ protected override UnityToExternalClient NewInstance(ClientBaseConfiguration con
}
}
#endregion

#endif

20 changes: 19 additions & 1 deletion UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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,
Expand All @@ -57,13 +61,18 @@ public UnityInput Initialize(UnityOutput unityOutput,
#endif
#endif
return result.UnityInput;
#else
throw new UnityAgentsException(
"You cannot perform training on this platform.");
#endif
}

/// <summary>
/// Close the communicator gracefully on both sides of the communication.
/// </summary>
public void Close()
{
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
if (!m_isOpen)
{
return;
Expand All @@ -78,6 +87,10 @@ public void Close()
{
return;
}
#else
throw new UnityAgentsException(
"You cannot perform training on this platform.");
#endif
}

/// <summary>
Expand All @@ -87,6 +100,7 @@ public void Close()
/// <param name="unityOutput">The UnityOutput to be sent.</param>
public UnityInput Exchange(UnityOutput unityOutput)
{
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
if (!m_isOpen)
{
return null;
Expand All @@ -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
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Google.Protobuf;
using Grpc.Core;
using System.Net.Sockets;
using UnityEngine;
using MLAgents.CommunicatorObjects;
Expand Down
12 changes: 12 additions & 0 deletions protobuf-definitions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.