Ejemplo n.º 1
0
        /// <summary>  加载AssetBundle资源 </summary>
        public LoadedAssetBundle LoadAssetBundleAsync(string assetBundleName, string assetName, Action <LoadedAssetBundle> loadAssetBundleCallback)
        {
#if UNITY_EDITOR
            if (assetBundleName != assetBundleName.ToLower())
            {
                Debug.LogErrorFormat("加载的AssetBundleName含有大写字母!【{0}】请改正", assetBundleName);
                assetBundleName = assetBundleName.ToLower();
            }
            if (GameConfigProject.instance.assetLoadType == (int)GameConfigProject.LoadType.SimulateEditor)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                if (assetPaths.Length == 0)
                {
                    //Debug.LogError("There is no assetBundle " + assetBundleName);
                    return(null);
                }

                LoadedAssetBundle loaded;
                if (mLoadedAssetBundleDic.TryGetValue(assetBundleName, out loaded))
                { //如果AssetBundle已经加载则其引用+1
                    ++loaded.referencedCount;
                    if (loadAssetBundleCallback != null)
                    {
                        loadAssetBundleCallback(loaded);
                    }
                    return(loaded);
                }
                Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                SimulateLoadedAssetBundle simulateAb = new SimulateLoadedAssetBundle(target, assetBundleName);
                AddToLoadedDic(assetBundleName, simulateAb);
                simulateAb.dependAssetBundles = GetDependAssetBundles(assetBundleName, false);
                simulateAb.isLoaded           = true;
                if (loadAssetBundleCallback != null)
                {
                    loadAssetBundleCallback(simulateAb);
                }
                return(simulateAb);
            }
#endif
            LoadedAssetBundle loadedAssetBundle = GetOrGenerateLoadedAssetBundle(assetBundleName, false, true);
            if (loadedAssetBundle == null)
            {
                if (loadAssetBundleCallback != null)
                {
                    loadAssetBundleCallback(null);
                }
                return(null);
            }

            if (loadedAssetBundle.isLoaded || loadedAssetBundle.isAsyncLoading)
            {
                if (loadAssetBundleCallback != null)
                {
                    loadAssetBundleCallback(loadedAssetBundle);
                }
                return(loadedAssetBundle);
            }
            MonoBehaviourDispatcher.instance.StartCoroutine(LoadAssetBundleAsyncFromeFile(loadedAssetBundle, assetName, loadAssetBundleCallback));
            return(loadedAssetBundle);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载AssetBundle资源。这里需要注意需自行管理AssetBundle的生命周期
        /// </summary>
        /// <param name="assetBundleName"></param>
        public LoadedAssetBundle LoadAssetBundle(string assetBundleName)
        {
#if UNITY_EDITOR
            if (assetBundleName != assetBundleName.ToLower())
            {
                Debug.LogErrorFormat("加载的AssetBundleName含有大写字母!必须是小写!【{0}】请改正", assetBundleName);
                throw new Exception(string.Format("加载的AssetBundleName含有大写字母!必须是小写!【{0}】请改正", assetBundleName));
                // assetBundleName = assetBundleName.ToLower();
            }
            if (GameConfigProject.instance.assetLoadType == (int)GameConfigProject.LoadType.SimulateEditor)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                if (assetPaths.Length == 0)
                {
                    return(null);
                }

                LoadedAssetBundle loaded;
                if (mLoadedAssetBundleDic.TryGetValue(assetBundleName, out loaded))
                { //如果AssetBundle已经加载则其引用+1
                    ++loaded.referencedCount;
                    return(loaded);
                }
                Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                SimulateLoadedAssetBundle simulateAb = new SimulateLoadedAssetBundle(target, assetBundleName);
                AddToLoadedDic(assetBundleName, simulateAb);
                simulateAb.dependAssetBundles = GetDependAssetBundles(assetBundleName, false);
                simulateAb.isLoaded           = true;
                return(simulateAb);
            }
