Ejemplo n.º 1
0
    public AssetBundlesDatabaseBuilder(string assetPath)
    {
        _database      = ScriptableObject.CreateInstance <AssetBundlesDatabase>();
        _database.Id   = "11";
        _database.Hash = new byte[] {};
        _database.Size = 0;
        dbPath         = assetPath;

        AssetDatabase.CreateAsset(_database, dbPath);
    }
Ejemplo n.º 2
0
    public void LoadStart(AssetBundlesDatabase database)
    {
        m_progressBar.gameObject.SetActive(true);
        m_downLoadText.gameObject.SetActive(true);
        m_progressBar.sliderValue = 0.0f;
        m_downLoadText.SetText("Loading");
        m_downLoadProgressText.SetText("");
        m_loadBundleCount = database.Bundles.Count;

        ShowLoadTip(false);
    }
Ejemplo n.º 3
0
 private IEnumerable <AssetBundlesDatabase.BundleData> EnumerateUncachedBundles(AssetBundlesDatabase database)
 {
     foreach (var bundleData in database.Bundles)
     {
         int version = CachingUtils.GetVersionFromHash(bundleData.Hash);
         if (!Caching.IsVersionCached(bundleData.Filename, version) && !IsBundleInShippedDatabase(bundleData.Name, version))
         {
             yield return(bundleData);
         }
     }
 }
Ejemplo n.º 4
0
    public void DownLoadStart(AssetBundlesDatabase dataBase, List <AssetBundlesDatabase.BundleData> bundleList, int totalSize)
    {
        m_progressBar.gameObject.SetActive(true);
        m_downLoadText.gameObject.SetActive(true);
        m_progressBar.sliderValue = 0.0f;
        m_downLoadText.SetText("");
        m_downLoadBundleCount = bundleList.Count;
        m_totalSize           = ((float)totalSize) / (1024.0f);
        m_downLoadProgressText.SetText("");

        ShowLoadTip(true);
    }
Ejemplo n.º 5
0
    private void Awake()
    {
        if (_appManagerExist)
        {
            Debug.Log("destroy new AppManager");
            Destroy(gameObject);
            return;
        }
        _appManagerExist = true;

        GameObject.DontDestroyOnLoad(this.gameObject);

        _buildInfo       = Resources.Load("BuildInfo") as BuildInfo;
        _shippedDatabase = Resources.Load("AssetBundlesDatabase") as AssetBundlesDatabase;

#if !UNITY_EDITOR || (UNITY_EDITOR && DEBUG_USEBUNDLESINEDITOR)
        AssetId.CurrentResolver = AssetIdResolver;
#endif

        if (_buildInfo != null)
        {
            Console_WriteLine(">>>> Build Information <<<<");
            Console_WriteLine("   App Version: " + _buildInfo.AppVersion);
            Console_WriteLine("  Build Number: " + _buildInfo.BuildNumber);
            Console_WriteLine("    Build Date: " + _buildInfo.BuildDate);
            Console_WriteLine("  Bundle Based: " + _buildInfo.IsBundleBased.ToString());
            Console_WriteLine("    Shipped Id: " + (_shippedDatabase != null? _shippedDatabase.Id : "(null)"));
            Console_WriteLine("   Development: " + Debug.isDebugBuild.ToString());
            Console_WriteLine(" Unity Version: " + Application.unityVersion);
            Console_WriteLine(" Is Stage Build: " + _buildInfo.IsStageBuild);



            //_isStageBuild = _buildInfo.IsStageBuild;
        }
        else
        {
            //_isStageBuild = Debug.isDebugBuild;
        }

        if (_buildInfo != null)
        {
            //string versionState = "live";//_isStageBuild ? "stage" :"live";
            //string verionNumber = "v"+ _buildInfo.AppVersion;

            //_defaultVersionUrl = string.Format(_defaultVersionUrl, versionState, Platform, verionNumber);
        }
    }
Ejemplo n.º 6
0
    public IEnumerator DoLoadOneBundle(string bundleId)
    {
        AssetBundlesDatabase database = LoadAssetBundlesDatabaseFromId(_lastRunDatabaseId);

        AssetBundlesDatabase.BundleData bundleData = null;

        foreach (var bData in database.Bundles)
        {
            if (bData.Name == bundleId)
            {
                bundleData = bData;
                break;
            }
        }

        if (bundleData != null)
        {
            BundleInfo bundleInfo = new BundleInfo(bundleData);


            int version = CachingUtils.GetVersionFromHash(bundleData.Hash);

            string databaseId = _latestDatabaseId;
            string url        = UpdateUrl + "/" + databaseId + "/";
            using (var www = WWW.LoadFromCacheOrDownload(url + bundleData.Filename,
                                                         version))
            {
                yield return(www);

                bundleInfo.Bundle = www.assetBundle;
            }

            foreach (var sceneName in bundleData.SceneNames)
            {
                _scenesMap.Add(sceneName, bundleInfo);
            }

            foreach (var assetId in bundleData.AssetsIds)
            {
                _assetIdMap[assetId] = bundleInfo;
            }

            _bundlesMap.Add(bundleData.Name, bundleInfo);
        }
    }
