Skip to content

Commit

Permalink
update defines, compile out Initialize body on non-desktop (#4957)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Elion committed Feb 18, 2021
1 parent afdf754 commit 68fa146
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#define MLA_SUPPORTED_TRAINING_PLATFORM
#endif

# if MLA_SUPPORTED_TRAINING_PLATFORM
using Grpc.Core;
#endif
#if UNITY_EDITOR
Expand Down Expand Up @@ -44,7 +48,7 @@ internal class RpcCommunicator : ICommunicator
Dictionary<string, ActionSpec> m_UnsentBrainKeys = new Dictionary<string, ActionSpec>();


#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if MLA_SUPPORTED_TRAINING_PLATFORM
/// The Unity to External client.
UnityToExternalProto.UnityToExternalProtoClient m_Client;
#endif
Expand Down Expand Up @@ -97,6 +101,7 @@ string pythonApiVersion
/// <param name="initParametersOut">The External Initialization Parameters received.</param>
public bool Initialize(CommunicatorInitParameters initParameters, out UnityRLInitParameters initParametersOut)
{
#if MLA_SUPPORTED_TRAINING_PLATFORM
var academyParameters = new UnityRLInitializationOutputProto
{
Name = initParameters.name,
Expand Down Expand Up @@ -183,6 +188,10 @@ out input
UpdateEnvironmentWithInput(input.RlInput);
initParametersOut = initializationInput.RlInitializationInput.ToUnityRLInitParameters();
return true;
#else
initParametersOut = new UnityRLInitParameters();
return false;
#endif
}

/// <summary>
Expand Down Expand Up @@ -213,7 +222,7 @@ void UpdateEnvironmentWithInput(UnityRLInputProto rlInput)

UnityInputProto Initialize(UnityOutputProto unityOutput, out UnityInputProto unityInput)
{
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if MLA_SUPPORTED_TRAINING_PLATFORM
m_IsOpen = true;
var channel = new Channel(
"localhost:" + m_CommunicatorInitParameters.port,
Expand Down Expand Up @@ -246,7 +255,7 @@ UnityInputProto Initialize(UnityOutputProto unityOutput, out UnityInputProto uni
/// </summary>
public void Dispose()
{
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if MLA_SUPPORTED_TRAINING_PLATFORM
if (!m_IsOpen)
{
return;
Expand Down Expand Up @@ -447,7 +456,7 @@ public ActionBuffers GetActions(string behaviorName, int agentId)
/// <param name="unityOutput">The UnityOutput to be sent.</param>
UnityInputProto Exchange(UnityOutputProto unityOutput)
{
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if MLA_SUPPORTED_TRAINING_PLATFORM
if (!m_IsOpen)
{
return null;
Expand Down

0 comments on commit 68fa146

Please sign in to comment.