9
9
// --------------------------------------------------------------------------------------------------------------------
10
10
11
11
using System ;
12
+ using System . Reflection ;
13
+ using System . Text ;
14
+ using Supyrb . Attributes ;
12
15
using UnityEngine ;
13
16
using UnityEngine . Rendering ;
14
17
@@ -53,22 +56,45 @@ private void Start()
53
56
Debug . Log ( "Unity WebGL Bridge ready -> Run 'unityGame.SendMessage(\" WebGL\" , \" Help\" )' in the browser console to see usage" ) ;
54
57
}
55
58
59
+ [ ContextMenu ( "Log all commands" ) ]
60
+ [ WebGlCommand ( Description = "Log all available commands" ) ]
56
61
public void Help ( )
57
62
{
58
- Debug . Log ( "Available unity interfaces:\n " +
59
- "- LogMemory() -> logs current memory\n " +
60
- "- SetApplicationRunInBackground(int runInBackground) -> Application.runInBackground\n " +
61
- "- SetApplicationTargetFrameRate(int targetFrameRate) -> Application.targetFrameRate\n " +
62
- "- SetTimeFixedDeltaTime(float fixedDeltaTime) -> Time.fixedDeltaTime\n " +
63
- "- SetTimeTimeScale(float timeScale) -> Time.timeScale\n " +
64
- "- ToggleInfoPanel() -> Toggle develop ui visibility of InfoPanel\n " +
65
- "\n Run a command through 'unityGame.SendMessage(\" WebGL\" , \" COMMAND_NAME\" ,PARAMETER)'" ) ;
63
+ StringBuilder sb = new StringBuilder ( ) ;
64
+ MethodInfo [ ] methods = GetType ( ) . GetMethods ( BindingFlags . Public | BindingFlags . Instance ) ;
65
+
66
+ sb . AppendLine ( "Available unity interfaces:" ) ;
67
+ for ( int i = 0 ; i < methods . Length ; i ++ )
68
+ {
69
+ var method = methods [ i ] ;
70
+ WebGlCommandAttribute commandAttribute = method . GetCustomAttribute < WebGlCommandAttribute > ( ) ;
71
+ if ( commandAttribute != null )
72
+ {
73
+ sb . Append ( $ "- { method . Name } (") ;
74
+ ParameterInfo [ ] parameters = method . GetParameters ( ) ;
75
+ for ( int j = 0 ; j < parameters . Length ; j ++ )
76
+ {
77
+ var parameter = parameters [ j ] ;
78
+ sb . Append ( $ "{ parameter . ParameterType } { parameter . Name } ") ;
79
+ if ( j < parameters . Length - 1 )
80
+ {
81
+ sb . Append ( ", " ) ;
82
+ }
83
+ }
84
+
85
+ sb . AppendLine ( $ ") -> { commandAttribute . Description } ") ;
86
+ }
87
+ }
88
+
89
+ sb . AppendLine ( "\n Run a command with 'unityGame.SendMessage(\" WebGL\" , \" COMMAND_NAME\" ,PARAMETER)'" ) ;
90
+ Debug . Log ( sb . ToString ( ) ) ;
66
91
}
67
92
68
93
/// <summary>
69
94
/// Logs the current memory usage
70
95
/// Browser Usage: <code>unityGame.SendMessage("WebGL","LogMemory");</code>
71
96
/// </summary>
97
+ [ WebGlCommand ( Description = "Logs the current memory" ) ]
72
98
public void LogMemory ( )
73
99
{
74
100
WebGlPlugins . LogMemory ( ) ;
@@ -80,6 +106,7 @@ public void LogMemory()
80
106
/// Browser Usage: <code>unityGame.SendMessage("WebGL", "SetApplicationRunInBackground", 1);</code>
81
107
/// </summary>
82
108
/// <param name="runInBackground">1 if it should run in background</param>
109
+ [ WebGlCommand ( Description = "Application.runInBackground" ) ]
83
110
public void SetApplicationRunInBackground ( int runInBackground )
84
111
{
85
112
Application . runInBackground = runInBackground == 1 ;
@@ -90,6 +117,7 @@ public void SetApplicationRunInBackground(int runInBackground)
90
117
/// Browser Usage: <code>unityGame.SendMessage("WebGL", "SetApplicationTargetFrameRate", 15);</code>
91
118
/// </summary>
92
119
/// <param name="targetFrameRate">frame rate to render in</param>
120
+ [ WebGlCommand ( Description = "Application.targetFrameRate" ) ]
93
121
public void SetApplicationTargetFrameRate ( int targetFrameRate )
94
122
{
95
123
Application . targetFrameRate = targetFrameRate ;
@@ -100,6 +128,7 @@ public void SetApplicationTargetFrameRate(int targetFrameRate)
100
128
/// Browser Usage: <code>unityGame.SendMessage("WebGL", "SetTimeFixedDeltaTime", 0.02);</code>
101
129
/// </summary>
102
130
/// <param name="fixedDeltaTime"></param>
131
+ [ WebGlCommand ( Description = "Time.fixedDeltaTime" ) ]
103
132
public void SetTimeFixedDeltaTime ( float fixedDeltaTime )
104
133
{
105
134
Time . fixedDeltaTime = fixedDeltaTime ;
@@ -111,6 +140,7 @@ public void SetTimeFixedDeltaTime(float fixedDeltaTime)
111
140
/// Browser Usage: <code>unityGame.SendMessage("WebGL", "SetTimeTimeScale", 0.2);</code>
112
141
/// </summary>
113
142
/// <param name="timeScale">new timescale value</param>
143
+ [ WebGlCommand ( Description = "Time.timeScale" ) ]
114
144
public void SetTimeTimeScale ( float timeScale )
115
145
{
116
146
Time . timeScale = timeScale ;
@@ -119,6 +149,7 @@ public void SetTimeTimeScale(float timeScale)
119
149
/// <summary>
120
150
/// Toggle the visibility of the info panel in the top right corner
121
151
/// </summary>
152
+ [ WebGlCommand ( Description = "Toggle develop ui visibility of InfoPanel" ) ]
122
153
public void ToggleInfoPanel ( )
123
154
{
124
155
WebGlPlugins . ToggleInfoPanel ( ) ;
0 commit comments