@@ -21,6 +21,11 @@ namespace Supyrb
21
21
/// </summary>
22
22
public class CommonCommands : WebCommands
23
23
{
24
+ /// <summary>
25
+ /// List that stores allocated byte arrays to prevent them from being garbage collected
26
+ /// </summary>
27
+ private List < byte [ ] > byteArrayMemory = new List < byte [ ] > ( ) ;
28
+
24
29
/// <summary>
25
30
/// Disable capturing all keyboard input, e.g. for using native html input fields
26
31
/// Browser Usage: <code>unityGame.SendMessage("WebGL","DisableCaptureAllKeyboardInput");</code>
@@ -58,6 +63,41 @@ public void LogMemory()
58
63
WebToolPlugins . LogMemory ( ) ;
59
64
}
60
65
66
+ /// <summary>
67
+ /// Allocate memory to test memory usage and limits
68
+ /// The memory will be stored in a list to prevent it from being garbage collected
69
+ /// </summary>
70
+ /// <param name="mb">MB to allocate</param>
71
+ [ WebCommand ( Description = "Allocate memory to test memory usage and limits" ) ]
72
+ public void AllocateByteArrayMemory ( int mb )
73
+ {
74
+ byte [ ] memory = new byte [ mb * 1024 * 1024 ] ;
75
+ byteArrayMemory . Add ( memory ) ;
76
+ Debug . Log ( $ "Allocated { mb } MB of memory, total memory usage: { WebToolPlugins . GetTotalMemorySize ( ) : 0.00} MB") ;
77
+ }
78
+
79
+ /// <summary>
80
+ /// Release all allocated byte array memory
81
+ /// </summary>
82
+ [ WebCommand ( Description = "Release all allocated byte array memory" ) ]
83
+ [ ContextMenu ( nameof ( ReleaseByteArrayMemory ) ) ]
84
+ public void ReleaseByteArrayMemory ( )
85
+ {
86
+ byteArrayMemory . Clear ( ) ;
87
+ Debug . Log ( "Released all allocated byte array memory, it can now be garbage collected" ) ;
88
+ }
89
+
90
+ /// <summary>
91
+ /// Trigger garbage collection
92
+ /// </summary>
93
+ [ WebCommand ( Description = "Trigger garbage collection" ) ]
94
+ [ ContextMenu ( nameof ( TriggerGarbageCollection ) ) ]
95
+ public void TriggerGarbageCollection ( )
96
+ {
97
+ GC . Collect ( ) ;
98
+ Debug . Log ( "Garbage collection triggered" ) ;
99
+ }
100
+
61
101
/// <summary>
62
102
/// Unloads all unused assets <see cref="Resources.UnloadUnusedAssets"/>
63
103
/// Browser Usage: <code>unityGame.SendMessage("WebGL","UnloadUnusedAssets");</code>
@@ -67,6 +107,7 @@ public void LogMemory()
67
107
public void UnloadUnusedAssets ( )
68
108
{
69
109
Resources . UnloadUnusedAssets ( ) ;
110
+ Debug . Log ( "Unloaded unused assets" ) ;
70
111
}
71
112
72
113
/// <summary>
@@ -79,6 +120,7 @@ public void UnloadUnusedAssets()
79
120
public void SetApplicationRunInBackground ( int runInBackground )
80
121
{
81
122
Application . runInBackground = runInBackground == 1 ;
123
+ Debug . Log ( $ "Application.runInBackground: { Application . runInBackground } ") ;
82
124
}
83
125
84
126
/// <summary>
@@ -90,6 +132,7 @@ public void SetApplicationRunInBackground(int runInBackground)
90
132
public void SetApplicationTargetFrameRate ( int targetFrameRate )
91
133
{
92
134
Application . targetFrameRate = targetFrameRate ;
135
+ Debug . Log ( $ "Application.targetFrameRate: { Application . targetFrameRate } ") ;
93
136
}
94
137
95
138
/// <summary>
@@ -101,6 +144,7 @@ public void SetApplicationTargetFrameRate(int targetFrameRate)
101
144
public void SetTimeFixedDeltaTime ( float fixedDeltaTime )
102
145
{
103
146
Time . fixedDeltaTime = fixedDeltaTime ;
147
+ Debug . Log ( $ "Time.fixedDeltaTime: { Time . fixedDeltaTime } ") ;
104
148
}
105
149
106
150
/// <summary>
@@ -113,6 +157,7 @@ public void SetTimeFixedDeltaTime(float fixedDeltaTime)
113
157
public void SetTimeTimeScale ( float timeScale )
114
158
{
115
159
Time . timeScale = timeScale ;
160
+ Debug . Log ( $ "Time.timeScale: { Time . timeScale } ") ;
116
161
}
117
162
118
163
/// <summary>
@@ -214,6 +259,7 @@ public void LogTextureSupport()
214
259
public void DeleteAllPlayerPrefs ( )
215
260
{
216
261
PlayerPrefs . DeleteAll ( ) ;
262
+ Debug . Log ( "Deleted all player prefs" ) ;
217
263
}
218
264
219
265
/// <summary>
@@ -226,6 +272,7 @@ public void DeleteAllPlayerPrefs()
226
272
public void LogShaderCompilation ( int enabled )
227
273
{
228
274
GraphicsSettings . logWhenShaderIsCompiled = enabled == 1 ;
275
+ Debug . Log ( $ "GraphicsSettings.logWhenShaderIsCompiled: { GraphicsSettings . logWhenShaderIsCompiled } ") ;
229
276
}
230
277
}
231
278
}
0 commit comments