@@ -76,12 +76,7 @@ public void OnGUI()
7676 RunIEnumeratorTryCatchExceptionAsync ( ) . WrapErrors ( ) ;
7777 }
7878
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" ) )
8580 {
8681 RunAsyncOperationAsync ( ) . WrapErrors ( ) ;
8782 }
@@ -106,11 +101,6 @@ public void OnGUI()
106101 RunWwwAsync ( ) . WrapErrors ( ) ;
107102 }
108103
109- if ( _buttonHandler . Display ( "Test www download coroutines" ) )
110- {
111- StartCoroutine ( RunWww ( ) ) ;
112- }
113-
114104 if ( _buttonHandler . Display ( "Test Call Async from coroutine" ) )
115105 {
116106 StartCoroutine ( RunAsyncFromCoroutineTest ( ) ) ;
@@ -131,13 +121,6 @@ async Task RunAsyncFromCoroutineTest2()
131121 await new WaitForSeconds ( 1.0f ) ;
132122 }
133123
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-
141124 async Task RunWwwAsync ( )
142125 {
143126 var bytes = ( await new WWW ( AssetBundleSampleUrl ) ) . bytes ;
@@ -159,21 +142,20 @@ async Task RunUnhandledExceptionTestAsync()
159142
160143 async Task RunTryCatchExceptionTestAsync ( )
161144 {
162- var test = NestedRunAsync ( ) ;
163145 try
164146 {
165- await test ;
147+ await NestedRunAsync ( ) ;
166148 }
167149 catch ( Exception e )
168150 {
169- Debug . Log ( "Caught expected exception: " + e . Message ) ;
151+ Debug . Log ( "Caught exception! " + e . Message ) ;
170152 }
171153 }
172154
173155 async Task NestedRunAsync ( )
174156 {
175157 await new WaitForSeconds ( 1 ) ;
176- throw new Exception ( ) ;
158+ throw new Exception ( "foo" ) ;
177159 }
178160
179161 async Task WaitThenThrowException ( )
@@ -182,54 +164,23 @@ async Task WaitThenThrowException()
182164 throw new Exception ( "asdf" ) ;
183165 }
184166
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-
208167 async Task RunAsyncOperationAsync ( )
209168 {
210169 await InstantiateAssetBundleAsync ( AssetBundleSampleUrl , AssetBundleSampleAssetName ) ;
211170 }
212171
213172 async Task InstantiateAssetBundleAsync ( string abUrl , string assetName )
214173 {
174+ // We could use WWW here too which might be easier
175+ Debug . Log ( "Downloading asset bundle data..." ) ;
215176 var assetBundle = await AssetBundle . LoadFromMemoryAsync (
216177 await DownloadRawDataAsync ( abUrl ) ) ;
217178
218179 var prefab = ( GameObject ) ( await assetBundle . LoadAssetAsync < GameObject > ( assetName ) ) ;
219180
220181 GameObject . Instantiate ( prefab ) ;
221182 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" ) ;
233184 }
234185
235186 async Task < byte [ ] > DownloadRawDataAsync ( string url )
@@ -247,7 +198,7 @@ async Task RunIEnumeratorTryCatchExceptionAsync()
247198 }
248199 catch ( Exception e )
249200 {
250- Debug . Log ( "Caught exception! {0} " + e ) ;
201+ Debug . Log ( "Caught exception! " + e . Message ) ;
251202 }
252203 }
253204
@@ -263,8 +214,8 @@ IEnumerator WaitThenThrow()
263214
264215 IEnumerator WaitThenThrowNested ( )
265216 {
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) ;
268219 throw new Exception ( "zxcv" ) ;
269220 }
270221
0 commit comments