17
17
18
18
namespace Unity . MLAgents . Analytics
19
19
{
20
- internal class TrainingAnalytics
20
+ internal static class TrainingAnalytics
21
21
{
22
22
const string k_VendorKey = "unity.ml-agents" ;
23
23
const string k_TrainingEnvironmentInitializedEventName = "ml_agents_training_environment_initialized" ;
@@ -31,11 +31,6 @@ internal class TrainingAnalytics
31
31
k_RemotePolicyInitializedEventName
32
32
} ;
33
33
34
- /// <summary>
35
- /// Whether or not we've registered this particular event yet
36
- /// </summary>
37
- static bool s_EventsRegistered = false ;
38
-
39
34
/// <summary>
40
35
/// Hourly limit for this event name
41
36
/// </summary>
@@ -47,36 +42,40 @@ internal class TrainingAnalytics
47
42
const int k_MaxNumberOfElements = 1000 ;
48
43
49
44
private static bool s_SentEnvironmentInitialized ;
45
+
46
+ #if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
47
+ /// <summary>
48
+ /// Whether or not we've registered this particular event yet
49
+ /// </summary>
50
+ static bool s_EventsRegistered = false ;
51
+
50
52
/// <summary>
51
53
/// Behaviors that we've already sent events for.
52
54
/// </summary>
53
55
private static HashSet < string > s_SentRemotePolicyInitialized ;
54
56
private static HashSet < string > s_SentTrainingBehaviorInitialized ;
57
+ #endif
55
58
56
59
private static Guid s_TrainingSessionGuid ;
57
60
58
61
// These are set when the RpcCommunicator connects
59
62
private static string s_TrainerPackageVersion = "" ;
60
63
private static string s_TrainerCommunicationVersion = "" ;
61
64
62
- static bool EnableAnalytics ( )
65
+ internal static bool EnableAnalytics ( )
63
66
{
64
- #if MLA_UNITY_ANALYTICS_MODULE
67
+ #if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
65
68
if ( s_EventsRegistered )
66
69
{
67
70
return true ;
68
71
}
69
72
foreach ( var eventName in s_EventNames )
70
73
{
71
- #if UNITY_EDITOR
72
74
AnalyticsResult result = EditorAnalytics . RegisterEventWithLimit ( eventName , k_MaxEventsPerHour , k_MaxNumberOfElements , k_VendorKey ) ;
73
75
if ( result != AnalyticsResult . Ok )
74
76
{
75
77
return false ;
76
78
}
77
- #else
78
- return false ;
79
- #endif // UNITY_EDITOR
80
79
}
81
80
s_EventsRegistered = true ;
82
81
@@ -152,6 +151,7 @@ public static void RemotePolicyInitialized(
152
151
IList < IActuator > actuators
153
152
)
154
153
{
154
+ #if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
155
155
if ( ! IsAnalyticsEnabled ( ) )
156
156
return ;
157
157
@@ -173,7 +173,6 @@ IList<IActuator> actuators
173
173
// Debug.Log(
174
174
// $"Would send event {k_RemotePolicyInitializedEventName} with body {JsonUtility.ToJson(data, true)}"
175
175
// );
176
- #if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
177
176
if ( AnalyticsUtils . s_SendEditorAnalytics )
178
177
{
179
178
EditorAnalytics . SendEventWithLimit ( k_RemotePolicyInitializedEventName , data ) ;
@@ -196,6 +195,7 @@ internal static string ParseBehaviorName(string fullyQualifiedBehaviorName)
196
195
[ Conditional ( "MLA_UNITY_ANALYTICS_MODULE" ) ]
197
196
public static void TrainingBehaviorInitialized ( TrainingBehaviorInitializedEvent tbiEvent )
198
197
{
198
+ #if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
199
199
if ( ! IsAnalyticsEnabled ( ) )
200
200
return ;
201
201
@@ -219,13 +219,10 @@ public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent
219
219
// Debug.Log(
220
220
// $"Would send event {k_TrainingBehaviorInitializedEventName} with body {JsonUtility.ToJson(tbiEvent, true)}"
221
221
// );
222
- #if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
223
222
if ( AnalyticsUtils . s_SendEditorAnalytics )
224
223
{
225
224
EditorAnalytics . SendEventWithLimit ( k_TrainingBehaviorInitializedEventName , tbiEvent ) ;
226
225
}
227
- #else
228
- return ;
229
226
#endif
230
227
}
231
228
0 commit comments