Ejemplo n.º 7
0
    public void BuildAssetBundle(string path, BuildTarget target)
    {
        // Check for collisions
        var idSet = new HashSet <string>();
        AssetBundlesDatabase sedataBase = ScriptableObject.CreateInstance <AssetBundlesDatabase>();

        sedataBase.Id      = _database.Id;
        sedataBase.Hash    = _database.Hash;
        sedataBase.Bundles = _database.Bundles;
        sedataBase.Size    = _database.Size;
        foreach (var bundle in _database.Bundles)
        {
            if (bundle.AssetsIds != null)
            {
                if (idSet.Overlaps(bundle.AssetsIds))
                {
                    throw new UnityException("AssetId conflict");
                }

                idSet.UnionWith(bundle.AssetsIds);
            }
        }
        //EditorUtility.SetDirty(_database);
        AssetDatabase.CreateAsset(sedataBase, "Assets/Resources/AssetBundlesDatabase.asset");

        //EditorUtility.SetDirty(_database);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();


        string objPath = AssetDatabase.GetAssetPath(_database);

        if (!BuildPipeline.BuildAssetBundle(sedataBase,
                                            null,
                                            path,
                                            BuildAssetBundleOptions.CompleteAssets |
                                            BuildAssetBundleOptions.CollectDependencies |
                                            BuildAssetBundleOptions.DeterministicAssetBundle,
                                            target))
        {
            throw new UnityException("Error building asset bundles database bundle");
        }
    }
Ejemplo n.º 8
0
 public void Setup(AssetBundlesDatabase database, string bundlesDirectory)
 {
     _database         = database;
     _bundlesDirectory = bundlesDirectory;
 }
Ejemplo n.º 9
0
    private IEnumerator DoDownloadBundles(string databaseId)
    {
        ResetUpdateError();


        Console_WriteLine("Downloading database " + databaseId + "...");


        if (DownloadingStart != null)
        {
            DownloadingStart();
        }

        if (DownloadingBundleStart != null)
        {
            DownloadingBundleStart();
        }


        if (DownloadingDatabase != null)
        {
            DownloadingDatabase(databaseId);
        }

        AssetBundlesDatabase database = _shippedDatabase;

        if (databaseId != _shippedDatabase.Id)
        {
            if (!Caching.IsVersionCached("index", CachingUtils.GetVersionFromId(databaseId)))
            {
                if (Application.internetReachability == NetworkReachability.NotReachable)
                {
                    ThrowUpdateError(UpdateErrorType.NoInternetAvailable);
                    yield break;
                }
            }


            // Download requested database
            int version = CachingUtils.GetVersionFromId(databaseId);



            // This do-while: workaround of unity bug of caching startup delay
            do
            {
                using (WWW www = WWW.LoadFromCacheOrDownload(UpdateUrl + "/" + databaseId + "/index", version))
                {
                    yield return(StartCoroutine(WwwDone(www)));

                    if (WwwHasBundleError(www))
                    {
                    }
                    else
                    {
                        database = www.assetBundle.mainAsset as AssetBundlesDatabase;
                        www.assetBundle.Unload(false);
                    }
                }
            } while (!Caching.IsVersionCached("index", version));
        }
        else
        {
            database = _shippedDatabase;
        }

        int totalDownloadSize = 0;

        var bundlesToDownload = new List <AssetBundlesDatabase.BundleData>();

        // Check which bundles must be downloaded/cached
        foreach (var bundleData in EnumerateUncachedBundles(database))
        {
            totalDownloadSize += bundleData.Size;
            bundlesToDownload.Add(bundleData);
        }

        if (bundlesToDownload.Count == 0)
        {
            yield break;
        }

        if (DownloadStart != null)
        {
            DownloadStart(database, bundlesToDownload, totalDownloadSize);
        }

        int totalDownloadedBytes = 0;

        if (bundlesToDownload.Count > 0)
        {
            Console_WriteLine("Will download " + bundlesToDownload.Count + " bundles, with a total of " + totalDownloadSize + " bytes");


            string url = UpdateUrl + "/" + databaseId + "/";

            //foreach (var bundleData in bundlesToDownload)
            for (int i = 0; i < bundlesToDownload.Count;)
            {
                var bundleData = bundlesToDownload.ElementAt(i);

                Console_WriteLine("Downloading bundle " + bundleData.Name + "...");

                using (var www = WWW.LoadFromCacheOrDownload(url + bundleData.Filename,
                                                             CachingUtils.GetVersionFromHash(bundleData.Hash)))
                {
                    int previousDownloadedBytes = totalDownloadedBytes;

                    yield return(StartCoroutine(WwwDone(www, () => {
                        totalDownloadedBytes = previousDownloadedBytes + (int)(www.progress * (float)bundleData.Size);

                        if (DownloadProgress != null)
                        {
                            DownloadProgress(bundlesToDownload.IndexOf(bundleData), totalDownloadedBytes);
                        }
                    })));

                    if (WwwHasBundleError(www))
                    {
                    }
                    else
                    {
                        www.assetBundle.Unload(false);
                        totalDownloadedBytes = previousDownloadedBytes + bundleData.Size;
                    }
                }

                i++;
            }
        }

        Console_WriteLine("Database downloaded");
        if (DownloadingBundleEnd != null)
        {
            DownloadingBundleEnd("success", "url");
        }

        if (DownloadingFinish != null)
        {
            DownloadingFinish();
        }
    }