コード例 #1
0
 // Returns true if more Update calls are required.
 public override bool Update()
 {
     //base.Update();
     if (m_Request == null)
     {
         LoadedAssetBundle loadedBundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);
         if (loadedBundle != null)
         {
             if (_isJsonIndex)
             {
                 AssetBundleManager.AssetBundleIndexObject = ScriptableObject.CreateInstance <AssetBundleIndex>();
                 JsonUtility.FromJsonOverwrite(loadedBundle.m_data, AssetBundleManager.AssetBundleIndexObject);
             }
             else
             {
                 if (loadedBundle.m_AssetBundle == null)
                 {
                     Debug.LogWarning("AssetBundle was null for " + m_AssetBundleName);
                     return(false);
                 }
                 m_Request = loadedBundle.m_AssetBundle.LoadAssetAsync <AssetBundleIndex>(m_AssetName);
             }
         }
     }
     if (m_Request != null && m_Request.isDone)
     {
         AssetBundleManager.AssetBundleIndexObject = GetAsset <AssetBundleIndex>();
         //If there is an AssetBundleManager.m_ConnectionChecker and it is set to m_ConnectionChecker.UseBundleIndexCaching
         //cache this so we can use it offline if we need to
         if (AssetBundleManager.ConnectionChecker != null && AssetBundleManager.ConnectionChecker.UseBundleIndexCaching == true)
         {
             if (AssetBundleManager.AssetBundleIndexObject != null)
             {
                 Debug.Log("Caching downloaded index with Build version " + AssetBundleManager.AssetBundleIndexObject.bundlesPlayerVersion);
                 var cachedIndexPath = Path.Combine(Application.persistentDataPath, "cachedBundleIndex");
                 if (!Directory.Exists(cachedIndexPath))
                 {
                     Directory.CreateDirectory(cachedIndexPath);
                 }
                 cachedIndexPath = Path.Combine(cachedIndexPath, m_AssetBundleName + ".json");
                 File.WriteAllText(cachedIndexPath, JsonUtility.ToJson(AssetBundleManager.AssetBundleIndexObject));
             }
         }
         return(false);
     }
     if (AssetBundleManager.AssetBundleIndexObject != null)
     {
         return(false);
     }
     else
     {
         // if there has been an error make this return false
         //It wont need any more updates and ABM needs to put it in failed downloads
         if (string.IsNullOrEmpty(m_DownloadingError))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }