Пример #1
0
 public LoadAssetRequest <T> LoadAssetAsync <T>(string name) where T : UnityEngine.Object
 {
     if (assetCache.TryGetValue(name, out var obj))
     {
         AssetBundleLoadAssetRequest <T> request = new AssetBundleLoadAssetRequest <T>(obj.name);
         request.SetAsset(obj as T);
         return(request);
     }
     if (assetLocations.TryGetValue(name, out int location))
     {
         int bundleIndex = location >> 16;
         int assetIndex  = location & 0xFFFF;
         var bundle      = mainBundles[bundleIndex];
         CheckAndLoadAssetBundle(bundle);
         var request = bundle.LoadAsync <T>(assetIndex);
         request.OnComplete += (r) =>
         {
             if (!assetCache.ContainsKey(name))
             {
                 assetCache.Add(name, request.Asset);
             }
         };
         return(request);
     }
     Debug.LogErrorFormat("资源不存在 : {0}", name);
     return(null);
 }
Пример #2
0
        public LoadAssetRequest <T> LoadAsync <T>(int index) where T : Object
        {
            AssetBundleLoadAssetRequest <T> request = new AssetBundleLoadAssetRequest <T>(Assets[index]);

            if (Bundle)
            {
                DoRequest(request);
            }
            else
            {
                Requests.Add(request);
            }

            return(request);
        }