Exemple #1
0
            public UnityEngine.Object Load(Type type = null)
            {
                if (null != theObj)
                {
                    LoadComplete(theObj);
                    return(theObj);
                }

                UnityEngine.Object obj = ABLoader.LoadObject(thePath, null, type);
                if (null != obj)
                {
                    LoadComplete(obj);
                    return(obj);
                }

                if (null == type)
                {
                    obj = Resources.Load(thePath);
                }
                else
                {
                    obj = Resources.Load(thePath, type);
                }
                LoadComplete(obj);
                return(obj);
            }
Exemple #2
0
        public static void LoadUI(string uipath)
        {
            if (string.IsNullOrEmpty(uipath))
            {
                return;
            }
            AssetBundle ab = null;

            if (m_abDir.ContainsKey(uipath))
            {
                ab = m_abDir[uipath];
            }
            if (null == ab)
            {
                ab = ABLoader.GetUIAssetBundle(uipath);
                m_abDir.Remove(uipath);
                if (null != ab)
                {
                    m_abDir.Add(uipath, ab);
                }
            }

            string id = uipath;

            if (m_pkgDir.ContainsKey(uipath))
            {
                id = m_pkgDir[uipath];
            }

            UIPackage pkg = UIPackage.GetById(id);

            if (null == pkg)
            {
                if (null == ab)
                {
                    pkg = UIPackage.AddPackage(uipath);
                }
                else
                {
                    pkg = UIPackage.AddPackage(ab);
                }
            }
            else
            {
                if (null == ab)
                {
                    pkg.ReloadAssets();
                }
                else
                {
                    pkg.ReloadAssets(ab);
                }
            }
            if (!m_pkgDir.ContainsKey(uipath))
            {
                m_pkgDir.Add(uipath, pkg.id);
            }
        }
Exemple #3
0
        public static byte[] LoadLua(ref string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(null);
            }
            try
            {
                if (!LoadedLua.Contains(filePath))
                {
                    LoadedLua.Add(filePath);
                }

                string luaPath     = "";
                string luaFullPath = "";
                byte[] luaBytes    = null;

                // 转换为小写路径
                filePath = ("Lua/" + filePath).ToLower();
                // 例:Lua文件中类似require "aaa.bbb"时,自动转换为路径aaa/bbb
                filePath = filePath.Replace(".", "/");

                luaFullPath = ABLoader.GetLuaPath(filePath);
                if (!string.IsNullOrEmpty(luaFullPath))
                {
                    Debug.Log("加载lua:" + filePath);
                    luaBytes = TryLoadLuaFromFile(luaFullPath, true);
                }

                if (null == luaBytes)
                {
                    luaPath     = filePath + ".lua";
                    luaFullPath = string.Format("{0}/{1}", Application.dataPath, luaPath);
                    if (File.Exists(luaFullPath))
                    {
                        luaBytes = TryLoadLuaFromFile(luaFullPath, false);
                    }
                }

                if (null == luaBytes)
                {
                    luaPath  = filePath + ".lua";
                    luaBytes = TryLoadLuaFromResource(luaPath, true);

                    if (null == luaBytes)
                    {
                        UnityEngine.Debug.LogError("[error] Cant find " + luaFullPath);
                    }
                }

                return(luaBytes);
            }
            catch
            {
                return(null);
            }
        }
Exemple #4
0
 public static void UnloadScene(string sname)
 {
     if (string.IsNullOrEmpty(sname))
     {
         return;
     }
     ABLoader.UnloadScene(ScenePathPrefix + sname);
     // 和上一场景一致
     if (lastSceneName == sname)
     {
         lastSceneName = null;
     }
 }
Exemple #5
0
 private void ReferenceDec()
 {
     referenceCount--;
     if (referenceCount > 0)
     {
         return;
     }
     if (theType != typeof(UnityEngine.GameObject))
     {
         Resources.UnloadAsset(theObj);
     }
     ABLoader.UnloadObject(thePath);
     theObj = null;
 }
Exemple #6
0
 public static void UnloadAll()
 {
     foreach (var v in m_pkgDir.Values)
     {
         UnloadUI(v);
     }
     foreach (var v in m_objDir.Keys)
     {
         UnloadObject(v);
     }
     m_objDir.Clear();
     m_pkgDir.Clear();
     m_abDir.Clear();
     UnloadScene(lastSceneName);
     ABLoader.UnloadAll();
     UIPackage.RemoveAllPackages();
     Resources.UnloadUnusedAssets();
 }
Exemple #7
0
        public static void LoadScene(string sname)
        {
            if (string.IsNullOrEmpty(sname))
            {
                return;
            }
            //  加载新场景
            bool r = ABLoader.LoadScene(ScenePathPrefix + sname, sname);

            // 卸载上一个场景
            if (!string.IsNullOrEmpty(lastSceneName) && sname != lastSceneName)
            {
                ABLoader.UnloadScene(ScenePathPrefix + lastSceneName);
                lastSceneName = null;
            }
            // if (r)
            {
                lastSceneName = sname;
            }
        }
Exemple #8
0
            public void AsyncLoad(Type type, Action <UnityEngine.Object> complete, Action <float> progress = null)
            {
                if (null == complete)
                {
                    return;
                }

                if (null != theObj)
                {
                    complete.Invoke(theObj);
                    complete = null;
                    progress = null;
                    LoadComplete(theObj);
                    return;
                }

                if (ABLoader.AsyncLoadObject(thePath, null, type, (s, o) =>
                {
                    complete.Invoke(o);
                    complete = null;
                    progress = null;
                    LoadComplete(o);
                }, progress))
                {
                    return;
                }

                UnityEngine.Object obj;
                if (null == type)
                {
                    obj = Resources.Load(thePath);
                }
                else
                {
                    obj = Resources.Load(thePath, type);
                }
                complete.Invoke(obj);
                complete = null;
                progress = null;
                LoadComplete(obj);
            }