|
@@ -7,10 +7,11 @@ using System.Collections;
|
|
|
using System.Linq.Expressions;
|
|
|
using System.ComponentModel;
|
|
|
using System.Collections.Generic;
|
|
|
-
|
|
|
+using System.Diagnostics;
|
|
|
using Object = UnityEngine.Object;
|
|
|
using Random = UnityEngine.Random;
|
|
|
using Component = UnityEngine.Component;
|
|
|
+using Debug = UnityEngine.Debug;
|
|
|
|
|
|
public enum Folder
|
|
|
{
|
|
@@ -65,6 +66,12 @@ public enum ObjType
|
|
|
ButterflyYellow,
|
|
|
}
|
|
|
|
|
|
+public class AsyncRequest
|
|
|
+{
|
|
|
+ public UnityAction Callback;
|
|
|
+ public AssetBundleRequest Request;
|
|
|
+}
|
|
|
+
|
|
|
public class ManaReso : Regist
|
|
|
{
|
|
|
#region 变量
|
|
@@ -78,7 +85,7 @@ public class ManaReso : Regist
|
|
|
public static List<UnityAction> AsyncList = new List<UnityAction>();
|
|
|
public static List<AssetBundleRequest> RequestList = new List<AssetBundleRequest>();
|
|
|
|
|
|
- public static List<KV<AssetBundleRequest, UnityAction>> InstantiateList = new List<KV<AssetBundleRequest, UnityAction>>();
|
|
|
+ public static List<KV<AsyncRequest, UnityAction>> InstantiateList = new List<KV<AsyncRequest, UnityAction>>();
|
|
|
|
|
|
public static Dictionary<string, Object> ObjDic = new Dictionary<string, Object>();
|
|
|
public static Dictionary<string, Transform> TraDic = new Dictionary<string, Transform>();
|
|
@@ -701,9 +708,9 @@ public class ManaReso : Regist
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void AsyncLoad(string goName, Folder folder)
|
|
|
+ public static void AsyncLoad(string goName, Folder folder, UnityAction callback = null)
|
|
|
{
|
|
|
- KV<AssetBundleRequest, UnityAction> kv = new KV<AssetBundleRequest, UnityAction>();
|
|
|
+ KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
|
|
|
|
|
|
AssetBundleRequest bundleRequest;
|
|
|
|
|
@@ -732,7 +739,11 @@ public class ManaReso : Regist
|
|
|
throw new Exception();
|
|
|
}
|
|
|
|
|
|
- kv.Key = bundleRequest;
|
|
|
+ AsyncRequest asyncRequest = new AsyncRequest();
|
|
|
+ asyncRequest.Request = bundleRequest;
|
|
|
+ asyncRequest.Callback = callback;
|
|
|
+
|
|
|
+ kv.Key = asyncRequest;
|
|
|
kv.Value = () =>
|
|
|
{
|
|
|
ObjDic.Add(goName, bundleRequest.asset);
|
|
@@ -743,9 +754,9 @@ public class ManaReso : Regist
|
|
|
InstantiateList.Add(kv);
|
|
|
}
|
|
|
|
|
|
- public static void AsyncLoad<T>(string goName, int amt, Folder folder, ObjType objType) where T : ObjRoot
|
|
|
+ public static void AsyncLoad<T>(string goName, int amt, Folder folder, ObjType objType, UnityAction callback = null) where T : ObjRoot
|
|
|
{
|
|
|
- KV<AssetBundleRequest, UnityAction> kv = new KV<AssetBundleRequest, UnityAction>();
|
|
|
+ KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
|
|
|
|
|
|
AssetBundleRequest bundleRequest;
|
|
|
|
|
@@ -774,8 +785,11 @@ public class ManaReso : Regist
|
|
|
throw new Exception();
|
|
|
}
|
|
|
|
|
|
+ AsyncRequest asyncRequest = new AsyncRequest();
|
|
|
+ asyncRequest.Request = bundleRequest;
|
|
|
+ asyncRequest.Callback = callback;
|
|
|
|
|
|
- kv.Key = bundleRequest;
|
|
|
+ kv.Key = asyncRequest;
|
|
|
kv.Value = () =>
|
|
|
{
|
|
|
ObjDic.UniqueAdd(goName, bundleRequest.asset);
|
|
@@ -802,24 +816,24 @@ public class ManaReso : Regist
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void AddAsyncLoad(string goName, Folder folder)
|
|
|
+ public static void AddAsyncLoad(string goName, Folder folder, UnityAction callback = null)
|
|
|
{
|
|
|
AsyncList.Add
|
|
|
(
|
|
|
() =>
|
|
|
{
|
|
|
- AsyncLoad(goName, folder);
|
|
|
+ AsyncLoad(goName, folder, callback);
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public static void AddAsyncLoad<T>(string goName, int amt, Folder folder, ObjType objType) where T : ObjRoot
|
|
|
+ public static void AddAsyncLoad<T>(string goName, int amt, Folder folder, ObjType objType, UnityAction callback = null) where T : ObjRoot
|
|
|
{
|
|
|
AsyncList.Add
|
|
|
(
|
|
|
() =>
|
|
|
{
|
|
|
- AsyncLoad<T>(goName, amt, folder, objType);
|
|
|
+ AsyncLoad<T>(goName, amt, folder, objType, callback);
|
|
|
}
|
|
|
);
|
|
|
}
|
|
@@ -830,11 +844,15 @@ public class ManaReso : Regist
|
|
|
(
|
|
|
() =>
|
|
|
{
|
|
|
- KV<AssetBundleRequest, UnityAction> kv = new KV<AssetBundleRequest, UnityAction>();
|
|
|
+ KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
|
|
|
|
|
|
AssetBundleRequest bundleRequest = Bundle.Scene.LoadAssetAsync("Player");
|
|
|
|
|
|
- kv.Key = bundleRequest;
|
|
|
+ AsyncRequest asyncRequest = new AsyncRequest();
|
|
|
+ asyncRequest.Request = bundleRequest;
|
|
|
+ asyncRequest.Callback = null;
|
|
|
+
|
|
|
+ kv.Key = asyncRequest;
|
|
|
kv.Value = () =>
|
|
|
{
|
|
|
GameObject go = (GameObject)Instantiate(bundleRequest.asset);
|
|
@@ -950,26 +968,28 @@ public class ManaReso : Regist
|
|
|
yield return null;
|
|
|
}
|
|
|
|
|
|
- if (!InstantiateList[0].Key.isDone)
|
|
|
+ if (!InstantiateList[0].Key.Request.isDone)
|
|
|
{
|
|
|
yield return null;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- RequestList.Remove(InstantiateList[0].Key);
|
|
|
+ InstantiateList[0].Key.Callback.SafeInvoke();
|
|
|
+
|
|
|
+ RequestList.Remove(InstantiateList[0].Key.Request);
|
|
|
|
|
|
UnityAction action = InstantiateList[0].Value;
|
|
|
|
|
|
InstantiateList.RemoveAt(0);
|
|
|
|
|
|
AsyncInstantiateLock = true;
|
|
|
-
|
|
|
+
|
|
|
Auxiliary.Instance.DelayCall
|
|
|
(
|
|
|
() =>
|
|
|
{
|
|
|
action.SafeInvoke();
|
|
|
-
|
|
|
+
|
|
|
AsyncInstantiateLock = false;
|
|
|
},
|
|
|
0.05f
|