#endif
//            Debug.Log("LoadAssetBundle:" + assetBundleName + " | " + Time.realtimeSinceStartup);
            LoadedAssetBundle assetBundle = GetOrGenerateLoadedAssetBundle(assetBundleName, false, false);
            return(assetBundle);
        }
Ejemplo n.º 3
0
 static int QPYX_LoadAllAssets_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 1);
         GameAsset.SimulateLoadedAssetBundle QPYX_obj_YXQP = (GameAsset.SimulateLoadedAssetBundle)ToLua.CheckObject <GameAsset.SimulateLoadedAssetBundle>(L_YXQP, 1);
         QPYX_obj_YXQP.LoadAllAssets();
         return(0);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
Ejemplo n.º 4
0
 static int LoadAllAssets(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         GameAsset.SimulateLoadedAssetBundle obj = (GameAsset.SimulateLoadedAssetBundle)ToLua.CheckObject <GameAsset.SimulateLoadedAssetBundle>(L, 1);
         obj.LoadAllAssets();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 5
0
 static int QPYX_GetAsset_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 3);
         GameAsset.SimulateLoadedAssetBundle QPYX_obj_YXQP = (GameAsset.SimulateLoadedAssetBundle)ToLua.CheckObject <GameAsset.SimulateLoadedAssetBundle>(L_YXQP, 1);
         string             QPYX_arg0_YXQP = ToLua.CheckString(L_YXQP, 2);
         bool               QPYX_arg1_YXQP = LuaDLL.luaL_checkboolean(L_YXQP, 3);
         UnityEngine.Object QPYX_o_YXQP    = QPYX_obj_YXQP.GetAsset(QPYX_arg0_YXQP, QPYX_arg1_YXQP);
         ToLua.Push(L_YXQP, QPYX_o_YXQP);
         return(1);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
Ejemplo n.º 6
0
 static int GetAsset(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         GameAsset.SimulateLoadedAssetBundle obj = (GameAsset.SimulateLoadedAssetBundle)ToLua.CheckObject <GameAsset.SimulateLoadedAssetBundle>(L, 1);
         string             arg0 = ToLua.CheckString(L, 2);
         bool               arg1 = LuaDLL.luaL_checkboolean(L, 3);
         UnityEngine.Object o    = obj.GetAsset(arg0, arg1);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 7
0
 static int QPYX__CreateGameAsset_SimulateLoadedAssetBundle_YXQP(IntPtr L_YXQP)
 {
     try
     {
         int QPYX_count_YXQP = LuaDLL.lua_gettop(L_YXQP);
         if (QPYX_count_YXQP == 2)
         {
             UnityEngine.Object QPYX_arg0_YXQP = (UnityEngine.Object)ToLua.CheckObject <UnityEngine.Object>(L_YXQP, 1);
             string             QPYX_arg1_YXQP = ToLua.CheckString(L_YXQP, 2);
             GameAsset.SimulateLoadedAssetBundle QPYX_obj_YXQP = new GameAsset.SimulateLoadedAssetBundle(QPYX_arg0_YXQP, QPYX_arg1_YXQP);
             ToLua.PushObject(L_YXQP, QPYX_obj_YXQP);
             return(1);
         }
         else
         {
             return(LuaDLL.luaL_throw(L_YXQP, "invalid arguments to ctor method: GameAsset.SimulateLoadedAssetBundle.New"));
         }
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
Ejemplo n.º 8
0
    static int _CreateGameAsset_SimulateLoadedAssetBundle(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.Object arg0 = (UnityEngine.Object)ToLua.CheckObject <UnityEngine.Object>(L, 1);
                string             arg1 = ToLua.CheckString(L, 2);
                GameAsset.SimulateLoadedAssetBundle obj = new GameAsset.SimulateLoadedAssetBundle(arg0, arg1);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: GameAsset.SimulateLoadedAssetBundle.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }