1
- # if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
1
+ #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
2
2
using Grpc . Core ;
3
- #endif
4
3
#if UNITY_EDITOR
5
4
using UnityEditor ;
6
5
#endif
@@ -44,23 +43,17 @@ internal class RpcCommunicator : ICommunicator
44
43
Dictionary < string , ActionSpec > m_UnsentBrainKeys = new Dictionary < string , ActionSpec > ( ) ;
45
44
46
45
47
- #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
48
46
/// The Unity to External client.
49
47
UnityToExternalProto . UnityToExternalProtoClient m_Client ;
50
- #endif
51
- /// The communicator parameters sent at construction
52
- CommunicatorInitParameters m_CommunicatorInitParameters ;
53
48
54
49
/// <summary>
55
50
/// Initializes a new instance of the RPCCommunicator class.
56
51
/// </summary>
57
- /// <param name="communicatorInitParameters">Communicator parameters.</param>
58
- public RpcCommunicator ( CommunicatorInitParameters communicatorInitParameters )
52
+ public RpcCommunicator ( )
59
53
{
60
- m_CommunicatorInitParameters = communicatorInitParameters ;
61
54
}
62
55
63
- #region Initialization
56
+ #region Initialization
64
57
65
58
internal static bool CheckCommunicationVersionsAreCompatible (
66
59
string unityCommunicationVersion ,
@@ -110,6 +103,7 @@ public bool Initialize(CommunicatorInitParameters initParameters, out UnityRLIni
110
103
try
111
104
{
112
105
initializationInput = Initialize (
106
+ initParameters . port ,
113
107
new UnityOutputProto
114
108
{
115
109
RlInitializationOutput = academyParameters
@@ -211,13 +205,10 @@ void UpdateEnvironmentWithInput(UnityRLInputProto rlInput)
211
205
SendCommandEvent ( rlInput . Command ) ;
212
206
}
213
207
214
- UnityInputProto Initialize ( UnityOutputProto unityOutput , out UnityInputProto unityInput )
208
+ UnityInputProto Initialize ( int port , UnityOutputProto unityOutput , out UnityInputProto unityInput )
215
209
{
216
- #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
217
210
m_IsOpen = true ;
218
- var channel = new Channel (
219
- "localhost:" + m_CommunicatorInitParameters . port ,
220
- ChannelCredentials . Insecure ) ;
211
+ var channel = new Channel ( $ "localhost:{ port } ", ChannelCredentials . Insecure ) ;
221
212
222
213
m_Client = new UnityToExternalProto . UnityToExternalProtoClient ( channel ) ;
223
214
var result = m_Client . Exchange ( WrapMessage ( unityOutput , 200 ) ) ;
@@ -232,21 +223,17 @@ UnityInputProto Initialize(UnityOutputProto unityOutput, out UnityInputProto uni
232
223
QuitCommandReceived ? . Invoke ( ) ;
233
224
}
234
225
return result . UnityInput ;
235
- #else
236
- throw new UnityAgentsException ( "You cannot perform training on this platform." ) ;
237
- #endif
238
226
}
239
227
240
- #endregion
228
+ #endregion
241
229
242
- #region Destruction
230
+ #region Destruction
243
231
244
232
/// <summary>
245
233
/// Close the communicator gracefully on both sides of the communication.
246
234
/// </summary>
247
235
public void Dispose ( )
248
236
{
249
- #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
250
237
if ( ! m_IsOpen )
251
238
{
252
239
return ;
@@ -261,15 +248,11 @@ public void Dispose()
261
248
{
262
249
// ignored
263
250
}
264
- #else
265
- throw new UnityAgentsException (
266
- "You cannot perform training on this platform." ) ;
267
- #endif
268
251
}
269
252
270
- #endregion
253
+ #endregion
271
254
272
- #region Sending Events
255
+ #region Sending Events
273
256
274
257
void SendCommandEvent ( CommandProto command )
275
258
{
@@ -296,9 +279,9 @@ void SendCommandEvent(CommandProto command)
296
279
}
297
280
}
298
281
299
- #endregion
282
+ #endregion
300
283
301
- #region Sending and retreiving data
284
+ #region Sending and retreiving data
302
285
303
286
public void DecideBatch ( )
304
287
{
@@ -447,7 +430,6 @@ public ActionBuffers GetActions(string behaviorName, int agentId)
447
430
/// <param name="unityOutput">The UnityOutput to be sent.</param>
448
431
UnityInputProto Exchange ( UnityOutputProto unityOutput )
449
432
{
450
- #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
451
433
if ( ! m_IsOpen )
452
434
{
453
435
return null ;
@@ -500,10 +482,6 @@ UnityInputProto Exchange(UnityOutputProto unityOutput)
500
482
QuitCommandReceived ? . Invoke ( ) ;
501
483
return null ;
502
484
}
503
- #else
504
- throw new UnityAgentsException (
505
- "You cannot perform training on this platform." ) ;
506
- #endif
507
485
}
508
486
509
487
/// <summary>
@@ -573,7 +551,7 @@ void UpdateSentActionSpec(UnityRLInitializationOutputProto output)
573
551
}
574
552
}
575
553
576
- #endregion
554
+ #endregion
577
555
578
556
#if UNITY_EDITOR
579
557
/// <summary>
@@ -592,3 +570,4 @@ void HandleOnPlayModeChanged(PlayModeStateChange state)
592
570
#endif
593
571
}
594
572
}
573
+ #endif // UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
0 commit comments