Skip to content

Commit 8153d9c

Browse files
committed
Code cleanup
1 parent 2820034 commit 8153d9c

File tree

3 files changed

+12
-108
lines changed

3 files changed

+12
-108
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vs

UnityProject/Assets/AsyncUtil/Tests/AsyncTests.unity

+1-49
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0.1273174, g: 0.13414761, b: 0.12107885, a: 1}
41+
m_IndirectSpecularColor: {r: 0.37311992, g: 0.38074034, b: 0.35872713, a: 1}
4242
--- !u!157 &3
4343
LightmapSettings:
4444
m_ObjectHideFlags: 0
@@ -108,54 +108,6 @@ NavMeshSettings:
108108
tileSize: 256
109109
accuratePlacement: 0
110110
m_NavMeshData: {fileID: 0}
111-
--- !u!1 &569663778
112-
GameObject:
113-
m_ObjectHideFlags: 0
114-
m_PrefabParentObject: {fileID: 0}
115-
m_PrefabInternal: {fileID: 0}
116-
serializedVersion: 5
117-
m_Component:
118-
- component: {fileID: 569663780}
119-
- component: {fileID: 569663779}
120-
m_Layer: 0
121-
m_Name: SceneContext
122-
m_TagString: Untagged
123-
m_Icon: {fileID: 0}
124-
m_NavMeshLayer: 0
125-
m_StaticEditorFlags: 0
126-
m_IsActive: 1
127-
--- !u!114 &569663779
128-
MonoBehaviour:
129-
m_ObjectHideFlags: 0
130-
m_PrefabParentObject: {fileID: 0}
131-
m_PrefabInternal: {fileID: 0}
132-
m_GameObject: {fileID: 569663778}
133-
m_Enabled: 1
134-
m_EditorHideFlags: 0
135-
m_Script: {fileID: 11500000, guid: 89715ad69b973a14899afa2c6730b30b, type: 3}
136-
m_Name:
137-
m_EditorClassIdentifier:
138-
_installers: []
139-
_installerPrefabs: []
140-
_scriptableObjectInstallers: []
141-
_autoRun: 1
142-
_parentNewObjectsUnderRoot: 0
143-
_contractNames: []
144-
_parentContractName:
145-
_parentContractNames: []
146-
--- !u!4 &569663780
147-
Transform:
148-
m_ObjectHideFlags: 0
149-
m_PrefabParentObject: {fileID: 0}
150-
m_PrefabInternal: {fileID: 0}
151-
m_GameObject: {fileID: 569663778}
152-
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
153-
m_LocalPosition: {x: 0, y: 0, z: 0}
154-
m_LocalScale: {x: 1, y: 1, z: 1}
155-
m_Children: []
156-
m_Father: {fileID: 0}
157-
m_RootOrder: 2
158-
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
159111
--- !u!1 &872110973
160112
GameObject:
161113
m_ObjectHideFlags: 0

UnityProject/Assets/AsyncUtil/Tests/AsyncUtilTests.cs

+10-59
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)