Beispiel #1
0
            public void Start(ProvideHandle provideHandle)
            {
                Type          t    = provideHandle.Type;
                List <object> deps = new List <object>();

                provideHandle.GetDependencies(deps);
                AssetBundle bundle = LoadBundleFromDependecies(deps);

                if (bundle == null)
                {
                    provideHandle.Complete <AssetBundle>(null, false,
                                                         new Exception("Unable to load dependent bundle from location " + provideHandle.Location));
                    return;
                }

                object result = null;

                if (t.IsArray)
                {
                    result = bundle.LoadAssetWithSubAssets(provideHandle.Location.InternalId, t.GetElementType());
                }
                else if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition())
                {
                    result = bundle.LoadAssetWithSubAssets(provideHandle.Location.InternalId, t.GetElementType())
                             .ToList();
                }
                else
                {
                    result = bundle.LoadAsset(provideHandle.Location.InternalId, t);
                }

                provideHandle.Complete(result, result != null, null);
            }
            private void BeginAssetLoad()
            {
                if (m_AssetBundle == null)
                {
                    m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location));
                }
                else
                {
                    var assetPath = m_ProvideHandle.ResourceManager.TransformInternalId(m_ProvideHandle.Location);
                    if (m_ProvideHandle.Type.IsArray)
                    {
#if !UNITY_2021_1_OR_NEWER
                        if (AsyncOperationHandle.IsWaitingForCompletion)
                        {
                            GetArrayResult(m_AssetBundle.LoadAssetWithSubAssets(assetPath, m_ProvideHandle.Type.GetElementType()));
                            CompleteOperation();
                        }
                        else
#endif
                        m_RequestOperation = m_AssetBundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetElementType());
                    }
                    else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                    {
#if !UNITY_2021_1_OR_NEWER
                        if (AsyncOperationHandle.IsWaitingForCompletion)
                        {
                            GetListResult(m_AssetBundle.LoadAssetWithSubAssets(assetPath, m_ProvideHandle.Type.GetGenericArguments()[0]));
                            CompleteOperation();
                        }
                        else
#endif
                        m_RequestOperation = m_AssetBundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetGenericArguments()[0]);
                    }
                    else
                    {
                        if (ResourceManagerConfig.ExtractKeyAndSubKey(assetPath, out string mainPath, out string subKey))
                        {
                            subObjectName = subKey;
#if !UNITY_2021_1_OR_NEWER
                            if (AsyncOperationHandle.IsWaitingForCompletion)
                            {
                                GetAssetSubObjectResult(m_AssetBundle.LoadAssetWithSubAssets(mainPath, m_ProvideHandle.Type));
                                CompleteOperation();
                            }
                            else
#endif
                            m_RequestOperation = m_AssetBundle.LoadAssetWithSubAssetsAsync(mainPath, m_ProvideHandle.Type);
                        }
Beispiel #3
0
        /// <summary>
        /// load ALL TestAPI
        /// 这个有一定局限性,这里是返回某个Ab中的所有资源
        /// 简单处理一些简单资源情况:目前只解决图集
        /// 仅作为某些项目补坑用
        /// </summary>
        /// <param name="path"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public T[] LoadAll_TestAPI_2020_5_23 <T>(string path) where T : Object
        {
            var    item     = config.Manifest.GetManifestItemByName(path);
            string realPath = string.IsNullOrEmpty(item.Package) ? item.Hash : item.Package;

            //加载assetbundle
            AssetBundle ab = LoadAssetBundle(realPath);

            if (ab != null)
            {
                var    assetNames = ab.GetAllAssetNames();
                string relname    = "";
                if (assetNames.Length == 1)
                {
                    relname = assetNames[0];
                }
                else
                {
                    var f = path + ".";
                    relname = assetNames.First((s) => s.Contains(f));
                }
                return(ab.LoadAssetWithSubAssets <T>(relname));
            }

            return(null);
        }
Beispiel #4
0
    static int LoadAssetWithSubAssets(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2)
        {
            AssetBundle obj  = LuaScriptMgr.GetUnityObject <AssetBundle>(L, 1);
            string      arg0 = LuaScriptMgr.GetLuaString(L, 2);
            Object[]    o    = obj.LoadAssetWithSubAssets(arg0);
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        else if (count == 3)
        {
            AssetBundle obj  = LuaScriptMgr.GetUnityObject <AssetBundle>(L, 1);
            string      arg0 = LuaScriptMgr.GetLuaString(L, 2);
            Type        arg1 = LuaScriptMgr.GetTypeObject(L, 3);
            Object[]    o    = obj.LoadAssetWithSubAssets(arg0, arg1);
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: AssetBundle.LoadAssetWithSubAssets");
        }

        return(0);
    }
Beispiel #5
0
        /// <summary>
        /// load ALL TestAPI
        /// 这个有一定局限性,这里是返回某个Ab中的所有资源
        /// 简单处理一些简单资源情况:目前只解决图集
        /// 仅作为某些项目补坑用
        /// </summary>
        /// <param name="path"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public T[] LoadAll <T>(string path) where T : Object
        {
            //非hash模式,需要debugRuntime
            // if (!this.AssetConfigLoder.IsHashName)
            // {
            //     path = ZString.Format(DEBUG_RUNTIME, path);
            // }


            var item = AssetConfigLoder.GetAssetBundleData <T>(path);
            //加载assetbundle
            AssetBundle ab = LoadAssetBundle(item.AssetBundlePath);

            if (ab != null)
            {
                var    assetNames = ab.GetAllAssetNames();
                string relname    = "";
                if (assetNames.Length == 1)
                {
                    relname = assetNames[0];
                }
                else
                {
                    var f = path + ".";
                    relname = assetNames.First((s) => s.Contains(f));
                }

                return(ab.LoadAssetWithSubAssets <T>(relname));
            }

            return(null);
        }
Beispiel #6
0
    public Sprite[] GetUISpriteList(string resName)
    {
        string[] tmpName         = resName.Split('/');
        int      tmpCount        = tmpName.Length;
        string   curName         = tmpName[tmpCount - 1];
        string   bundleFristName = tmpName[0].ToLower() + "/" + tmpName[1].ToLower();

        if (!AllAssetBundle.ContainsKey(bundleFristName))
        {
            string tmppath = Util.DataPath + bundleFristName + ".ld";
            if (!File.Exists(tmppath))
            {
                return(null);
            }
            AssetBundle tmpBundle = AssetBundle.LoadFromFile(tmppath);
            AllAssetBundle.Add(bundleFristName, tmpBundle);


            if (MainManiFest != null)
            {
                loadManifestDependencies(bundleFristName + ".ld");
            }
            return(tmpBundle.LoadAssetWithSubAssets <Sprite>(curName));
        }
        else
        {
            Sprite[] ob = AllAssetBundle[bundleFristName].LoadAssetWithSubAssets <Sprite>(curName);
            //Sprite[] ob = AllAssetBundle[bundleFristName].LoadAsset(curName + ".png");
            if (ob == null)
            {
                Debug.LogError("ob == null");
            }
            return(ob);
        }
    }
Beispiel #7
0
        /// <summary>
        /// load ALL TestAPI
        /// 这个有一定局限性,这里是返回某个Ab中的所有资源
        /// 简单处理一些简单资源情况:目前只解决图集
        /// 仅作为某些项目补坑用
        /// </summary>
        /// <param name="path"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public T[] LoadAll_TestAPI_2020_5_23 <T>(string path) where T : Object
        {
            path = string.Format(RUNTIME, path.ToLower());
            var item = loder.Manifest.GetManifest(path);
            //加载assetbundle
            AssetBundle ab = LoadAssetBundle(item.Path);

            if (ab != null)
            {
                var    assetNames = ab.GetAllAssetNames();
                string relname    = "";
                if (assetNames.Length == 1)
                {
                    relname = assetNames[0];
                }
                else
                {
                    var f = path + ".";
                    relname = assetNames.First((s) => s.Contains(f));
                }

                return(ab.LoadAssetWithSubAssets <T>(relname));
            }

            return(null);
        }
    private static int LoadAssetWithSubAssets(IntPtr L)
    {
        int result;

        try
        {
            int num = LuaDLL.lua_gettop(L);
            if (num == 2 && TypeChecker.CheckTypes(L, 1, typeof(AssetBundle), typeof(string)))
            {
                AssetBundle assetBundle = (AssetBundle)ToLua.ToObject(L, 1);
                string      text        = ToLua.ToString(L, 2);
                Object[]    array       = assetBundle.LoadAssetWithSubAssets(text);
                ToLua.Push(L, array);
                result = 1;
            }
            else if (num == 3 && TypeChecker.CheckTypes(L, 1, typeof(AssetBundle), typeof(string), typeof(Type)))
            {
                AssetBundle assetBundle2 = (AssetBundle)ToLua.ToObject(L, 1);
                string      text2        = ToLua.ToString(L, 2);
                Type        type         = (Type)ToLua.ToObject(L, 3);
                Object[]    array2       = assetBundle2.LoadAssetWithSubAssets(text2, type);
                ToLua.Push(L, array2);
                result = 1;
            }
            else
            {
                result = LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.AssetBundle.LoadAssetWithSubAssets");
            }
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
Beispiel #9
0
 /// <summary>
 /// 获取精灵贴图数组
 /// </summary>
 /// <param name="resName">资源名称</param>
 /// <returns>Sprite贴图数组</returns>
 public Sprite[] GetSpriteArrayResourceByName(string resName)
 {
     Sprite[] spriteArray = null;
     for (int i = 0; i < m_TexturePathList.Count; ++i)
     {
         string assetBundlePath = m_TexturePathList[i];
         //判断文件是否存在
         if (!File.Exists(assetBundlePath))
         {
             return(null);
         }
         AssetBundle assetBundle = AssetBundle.LoadFromFile(assetBundlePath);
         if (null == assetBundle)
         {
             return(null);
         }
         spriteArray = assetBundle.LoadAssetWithSubAssets <Sprite>(resName);
         assetBundle.Unload(false);
         if (spriteArray != null)
         {
             break;
         }
     }
     return(spriteArray);
 }
Beispiel #10
0
        private void GetAssetBundle(ref int _loadNum, AssetBundle _assetBundle, string _msg)
        {
            _loadNum--;

            if (_loadNum == 0)
            {
                if (string.IsNullOrEmpty(_msg))
                {
                    if (AssetManager.LOADASYNC)
                    {
                        AssetManager.Instance.script.Load <T>(name, _assetBundle, LoadOver);
                    }
                    else
                    {
                        string msg = string.Empty;

                        T[] asset = null;

                        try{
                            asset = _assetBundle.LoadAssetWithSubAssets <T>(name);
                        }catch (Exception e) {
                            msg = "Asset加载错误  name:" + name + "   msg:" + e.Message;
                        }finally{
                            LoadOver(asset, msg);
                        }
                    }
                }
                else
                {
                    LoadOver(null, _msg);
                }
            }
        }
Beispiel #11
0
 /// <summary>
 /// 加载子物体
 /// </summary>
 /// <param name="bundleName"></param>
 /// <returns></returns>
 public object[] LoadAssetWithSubAssets(string bundleName)
 {
     if (bundleName != null)
     {
         return(assetBundle.LoadAssetWithSubAssets(bundleName));
     }
     return(null);
 }
 private static Object[] LoadAll(string path, System.Type systemTypeInstance)
 {
     if (string.IsNullOrEmpty(path))
     {
         return(ResourcesBundle.LoadAllAssets(systemTypeInstance));
     }
     return(ResourcesBundle.LoadAssetWithSubAssets(path.ToLower(), systemTypeInstance));
 }
Beispiel #13
0
 /// <summary>
 /// 加载多个资源
 /// </summary>
 /// <param name="resName"></param>
 /// <returns></returns>
 public UnityEngine.Object[] LoadResources(string resName)
 {
     if (this.mABRes == null || !this.mABRes.Contains(resName))
     {
         Debug.LogWarning("AssetBundle资源不存在");
         return(null);
     }
     return(mABRes.LoadAssetWithSubAssets(resName));
 }
Beispiel #14
0
 public UnityEngine.Object[] LoadResources(string resName)
 {
     if (this.ABRes == null || !this.ABRes.Contains(resName))
     {
         Debug.Log("res not contain");
         return(null);
     }
     return(ABRes.LoadAssetWithSubAssets(resName));
 }
Beispiel #15
0
 /// <summary>
 /// 加载带有子物体的资源
 /// </summary>
 /// <param name="resName">资源名称</param>
 /// <returns></returns>
 public Object[] LoadMultRes(string resName)
 {
     if (mAB != null && mAB.Contains(resName))
     {
         return(mAB.LoadAssetWithSubAssets(resName));
     }
     Debug.Log("res is not Contain");
     return(null);
 }
Beispiel #16
0
    /// <summary>
    /// 加载多个资源
    /// </summary>
    public Object[] LoadAssetWithSubAssets(string assetName)
    {
        if (abRes == null || !abRes.Contains(assetName))
        {
            Debug.LogError("The abRes is Not Exists :" + assetName);
            return(null);
        }

        return(abRes.LoadAssetWithSubAssets(assetName));
    }
Beispiel #17
0
    /// <summary>
    /// 加载多个资源(一般用于切割成多个的精灵图)
    /// </summary>
    /// <param name="resName"></param>
    /// <returns></returns>
    public UnityEngine.Object[] LoadResources(string resName)
    {
        if (abRes == null || !abRes.Contains(resName))
        {
            Debug.LogWarning("res not contain " + resName);
            return(null);
        }

        return(abRes.LoadAssetWithSubAssets(resName));
    }
Beispiel #18
0
    /// <summary>
    /// 加载多个资源文件
    /// </summary>
    /// <returns>The resoures.</returns>
    /// <param name="resname">Resname.</param>
    /// <param name="tempBundle">Temp bundle.</param>
    public UnityEngine.Object[] LoadResoures(string resname, AssetBundle tempBundle)

    {
        if (tempBundle == null || tempBundle.Contains(resname))
        {
            Debug.Log("res is not constain");
            return(null);
        }
        return(tempBundle.LoadAssetWithSubAssets(resname));
    }
        public override Asset[] LoadAssetWithSubAssets(string assetName, Type type)
        {
            List <Asset> rli    = new List <Asset>();
            var          assets = assetBundle.LoadAssetWithSubAssets(assetName, type);

            foreach (var asset in assets)
            {
                rli.Add(CreateAsset(asset, assetName));
            }
            return(rli.ToArray());
        }
Beispiel #20
0
    public GameObject[] LoadPlatform(string name)
    {
        AssetBundle bundle = AssetBundle.LoadFromFile(CustomPlatformsDictionary[name].Info.FullName);

        GameObject[] platformPrefab = bundle.LoadAssetWithSubAssets <GameObject>("_CustomPlatform");

        bundle.Unload(false);

        Debug.Log("Load platform/s: " + name + " " + platformPrefab.Length);
        return(platformPrefab);
    }
Beispiel #21
0
        /// <summary>
        /// 资源加载的方法
        /// </summary>
        /// <param name="resName"></param>
        /// <returns></returns>
        public UnityEngine.Object[] LoadResources(string resName)
        {
            if (this.ABRes == null)
            {
                return(null);
            }


            //  Debug.Log("LoadResources resName  ==" + resName);
            return(ABRes.LoadAssetWithSubAssets(resName));
        }
    public static int LoadAssetWithSubAssets(IntPtr l)
    {
        int result;

        try
        {
            int num = LuaDLL.lua_gettop(l);
            if (LuaObject.matchType(l, num, 2, typeof(string)))
            {
                AssetBundle assetBundle = (AssetBundle)LuaObject.checkSelf(l);
                string      name;
                LuaObject.checkType(l, 2, out name);
                UnityEngine.Object[] a = assetBundle.LoadAssetWithSubAssets(name);
                LuaObject.pushValue(l, true);
                LuaObject.pushValue(l, a);
                result = 2;
            }
            else if (LuaObject.matchType(l, num, 2, typeof(string)))
            {
                AssetBundle assetBundle2 = (AssetBundle)LuaObject.checkSelf(l);
                string      name2;
                LuaObject.checkType(l, 2, out name2);
                UnityEngine.Object[] a2 = assetBundle2.LoadAssetWithSubAssets <UnityEngine.Object>(name2);
                LuaObject.pushValue(l, true);
                LuaObject.pushValue(l, a2);
                result = 2;
            }
            else if (num == 3)
            {
                AssetBundle assetBundle3 = (AssetBundle)LuaObject.checkSelf(l);
                string      name3;
                LuaObject.checkType(l, 2, out name3);
                Type type;
                LuaObject.checkType(l, 3, out type);
                UnityEngine.Object[] a3 = assetBundle3.LoadAssetWithSubAssets(name3, type);
                LuaObject.pushValue(l, true);
                LuaObject.pushValue(l, a3);
                result = 2;
            }
            else
            {
                LuaObject.pushValue(l, false);
                LuaDLL.lua_pushstring(l, "No matched override function LoadAssetWithSubAssets to call");
                result = 2;
            }
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Beispiel #23
0
    void Awake()
    {
        // TEST
        AssetBundle bundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "AssetBundles/testbundle"));

        Sprite[] sprites = bundle.LoadAssetWithSubAssets <Sprite>("Assets/LoadedAssets/Spritesets/player.png");
        GetComponent <SpriteRenderer>().sprite = sprites[7];

        Body     body     = new Body(GetComponent <SpriteRenderer>(), sprites, transform);
        Behavior behavior = new Behavior();
        Stats    stats    = new Stats();

        Unit = new Unit(body, behavior, stats);
    }
Beispiel #24
0
 public static void CheckSubAssetsInBundle(AssetBundle assetBundle, string assetName)
 {
     GameObject[] BaseObject = assetBundle.LoadAssetWithSubAssets <GameObject>(assetName);
     if (BaseObject == null)
     {
         ETGModConsole.Log("ERROR: Selected Asset does not exist or is null!", false);
         return;
     }
     ETGModConsole.Log("Asset Count: " + BaseObject.Length, false);
     for (int i = 0; i < BaseObject.Length; i++)
     {
         ETGModConsole.Log(BaseObject[i].ToString(), false);
     }
 }
Beispiel #25
0
        public Object[] LoadAssetWithSubAssets(string assetName)
        {
            if (mAssetBundle == null)
            {
                Debug.LogError("当前资源包为空,无法获取:" + assetName);
                return(null);
            }

            if (!mAssetBundle.Contains(assetName))
            {
                Debug.LogError("当前资源包不包括:" + assetName);
                return(null);
            }

            return(mAssetBundle.LoadAssetWithSubAssets(assetName));
        }
 /// <summary>
 /// 获取带有子物体的资源
 /// </summary>
 /// <param name="assetName">资源名称</param>
 /// <returns>所有资源</returns>
 public UnityEngine.Object[] LoadAssetWithSubAssets(string assetName)
 {
     if (assetBundle == null)
     {
         Debug.LogError("当前资源包为空,无法获取该 " + assetName + " 资源");
         return(null);
     }
     else if (!assetBundle.Contains(assetName))
     {
         Debug.LogError("当前资源包里不包括 " + assetName + " 资源");
         return(null);
     }
     else
     {
         return(assetBundle.LoadAssetWithSubAssets(assetName));
     }
 }
 /// <summary>
 /// 获取带有子物体的资源
 /// </summary>
 /// <param name="assetname">资源名称</param>
 /// <returns>所有资源</returns>
 public Object[] LoadAssetWithSubAssets(string assetname)
 {
     if (m_assetBundle == null)
     {
         Debug.LogError("当前资源包为空,无法获取" + assetname + "资源");
         return(null);
     }
     else if (!m_assetBundle.Contains(assetname))
     {
         Debug.LogError("当前资源包里不存在" + assetname + "资源");
         return(null);
     }
     else
     {
         return(m_assetBundle.LoadAssetWithSubAssets(assetname));
     }
 }
Beispiel #28
0
    private void TestAutoBuild()
    {
        string      path   = string.Format("{0}/Example/Example2/LZ4Bundle/materials", Application.dataPath);
        AssetBundle bundle = AssetBundle.LoadFromFile(path);

        Object[] assets = bundle.LoadAllAssets();
        for (int i = 0; i < assets.Length; i++)
        {
            Debug.LogError("LoadAllAssets  : " + assets[i].name);
        }

        assets = bundle.LoadAssetWithSubAssets("New Material");
        for (int i = 0; i < assets.Length; i++)
        {
            Debug.LogError("LoadAllAssetsSubAssets  : " + assets[i].name);
        }
    }
Beispiel #29
0
 /// <summary>
 /// 获取带有子物体的资源[图集等]
 /// </summary>
 /// <param name="assetName">资源名字</param>
 /// <returns>所有资源</returns>
 public Object[] LoadAssetWithSubAssets(string assetName)
 {
     if (assetBundle == null)
     {
         Debug.LogError("当前资源包为空,无法获取" + assetName + "资源");
         return(null);
     }
     else if (!assetBundle.Contains(assetName))
     {
         Debug.LogError("当前资源不包含" + assetName + "资源");
         return(null);
     }
     else
     {
         return(assetBundle.LoadAssetWithSubAssets(assetName));
     }
 }
Beispiel #30
0
        private void GetAssetBundle(ref int _loadNum, AssetBundle _assetBundle)
        {
            _loadNum--;

            if (_loadNum == 0)
            {
                if (AssetManager.LOADASYNC)
                {
                    AssetManager.Instance.script.Load <T>(name, _assetBundle, LoadOver);
                }
                else
                {
                    T[] asset = _assetBundle.LoadAssetWithSubAssets <T>(name);

                    LoadOver(asset);
                }
            }
        }