diff --git a/Assets/LuaFramework/Lua/Main.lua b/Assets/LuaFramework/Lua/Main.lua index 6829089bb..8a47738e0 100644 --- a/Assets/LuaFramework/Lua/Main.lua +++ b/Assets/LuaFramework/Lua/Main.lua @@ -5,5 +5,6 @@ end --场景切换通知 function OnLevelWasLoaded(level) + collectgarbage("collect") Time.timeSinceLevelLoad = 0 end \ No newline at end of file diff --git a/Assets/LuaFramework/Scripts/Manager/ResourceManager.cs b/Assets/LuaFramework/Scripts/Manager/ResourceManager.cs index 3216248aa..f07787411 100644 --- a/Assets/LuaFramework/Scripts/Manager/ResourceManager.cs +++ b/Assets/LuaFramework/Scripts/Manager/ResourceManager.cs @@ -1,5 +1,4 @@ -#if ASYNC_MODE -using UnityEngine; +using UnityEngine; using System.Collections; using System.Collections.Generic; using System; @@ -7,7 +6,7 @@ using LuaInterface; using UObject = UnityEngine.Object; -public class AssetBundleInfo { +internal class AssetBundleInfo { public AssetBundle m_AssetBundle; public int m_ReferencedCount; @@ -17,51 +16,103 @@ public AssetBundleInfo(AssetBundle assetBundle) { } } +internal class LoadAssetRequest +{ + internal string abName; //AssetBundleName + internal Type assetType; + internal string[] assetNames; + + internal virtual void DoLoadCallback(UObject[] result) { } +} + +internal class CSLoadAssetRequest:LoadAssetRequest +{ + internal Action sharpFunc; + internal override void DoLoadCallback(UObject[] result) + { + sharpFunc(result); + sharpFunc = null; + } +} + +internal class LuaLoadAssetRequest:LoadAssetRequest +{ + internal LuaFunction luaFunc; + internal override void DoLoadCallback(UObject[] result) + { + luaFunc.Call((object)result); //传递给LUA用,需要强转 + luaFunc.Dispose(); + luaFunc = null; + } +} + namespace LuaFramework { public class ResourceManager : Manager { string m_BaseDownloadingURL = ""; - string[] m_AllManifest = null; + Dictionary m_ManifestMap = new Dictionary(); AssetBundleManifest m_AssetBundleManifest = null; Dictionary m_Dependencies = new Dictionary(); Dictionary m_LoadedAssetBundles = new Dictionary(); - Dictionary> m_LoadRequests = new Dictionary>(); + Queue m_LoadQueue = new Queue(); + private bool m_Loading = false; - class LoadAssetRequest { - public Type assetType; - public string[] assetNames; - public LuaFunction luaFunc; - public Action sharpFunc; - } + // Load AssetBundleManifest. - public void Initialize(string manifestName, Action initOK) { - m_BaseDownloadingURL = Util.GetRelativePath(); - LoadAsset(manifestName, new string[] { "AssetBundleManifest" }, delegate(UObject[] objs) { - if (objs.Length > 0) { - m_AssetBundleManifest = objs[0] as AssetBundleManifest; - m_AllManifest = m_AssetBundleManifest.GetAllAssetBundles(); - } - if (initOK != null) initOK(); - }); + public void Initialize() { + string manifestName = AppConst.AssetDir; + //m_BaseDownloadingURL = Util.GetRelativePath(); + m_BaseDownloadingURL = Util.DataPath; + string pathManifest = m_BaseDownloadingURL + manifestName; + AssetBundle abManifest = AssetBundle.LoadFromFile(pathManifest); + AssetBundleInfo abi = new AssetBundleInfo(abManifest); + abi.m_ReferencedCount++; + m_LoadedAssetBundles.Add(manifestName, abi); + m_AssetBundleManifest = abManifest.LoadAsset("AssetBundleManifest"); + var m_AllManifest = m_AssetBundleManifest.GetAllAssetBundles(); + for (int i = 0; i < m_AllManifest.Length; i++) + { + int index = m_AllManifest[i].LastIndexOf('/'); + string path = m_AllManifest[i].Remove(0, index + 1); //字符串操作函数都会产生GC + m_ManifestMap.Add(path, m_AllManifest[i]); + } } public void LoadPrefab(string abName, string assetName, Action func) { - LoadAsset(abName, new string[] { assetName }, func); + var ret = LoadAsset(abName, new string[] { assetName }); + func(ret); } - public void LoadPrefab(string abName, string[] assetNames, Action func) { - LoadAsset(abName, assetNames, func); + public void LoadPrefab(string abName, string[] assetNames, Action func) { + var ret = LoadAsset(abName, assetNames); + func(ret); } public void LoadPrefab(string abName, string[] assetNames, LuaFunction func) { - LoadAsset(abName, assetNames, null, func); + var ret = LoadAsset(abName, assetNames); + func.Call((object)ret); + func.Dispose(); + } + + public void LoadPrefabAsync(string abName,string[] assetNames,LuaFunction func) + { + LoadAssetAsync(abName, assetNames, func); + } + + public void LoadPrefabAsync(string abName, string[] assetNames, Action func) + { + LoadAssetAsync(abName, assetNames, func); + } + + public void LoadAsset(string abName,string[] assetNames,LuaFunction func) + { + var ret = LoadAsset(abName, assetNames); + func.Call((object)ret); + func.Dispose(); } string GetRealAssetPath(string abName) { - if (abName.Equals(AppConst.AssetDir)) { - return abName; - } abName = abName.ToLower(); if (!abName.EndsWith(AppConst.ExtName)) { abName += AppConst.ExtName; @@ -69,135 +120,210 @@ string GetRealAssetPath(string abName) { if (abName.Contains("/")) { return abName; } - //string[] paths = m_AssetBundleManifest.GetAllAssetBundles(); 产生GC,需要缓存结果 - for (int i = 0; i < m_AllManifest.Length; i++) { - int index = m_AllManifest[i].LastIndexOf('/'); - string path = m_AllManifest[i].Remove(0, index + 1); //字符串操作函数都会产生GC - if (path.Equals(abName)) { - return m_AllManifest[i]; - } + string ret = null; + if (m_ManifestMap.TryGetValue(abName,out ret)) + { + return ret; } Debug.LogError("GetRealAssetPath Error:>>" + abName); return null; } - /// - /// 载入素材 - /// - void LoadAsset(string abName, string[] assetNames, Action action = null, LuaFunction func = null) where T : UObject { - abName = GetRealAssetPath(abName); + T[] LoadAsset(string abName, string[] assetNames) where T : UObject + { + AssetBundleInfo abi = GetAssetBundleInfo(abName); + T[] rets = new T[assetNames.Length]; + for (int i = 0; i < assetNames.Length; i++) + { + rets[i] = abi.m_AssetBundle.LoadAsset(assetNames[i]); + } + return rets; + } - LoadAssetRequest request = new LoadAssetRequest(); - request.assetType = typeof(T); - request.assetNames = assetNames; - request.luaFunc = func; - request.sharpFunc = action; - - List requests = null; - if (!m_LoadRequests.TryGetValue(abName, out requests)) { - requests = new List(); - requests.Add(request); - m_LoadRequests.Add(abName, requests); - StartCoroutine(OnLoadAsset(abName)); - } else { - requests.Add(request); - } + UObject[] LoadAsset(string abName,string[] assetNames) + { + AssetBundleInfo abi = GetAssetBundleInfo(abName); + UObject[] rets = new UObject[assetNames.Length]; + for (int i = 0; i < assetNames.Length; i++) + { + rets[i] = abi.m_AssetBundle.LoadAsset(assetNames[i]); + } + return rets; + } + + AssetBundleInfo GetAssetBundleInfo(string abName) + { + abName = GetRealAssetPath(abName); + AssetBundleInfo abi = null; + if (!m_LoadedAssetBundles.TryGetValue(abName, out abi)) + { + abi = LoadAssetBundle(abName); + } + abi.m_ReferencedCount++; + return abi; + } + + AssetBundleInfo LoadAssetBundle(string abName) + { + string[] deps = m_AssetBundleManifest.GetDirectDependencies(abName); + if (deps.Length>0) + { + m_Dependencies.Add(abName, deps); + foreach (string item in deps) + { + AssetBundleInfo depAB = null; + if (m_LoadedAssetBundles.TryGetValue(item, out depAB)) + { + depAB.m_ReferencedCount++; + } + else + { + depAB = LoadAssetBundle(item); + depAB.m_ReferencedCount++; + } + } + } + string url = m_BaseDownloadingURL + abName; + AssetBundle ab = AssetBundle.LoadFromFile(url); + AssetBundleInfo abi = new AssetBundleInfo(ab); + m_LoadedAssetBundles.Add(abName, abi); + return abi; } - IEnumerator OnLoadAsset(string abName) where T : UObject { - AssetBundleInfo bundleInfo = GetLoadedAssetBundle(abName); - if (bundleInfo == null) { - yield return StartCoroutine(OnLoadAssetBundle(abName, typeof(T))); - - bundleInfo = GetLoadedAssetBundle(abName); - if (bundleInfo == null) { - m_LoadRequests.Remove(abName); - Debug.LogError("OnLoadAsset--->>>" + abName); - yield break; - } - } - List list = null; - if (!m_LoadRequests.TryGetValue(abName, out list)) { - m_LoadRequests.Remove(abName); - yield break; - } - for (int i = 0; i < list.Count; i++) { - string[] assetNames = list[i].assetNames; - List result = new List(); - - AssetBundle ab = bundleInfo.m_AssetBundle; - for (int j = 0; j < assetNames.Length; j++) { - string assetPath = assetNames[j]; - AssetBundleRequest request = ab.LoadAssetAsync(assetPath, list[i].assetType); - yield return request; - result.Add(request.asset); - - //T assetObj = ab.LoadAsset(assetPath); - //result.Add(assetObj); - } - if (list[i].sharpFunc != null) { - list[i].sharpFunc(result.ToArray()); - list[i].sharpFunc = null; - } - if (list[i].luaFunc != null) { - list[i].luaFunc.Call((object)result.ToArray()); - list[i].luaFunc.Dispose(); - list[i].luaFunc = null; - } - bundleInfo.m_ReferencedCount++; - } - m_LoadRequests.Remove(abName); + void LoadAssetAsync(string abName, string[] assetNames, Action action) where T:UObject + { + abName = GetRealAssetPath(abName); + CSLoadAssetRequest request = new CSLoadAssetRequest() + { + abName = abName, + assetType = typeof(T), + assetNames = assetNames, + sharpFunc = action + }; + StartCoroutine(AddLoadRequest(request)); + } + + void LoadAssetAsync(string abName, string[] assetNames, LuaFunction func ) where T : UObject { + abName = GetRealAssetPath(abName); + LuaLoadAssetRequest request = new LuaLoadAssetRequest() + { + abName = abName, + assetType = typeof(T), + assetNames = assetNames, + luaFunc = func + }; + StartCoroutine(AddLoadRequest(request)); } - IEnumerator OnLoadAssetBundle(string abName, Type type) { - string url = m_BaseDownloadingURL + abName; + public void LoadAssetAsync(string abName,string[] assetNames,LuaFunction func) + { + abName = GetRealAssetPath(abName); + LuaLoadAssetRequest request = new LuaLoadAssetRequest() + { + abName = abName, + assetType = null, + assetNames = assetNames, + luaFunc = func + }; + StartCoroutine(AddLoadRequest(request)); + } - WWW download = null; - if (type == typeof(AssetBundleManifest)) - download = new WWW(url); - else { - string[] dependencies = m_AssetBundleManifest.GetAllDependencies(abName); - if (dependencies.Length > 0) { - m_Dependencies.Add(abName, dependencies); - for (int i = 0; i < dependencies.Length; i++) { - string depName = dependencies[i]; - AssetBundleInfo bundleInfo = null; - if (m_LoadedAssetBundles.TryGetValue(depName, out bundleInfo)) { - bundleInfo.m_ReferencedCount++; - } else if (!m_LoadRequests.ContainsKey(depName)) { - yield return StartCoroutine(OnLoadAssetBundle(depName, type)); - } - } - } - download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(abName), 0); + IEnumerator AddLoadRequest(LoadAssetRequest request) + { + if (m_Loading) + { + m_LoadQueue.Enqueue(request); } - yield return download; + else + { + m_Loading = true; + yield return StartCoroutine(OnLoadAsset(request)); + while (m_LoadQueue.Count > 0) + { + LoadAssetRequest request2 = m_LoadQueue.Dequeue(); + yield return StartCoroutine(OnLoadAsset(request2)); + } + m_Loading = false; + } + } - AssetBundle assetObj = download.assetBundle; - if (assetObj != null) { - m_LoadedAssetBundles.Add(abName, new AssetBundleInfo(assetObj)); + private IEnumerator OnLoadComplete(AssetBundleInfo bundleInfo, LoadAssetRequest req) + { + UObject[] result = new UObject[req.assetNames.Length]; + AssetBundle ab = bundleInfo.m_AssetBundle; + bundleInfo.m_ReferencedCount++; + string[] assetNames = req.assetNames; + for (int j = 0; j < assetNames.Length; j++) + { + string assetPath = assetNames[j]; + AssetBundleRequest request = ab.LoadAssetAsync(assetPath, req.assetType); + yield return request; + result[j]=request.asset; } + req.DoLoadCallback(result); } - AssetBundleInfo GetLoadedAssetBundle(string abName) { - AssetBundleInfo bundle = null; - m_LoadedAssetBundles.TryGetValue(abName, out bundle); - if (bundle == null) return null; - - // No dependencies are recorded, only the bundle itself is required. - string[] dependencies = null; - if (!m_Dependencies.TryGetValue(abName, out dependencies)) - return bundle; - - // Make sure all dependencies are loaded - foreach (var dependency in dependencies) { - AssetBundleInfo dependentBundle; - m_LoadedAssetBundles.TryGetValue(dependency, out dependentBundle); - if (dependentBundle == null) return null; + IEnumerator OnLoadAsset(LoadAssetRequest request ) { + string abName = request.abName; + AssetBundleInfo bundleInfo = null; + if (!m_LoadedAssetBundles.TryGetValue(abName,out bundleInfo)) + { + yield return StartCoroutine(OnLoadAssetBundle(abName)); + bundleInfo = m_LoadedAssetBundles[abName]; } - return bundle; + yield return StartCoroutine(OnLoadComplete(bundleInfo,request)); + } + + IEnumerator OnLoadAssetBundle(string abName) { + Debug.Log("OnLoadAssetBundle:"+abName); + string url = m_BaseDownloadingURL + abName; + AssetBundle assetObj = null; + AssetBundleCreateRequest loadRequest = null; + string[] dependencies = m_AssetBundleManifest.GetDirectDependencies(abName); + if (dependencies.Length > 0) + { + m_Dependencies.Add(abName, dependencies); + for (int i = 0; i < dependencies.Length; i++) + { + string depName = dependencies[i]; + AssetBundleInfo bundleInfo = null; + if (m_LoadedAssetBundles.TryGetValue(depName, out bundleInfo)) + { + bundleInfo.m_ReferencedCount++; + } + else + { + yield return StartCoroutine(OnLoadAssetBundle(depName)); + m_LoadedAssetBundles[depName].m_ReferencedCount++; + } + } + } + loadRequest = AssetBundle.LoadFromFileAsync(url); + yield return loadRequest; + assetObj = loadRequest.assetBundle; + Debug.AssertFormat(assetObj != null, "load AssetBundle: {0} fialed", abName); + m_LoadedAssetBundles.Add(abName, new AssetBundleInfo(assetObj)); } + //AssetBundleInfo GetLoadedAssetBundle(string abName) { + // AssetBundleInfo bundle = null; + // m_LoadedAssetBundles.TryGetValue(abName, out bundle); + // if (bundle == null) return null; + + // // No dependencies are recorded, only the bundle itself is required. + // string[] dependencies = null; + // if (!m_Dependencies.TryGetValue(abName, out dependencies)) + // return bundle; + + // // Make sure all dependencies are loaded + // foreach (var dependency in dependencies) { + // AssetBundleInfo dependentBundle; + // m_LoadedAssetBundles.TryGetValue(dependency, out dependentBundle); + // if (dependentBundle == null) return null; + // } + // return bundle; + //} + /// /// 此函数交给外部卸载专用,自己调整是否需要彻底清除AB /// @@ -207,8 +333,12 @@ public void UnloadAssetBundle(string abName, bool isThorough = false) { abName = GetRealAssetPath(abName); Debug.Log(m_LoadedAssetBundles.Count + " assetbundle(s) in memory before unloading " + abName); UnloadAssetBundleInternal(abName, isThorough); - UnloadDependencies(abName, isThorough); + Debug.Log(m_LoadedAssetBundles.Count + " assetbundle(s) in memory after unloading " + abName); + foreach (var bundle in m_LoadedAssetBundles) + { + Debug.Log("bundle name:" + bundle.Key + "\t count:" + bundle.Value.m_ReferencedCount); + } } void UnloadDependencies(string abName, bool isThorough) { @@ -224,158 +354,17 @@ void UnloadDependencies(string abName, bool isThorough) { } void UnloadAssetBundleInternal(string abName, bool isThorough) { - AssetBundleInfo bundle = GetLoadedAssetBundle(abName); + AssetBundleInfo bundle = null; + m_LoadedAssetBundles.TryGetValue(abName, out bundle); if (bundle == null) return; - - if (--bundle.m_ReferencedCount <= 0) { - if (m_LoadRequests.ContainsKey(abName)) { - return; //如果当前AB处于Async Loading过程中,卸载会崩溃,只减去引用计数即可 - } + bundle.m_ReferencedCount--; + if (bundle.m_ReferencedCount <= 0) { bundle.m_AssetBundle.Unload(isThorough); m_LoadedAssetBundles.Remove(abName); Debug.Log(abName + " has been unloaded successfully"); + UnloadDependencies(abName, isThorough); } } } } -#else -using UnityEngine; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using LuaFramework; -using LuaInterface; -using UObject = UnityEngine.Object; - -namespace LuaFramework { - public class ResourceManager : Manager { - private string[] m_Variants = { }; - private AssetBundleManifest manifest; - private AssetBundle shared, assetbundle; - private Dictionary bundles; - - void Awake() { - } - - /// - /// 初始化 - /// - public void Initialize() { - byte[] stream = null; - string uri = string.Empty; - bundles = new Dictionary(); - uri = Util.DataPath + AppConst.AssetDir; - if (!File.Exists(uri)) return; - stream = File.ReadAllBytes(uri); - assetbundle = AssetBundle.CreateFromMemoryImmediate(stream); - manifest = assetbundle.LoadAsset("AssetBundleManifest"); - } - - /// - /// 载入素材 - /// - public T LoadAsset(string abname, string assetname) where T : UnityEngine.Object { - abname = abname.ToLower(); - AssetBundle bundle = LoadAssetBundle(abname); - return bundle.LoadAsset(assetname); - } - - public void LoadPrefab(string abName, string[] assetNames, LuaFunction func) { - abName = abName.ToLower(); - List result = new List(); - for (int i = 0; i < assetNames.Length; i++) { - UObject go = LoadAsset(abName, assetNames[i]); - if (go != null) result.Add(go); - } - if (func != null) func.Call((object)result.ToArray()); - } - - /// - /// 载入AssetBundle - /// - /// - /// - public AssetBundle LoadAssetBundle(string abname) { - if (!abname.EndsWith(AppConst.ExtName)) { - abname += AppConst.ExtName; - } - AssetBundle bundle = null; - if (!bundles.ContainsKey(abname)) { - byte[] stream = null; - string uri = Util.DataPath + abname; - Debug.LogWarning("LoadFile::>> " + uri); - LoadDependencies(abname); - - stream = File.ReadAllBytes(uri); - bundle = AssetBundle.CreateFromMemoryImmediate(stream); //关联数据的素材绑定 - bundles.Add(abname, bundle); - } else { - bundles.TryGetValue(abname, out bundle); - } - return bundle; - } - - /// - /// 载入依赖 - /// - /// - void LoadDependencies(string name) { - if (manifest == null) { - Debug.LogError("Please initialize AssetBundleManifest by calling AssetBundleManager.Initialize()"); - return; - } - // Get dependecies from the AssetBundleManifest object.. - string[] dependencies = manifest.GetAllDependencies(name); - if (dependencies.Length == 0) return; - - for (int i = 0; i < dependencies.Length; i++) - dependencies[i] = RemapVariantName(dependencies[i]); - - // Record and load all dependencies. - for (int i = 0; i < dependencies.Length; i++) { - LoadAssetBundle(dependencies[i]); - } - } - - // Remaps the asset bundle name to the best fitting asset bundle variant. - string RemapVariantName(string assetBundleName) { - string[] bundlesWithVariant = manifest.GetAllAssetBundlesWithVariant(); - - // If the asset bundle doesn't have variant, simply return. - if (System.Array.IndexOf(bundlesWithVariant, assetBundleName) < 0) - return assetBundleName; - - string[] split = assetBundleName.Split('.'); - - int bestFit = int.MaxValue; - int bestFitIndex = -1; - // Loop all the assetBundles with variant to find the best fit variant assetBundle. - for (int i = 0; i < bundlesWithVariant.Length; i++) { - string[] curSplit = bundlesWithVariant[i].Split('.'); - if (curSplit[0] != split[0]) - continue; - - int found = System.Array.IndexOf(m_Variants, curSplit[1]); - if (found != -1 && found < bestFit) { - bestFit = found; - bestFitIndex = i; - } - } - if (bestFitIndex != -1) - return bundlesWithVariant[bestFitIndex]; - else - return assetBundleName; - } - - /// - /// 销毁资源 - /// - void OnDestroy() { - if (shared != null) shared.Unload(true); - if (manifest != null) manifest = null; - Debug.Log("~ResourceManager was destroy!"); - } - } -} -#endif diff --git a/Assets/LuaFramework/ToLua/Core/ObjectTranslator.cs b/Assets/LuaFramework/ToLua/Core/ObjectTranslator.cs index 756a962b0..c4c5fbf53 100644 --- a/Assets/LuaFramework/ToLua/Core/ObjectTranslator.cs +++ b/Assets/LuaFramework/ToLua/Core/ObjectTranslator.cs @@ -93,6 +93,17 @@ public static ObjectTranslator Get(IntPtr L) #endif } + //fixed 枚举唯一性问题(对象唯一,没有实现__eq操作符) + void RemoveObject(object o, int udata) + { + int index = -1; + + if (objectsBackMap.TryGetValue(o, out index) && index == udata) + { + objectsBackMap.Remove(o); + } + } + //lua gc一个对象(lua 库不再引用,但不代表c#没使用) public void RemoveObject(int udata) { @@ -103,7 +114,7 @@ public void RemoveObject(int udata) { if (!TypeChecker.IsValueType(o.GetType())) { - objectsBackMap.Remove(o); + RemoveObject(o, udata); } if (LogGC) @@ -127,7 +138,7 @@ public void Destroy(int udata) { if (!TypeChecker.IsValueType(o.GetType())) { - objectsBackMap.Remove(o); + RemoveObject(o, udata); } if (LogGC) @@ -154,6 +165,11 @@ public bool Getudata(object o, out int index) return objectsBackMap.TryGetValue(o, out index); } + public void Destroyudata(int udata) + { + objects.Destroy(udata); + } + public void SetBack(int index, object o) { objects.Replace(index, o); @@ -172,13 +188,14 @@ bool RemoveFromGCList(int id) return false; } + //延迟删除处理 void DestroyUnityObject(int udata, UnityEngine.Object obj) { object o = objects.TryGetValue(udata); if (object.ReferenceEquals(o, obj)) { - objectsBackMap.Remove(o); + RemoveObject(o, udata); //一定不能Remove, 因为GC还可能再来一次 objects.Destroy(udata); diff --git a/Assets/LuaFramework/ToLua/Core/ToLua.cs b/Assets/LuaFramework/ToLua/Core/ToLua.cs index a2a1305c2..bab57db65 100644 --- a/Assets/LuaFramework/ToLua/Core/ToLua.cs +++ b/Assets/LuaFramework/ToLua/Core/ToLua.cs @@ -2083,6 +2083,8 @@ static void PushUserData(IntPtr L, object o, int reference) { return; } + + translator.Destroyudata(index); } index = translator.AddObject(o); diff --git a/Assets/LuaFramework/ToLua/Editor/ToLuaExport.cs b/Assets/LuaFramework/ToLua/Editor/ToLuaExport.cs index 276c380f1..ae6f823ec 100644 --- a/Assets/LuaFramework/ToLua/Editor/ToLuaExport.cs +++ b/Assets/LuaFramework/ToLua/Editor/ToLuaExport.cs @@ -146,25 +146,31 @@ public static class ToLuaExport "CanvasRenderer.OnRequestRebuild", "CanvasRenderer.onRequestRebuild", "Terrain.bakeLightProbesForTrees", + "MonoBehaviour.runInEditMode", + "Light.lightmappingMode", //NGUI "UIInput.ProcessEvent", "UIWidget.showHandlesWithMoveTool", "UIWidget.showHandles", "Input.IsJoystickPreconfigured", - "UIDrawCall.isActive", - "MonoBehaviour.runInEditMode", - "Light.lightmappingMode" + "UIDrawCall.isActive" + }; + + public static List memberInfoFilter = new List + { + //可精确查找一个函数 + //Type.GetMethod(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers); }; public static bool IsMemberFilter(MemberInfo mi) { - return memberFilter.Contains(type.Name + "." + mi.Name); + return memberInfoFilter.Contains(mi) || memberFilter.Contains(type.Name + "." + mi.Name); } public static bool IsMemberFilter(Type t) { string name = LuaMisc.GetTypeName(t); - return memberFilter.Find((p) => { return name.Contains(p); }) != null; + return memberInfoFilter.Contains(t) || memberFilter.Find((p) => { return name.Contains(p); }) != null; } static ToLuaExport() diff --git a/Assets/LuaFramework/ToLua/Misc/LuaClient.cs b/Assets/LuaFramework/ToLua/Misc/LuaClient.cs index 456b77914..7808fe7ff 100644 --- a/Assets/LuaFramework/ToLua/Misc/LuaClient.cs +++ b/Assets/LuaFramework/ToLua/Misc/LuaClient.cs @@ -175,7 +175,7 @@ protected void Awake() Instance = this; Init(); -#if UNITY_5_4 +#if UNITY_5_4_OR_NEWER SceneManager.sceneLoaded += OnSceneLoaded; #endif } @@ -204,7 +204,7 @@ void OnLevelLoaded(int level) } } -#if UNITY_5_4 +#if UNITY_5_4_OR_NEWER void OnSceneLoaded(Scene scene, LoadSceneMode mode) { OnLevelLoaded(scene.buildIndex); @@ -220,7 +220,7 @@ public virtual void Destroy() { if (luaState != null) { -#if UNITY_5_4 +#if UNITY_5_4_OR_NEWER SceneManager.sceneLoaded -= OnSceneLoaded; #endif LuaState state = luaState; diff --git a/ReadMe.txt b/ReadMe.txt index 33d3d1628..74bce1cf9 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -17,6 +17,9 @@ XlsxToLua: https://github.com/zhangqi-ulua/XlsxToLua UnityHello: https://github.com/woshihuo12/UnityHello Excel配置:https://github.com/sy-yanghuan/proton +//-------------2016-01-07------------- +(1)更新tolua#到1.0.6.284版 + //-------------2016-12-21------------- (1)更新tolua#到1.0.6.277版