Skip to content

Commit 0b8db7e

Browse files
committed
Add webgpu for newer unity versions
1 parent 1d098da commit 0b8db7e

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

Assets/Plugins/WebGL/WebTools/WebBridge.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ private static void SetGlobalVariables()
4545
case GraphicsDeviceType.OpenGLES3:
4646
webGraphics = "WebGL 2";
4747
break;
48+
#if UNITY_2023_2_OR_NEWER
49+
case GraphicsDeviceType.WebGPU:
50+
webGraphics = "WebGPU";
51+
break;
52+
#endif
4853
default:
4954
webGraphics = graphicsDevice.ToString();
5055
break;

Assets/Scripts/Editor/BuildScript.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,32 @@ public static void Build(string[] args)
121121
SetWebGlOptimization("speed");
122122
}
123123

124-
if (tagParameters.Contains("webgl2") && !tagParameters.Contains("webgl1"))
124+
List<GraphicsDeviceType> graphicsAPIs = new List<GraphicsDeviceType>();
125+
if (tagParameters.Contains("webgl1"))
125126
{
126-
PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, new[] { GraphicsDeviceType.OpenGLES3 });
127+
graphicsAPIs.Add(GraphicsDeviceType.OpenGLES2);
127128
}
128-
129-
if (tagParameters.Contains("webgl1") && !tagParameters.Contains("webgl2"))
129+
if(tagParameters.Contains("webgl2"))
130130
{
131-
PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, new[] { GraphicsDeviceType.OpenGLES2 });
131+
graphicsAPIs.Add(GraphicsDeviceType.OpenGLES3);
132132
}
133-
134-
if (tagParameters.Contains("webgl1") && tagParameters.Contains("webgl2"))
133+
if(tagParameters.Contains("webgpu"))
135134
{
136-
PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, new[] { GraphicsDeviceType.OpenGLES2, GraphicsDeviceType.OpenGLES3 });
135+
#if UNITY_2023_2_OR_NEWER
136+
graphicsAPIs.Add(GraphicsDeviceType.WebGPU);
137+
#else
138+
LogError("WebGPU not supported yet");
139+
#endif
137140
}
138141

139-
#if UNITY_2023_1_OR_NEWER
142+
PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, graphicsAPIs.ToArray());
143+
144+
#if UNITY_2023_1_OR_NEWER
140145
if (tagParameters.Contains("webgl1"))
141146
{
142147
Log("WebGL1 not supported anymore, choosing WebGL2 instead");
143148
}
144-
#endif
149+
#endif
145150
}
146151

147152
break;

Assets/Scripts/Editor/BuildScriptMenu.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,34 @@ public static void BuildWebGL2MinSize()
8383
BuildWithParameters(parameters);
8484
}
8585

86+
#if UNITY_2023_2_OR_NEWER
87+
[MenuItem("Tools/Build WebGL/webgpu")]
88+
public static void BuildWebGpu()
89+
{
90+
var parameters = new List<string>(baseParameters);
91+
string tag = $"{Application.unityVersion}-webgpu-manualBuild";
92+
SetBuildTarget(BuildTarget.WebGL, ref parameters);
93+
SetParameterValue("-autorunplayer", "true", ref parameters);
94+
SetParameterValue("-tag", tag, ref parameters);
95+
SetParameterValue("-customBuildPath", $"Builds/WebGL/{tag}", ref parameters);
96+
SetParameterValue("-customBuildName", tag, ref parameters);
97+
BuildWithParameters(parameters);
98+
}
99+
100+
[MenuItem("Tools/Build WebGL/minsize-webgpu")]
101+
public static void BuildWebGpuMinSize()
102+
{
103+
var parameters = new List<string>(baseParameters);
104+
string tag = $"{Application.unityVersion}-minsize-webgpu-manualBuild";
105+
SetBuildTarget(BuildTarget.WebGL, ref parameters);
106+
SetParameterValue("-autorunplayer", "true", ref parameters);
107+
SetParameterValue("-tag", tag, ref parameters);
108+
SetParameterValue("-customBuildPath", $"Builds/WebGL/{tag}", ref parameters);
109+
SetParameterValue("-customBuildName", tag, ref parameters);
110+
BuildWithParameters(parameters);
111+
}
112+
#endif
113+
86114
[MenuItem("Tools/Build WebGL/debug")]
87115
public static void BuildWebGLDebug()
88116
{

0 commit comments

Comments
 (0)