@@ -76,12 +76,7 @@ public void OnGUI()
76
76
RunIEnumeratorTryCatchExceptionAsync ( ) . WrapErrors ( ) ;
77
77
}
78
78
79
- if ( _buttonHandler . Display ( "Load assetbundle with StartCoroutine" ) )
80
- {
81
- StartCoroutine ( RunAsyncOperation2 ( ) ) ;
82
- }
83
-
84
- if ( _buttonHandler . Display ( "Load assetbundle with async await" ) )
79
+ if ( _buttonHandler . Display ( "Load assetbundle" ) )
85
80
{
86
81
RunAsyncOperationAsync ( ) . WrapErrors ( ) ;
87
82
}
@@ -106,11 +101,6 @@ public void OnGUI()
106
101
RunWwwAsync ( ) . WrapErrors ( ) ;
107
102
}
108
103
109
- if ( _buttonHandler . Display ( "Test www download coroutines" ) )
110
- {
111
- StartCoroutine ( RunWww ( ) ) ;
112
- }
113
-
114
104
if ( _buttonHandler . Display ( "Test Call Async from coroutine" ) )
115
105
{
116
106
StartCoroutine ( RunAsyncFromCoroutineTest ( ) ) ;
@@ -131,13 +121,6 @@ async Task RunAsyncFromCoroutineTest2()
131
121
await new WaitForSeconds ( 1.0f ) ;
132
122
}
133
123
134
- IEnumerator RunWww ( )
135
- {
136
- var www = new WWW ( AssetBundleSampleUrl ) ;
137
- yield return www ;
138
- Debug . Log ( "Downloaded " + ( www . bytes . Length / 1024 ) + " kb" ) ;
139
- }
140
-
141
124
async Task RunWwwAsync ( )
142
125
{
143
126
var bytes = ( await new WWW ( AssetBundleSampleUrl ) ) . bytes ;
@@ -159,21 +142,20 @@ async Task RunUnhandledExceptionTestAsync()
159
142
160
143
async Task RunTryCatchExceptionTestAsync ( )
161
144
{
162
- var test = NestedRunAsync ( ) ;
163
145
try
164
146
{
165
- await test ;
147
+ await NestedRunAsync ( ) ;
166
148
}
167
149
catch ( Exception e )
168
150
{
169
- Debug . Log ( "Caught expected exception: " + e . Message ) ;
151
+ Debug . Log ( "Caught exception! " + e . Message ) ;
170
152
}
171
153
}
172
154
173
155
async Task NestedRunAsync ( )
174
156
{
175
157
await new WaitForSeconds ( 1 ) ;
176
- throw new Exception ( ) ;
158
+ throw new Exception ( "foo" ) ;
177
159
}
178
160
179
161
async Task WaitThenThrowException ( )
@@ -182,54 +164,23 @@ async Task WaitThenThrowException()
182
164
throw new Exception ( "asdf" ) ;
183
165
}
184
166
185
- IEnumerator RunAsyncOperation2 ( )
186
- {
187
- yield return InstantiateAssetBundle (
188
- AssetBundleSampleUrl , AssetBundleSampleAssetName ) ;
189
- }
190
-
191
- IEnumerator InstantiateAssetBundle ( string url , string assetName )
192
- {
193
- var request = UnityWebRequest . Get ( url ) ;
194
- yield return request . Send ( ) ;
195
-
196
- var abLoader = AssetBundle . LoadFromMemoryAsync ( request . downloadHandler . data ) ;
197
- yield return abLoader ;
198
- var assetbundle = abLoader . assetBundle ;
199
-
200
- var prefabLoader = assetbundle . LoadAssetAsync < GameObject > ( assetName ) ;
201
- yield return prefabLoader ;
202
- var prefab = prefabLoader . asset as GameObject ;
203
-
204
- GameObject . Instantiate ( prefab ) ;
205
- assetbundle . Unload ( false ) ;
206
- }
207
-
208
167
async Task RunAsyncOperationAsync ( )
209
168
{
210
169
await InstantiateAssetBundleAsync ( AssetBundleSampleUrl , AssetBundleSampleAssetName ) ;
211
170
}
212
171
213
172
async Task InstantiateAssetBundleAsync ( string abUrl , string assetName )
214
173
{
174
+ // We could use WWW here too which might be easier
175
+ Debug . Log ( "Downloading asset bundle data..." ) ;
215
176
var assetBundle = await AssetBundle . LoadFromMemoryAsync (
216
177
await DownloadRawDataAsync ( abUrl ) ) ;
217
178
218
179
var prefab = ( GameObject ) ( await assetBundle . LoadAssetAsync < GameObject > ( assetName ) ) ;
219
180
220
181
GameObject . Instantiate ( prefab ) ;
221
182
assetBundle . Unload ( false ) ;
222
- }
223
-
224
- async Task InstantiateAssetBundleAsync2 ( string abUrl , string assetName )
225
- {
226
- var assetBundle = await AssetBundle . LoadFromMemoryAsync (
227
- await DownloadRawDataAsync ( abUrl ) ) ;
228
-
229
- var prefab = ( GameObject ) ( await assetBundle . LoadAssetAsync < GameObject > ( assetName ) ) ;
230
-
231
- GameObject . Instantiate ( prefab ) ;
232
- assetBundle . Unload ( false ) ;
183
+ Debug . Log ( "Asset bundle instantiated" ) ;
233
184
}
234
185
235
186
async Task < byte [ ] > DownloadRawDataAsync ( string url )
@@ -247,7 +198,7 @@ async Task RunIEnumeratorTryCatchExceptionAsync()
247
198
}
248
199
catch ( Exception e )
249
200
{
250
- Debug . Log ( "Caught exception! {0} " + e ) ;
201
+ Debug . Log ( "Caught exception! " + e . Message ) ;
251
202
}
252
203
}
253
204
@@ -263,8 +214,8 @@ IEnumerator WaitThenThrow()
263
214
264
215
IEnumerator WaitThenThrowNested ( )
265
216
{
266
- Debug . Log ( "Waiting 2 seconds ..." ) ;
267
- yield return new WaitForSeconds ( 2 .0f) ;
217
+ Debug . Log ( "Waiting 1 second ..." ) ;
218
+ yield return new WaitForSeconds ( 1 .0f) ;
268
219
throw new Exception ( "zxcv" ) ;
269
220
}
270
221
0 commit comments