Skip to content

Commit eb5e812

Browse files
committed
fix: async Task based logic to IEnuemrator logic on WebpAnimation.cs for WebGL build
- ref: https://forum.unity.com/threads/async-await-and-webgl-builds.472994/
1 parent f749713 commit eb5e812

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

unity_project/Assets/Samples/example2/WebpAnimation.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
3-
using System.Threading.Tasks;
44
using unity.libwebp;
55
using unity.libwebp.Interop;
66
using UnityEngine;
@@ -12,7 +12,7 @@ public class WebpAnimation : MonoBehaviour
1212
{
1313
public RawImage image2;
1414

15-
private async void Start()
15+
private IEnumerator Start()
1616
{
1717
List<(Texture2D, int)> lst = LoadAnimation("cat");
1818

@@ -22,22 +22,25 @@ private async void Start()
2222
(Texture2D texture, int timestamp) = lst[i];
2323
if (image2 == null)
2424
{
25-
return;
25+
yield break;
2626
}
2727
image2.texture = texture;
2828
int delay = timestamp - prevTimestamp;
2929
prevTimestamp = timestamp;
30+
3031
if (delay < 0)
3132
{
3233
delay = 0;
3334
}
34-
await Task.Delay(delay);
35+
36+
yield return new WaitForSeconds(delay / 1000.0f);
3537
if (i == lst.Count - 1)
3638
{
3739
i = -1;
3840
}
3941
}
4042
}
43+
4144
private unsafe List<(Texture2D, int)> LoadAnimation(string loadPath)
4245
{
4346
List<(Texture2D, int)> ret = new List<(Texture2D, int)>();

unity_project/ProjectSettings/EditorBuildSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ EditorBuildSettings:
66
serializedVersion: 2
77
m_Scenes:
88
- enabled: 1
9-
path: Assets/example2/animation.unity
9+
path: Assets/Samples/example2/animation.unity
1010
guid: 543921e829fddb948a8c0611f462aaca
1111
m_configObjects: {}

unity_project/ProjectSettings/ProjectSettings.asset

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
--- !u!129 &1
44
PlayerSettings:
55
m_ObjectHideFlags: 0
6-
serializedVersion: 22
6+
serializedVersion: 23
77
productGUID: ba93c09bd9b834fdbb5f25615402aea6
88
AndroidProfiler: 0
99
AndroidFilterTouchesWhenObscured: 0
@@ -145,11 +145,13 @@ PlayerSettings:
145145
enable360StereoCapture: 0
146146
isWsaHolographicRemotingEnabled: 0
147147
enableFrameTimingStats: 0
148+
enableOpenGLProfilerGPURecorders: 1
148149
useHDRDisplay: 0
149150
D3DHDRBitDepth: 0
150151
m_ColorGamuts: 00000000
151152
targetPixelDensity: 30
152153
resolutionScalingMode: 0
154+
resetResolutionOnWindowResize: 0
153155
androidSupportedAspectRatio: 1
154156
androidMaxAspectRatio: 2.1
155157
applicationIdentifier:
@@ -160,7 +162,7 @@ PlayerSettings:
160162
tvOS: 0
161163
overrideDefaultApplicationIdentifier: 0
162164
AndroidBundleVersionCode: 1
163-
AndroidMinSdkVersion: 19
165+
AndroidMinSdkVersion: 22
164166
AndroidTargetSdkVersion: 0
165167
AndroidPreferredInstallLocation: 1
166168
aotOptions:
@@ -216,6 +218,7 @@ PlayerSettings:
216218
iOSLaunchScreeniPadCustomStoryboardPath:
217219
iOSDeviceRequirements: []
218220
iOSURLSchemes: []
221+
macOSURLSchemes: []
219222
iOSBackgroundModes: 0
220223
iOSMetalForceHardShadows: 0
221224
metalEditorSupport: 0
@@ -405,6 +408,9 @@ PlayerSettings:
405408
- m_BuildTarget: iOSSupport
406409
m_APIs: 10000000
407410
m_Automatic: 1
411+
- m_BuildTarget: AndroidPlayer
412+
m_APIs: 0b00000008000000
413+
m_Automatic: 0
408414
m_BuildTargetVRSettings: []
409415
openGLRequireES31: 0
410416
openGLRequireES31AEP: 0
@@ -422,6 +428,7 @@ PlayerSettings:
422428
m_EncodingQuality: 1
423429
m_BuildTargetGroupLightmapSettings: []
424430
m_BuildTargetNormalMapEncoding: []
431+
m_BuildTargetDefaultTextureCompressionFormat: []
425432
playModeTestRunnerEnabled: 0
426433
runPlayModeTestAsEditModeTest: 0
427434
actionOnDotNetUnhandledException: 1
@@ -440,6 +447,7 @@ PlayerSettings:
440447
switchScreenResolutionBehavior: 2
441448
switchUseCPUProfiler: 0
442449
switchUseGOLDLinker: 0
450+
switchLTOSetting: 0
443451
switchApplicationID: 0x01004b9000490000
444452
switchNSODependencies:
445453
switchTitleNames_0:
@@ -570,7 +578,9 @@ PlayerSettings:
570578
switchPlayerConnectionEnabled: 1
571579
switchUseNewStyleFilepaths: 0
572580
switchUseMicroSleepForYield: 1
581+
switchEnableRamDiskSupport: 0
573582
switchMicroSleepForYieldTime: 25
583+
switchRamDiskSpaceSize: 12
574584
ps4NPAgeRating: 12
575585
ps4NPTitleSecret:
576586
ps4NPTrophyPackPath:
@@ -641,7 +651,6 @@ PlayerSettings:
641651
ps4videoRecordingFeaturesUsed: 0
642652
ps4contentSearchFeaturesUsed: 0
643653
ps4CompatibilityPS5: 0
644-
ps4AllowPS5Detection: 0
645654
ps4GPU800MHz: 1
646655
ps4attribEyeToEyeDistanceSettingVR: 0
647656
ps4IncludedModules: []
@@ -661,7 +670,7 @@ PlayerSettings:
661670
webGLTemplate: APPLICATION:Default
662671
webGLAnalyzeBuildSize: 0
663672
webGLUseEmbeddedResources: 0
664-
webGLCompressionFormat: 1
673+
webGLCompressionFormat: 2
665674
webGLWasmArithmeticExceptions: 0
666675
webGLLinkerTarget: 1
667676
webGLThreadsSupport: 0
@@ -677,7 +686,6 @@ PlayerSettings:
677686
suppressCommonWarnings: 1
678687
allowUnsafeCode: 1
679688
useDeterministicCompilation: 1
680-
useReferenceAssemblies: 1
681689
enableRoslynAnalyzers: 1
682690
additionalIl2CppArgs:
683691
scriptingRuntimeVersion: 1
@@ -714,6 +722,7 @@ PlayerSettings:
714722
metroFTAName:
715723
metroFTAFileTypes: []
716724
metroProtocolName:
725+
vcxProjDefaultLanguage:
717726
XboxOneProductId:
718727
XboxOneUpdateKey:
719728
XboxOneSandboxId:
@@ -763,4 +772,6 @@ PlayerSettings:
763772
organizationId:
764773
cloudEnabled: 0
765774
legacyClampBlendShapeWeights: 1
775+
playerDataPath:
776+
forceSRGBBlit: 1
766777
virtualTexturingSupportEnabled: 0

0 commit comments

Comments
 (0)