コード例 #1
0
    private IEnumerator UpdateResourceLocatorsAsync()
    {
        Addressables.ClearResourceLocators();
        string[] catalogs = null;
        if (Directory.Exists(addressablesDir))
        {
            catalogs = GetCatalogs(addressablesDir, "json", SearchOption.TopDirectoryOnly);
            for (int i = 0; i < catalogs.Length; i++)
            {
                var catalogHandle = Addressables.LoadContentCatalogAsync(catalogs[i]);
                yield return(catalogHandle);

                Addressables.AddResourceLocator(catalogHandle.Result);
                Addressables.Release(catalogHandle);
            }
        }
        if (catalogs == null || catalogs.Length == 0)
        {
            catalogs = GetCatalogs(Addressables.RuntimePath, "json", SearchOption.TopDirectoryOnly);
            for (int i = 0; i < catalogs.Length; i++)
            {
                var catalogHandle = Addressables.LoadContentCatalogAsync(catalogs[i]);
                yield return(catalogHandle);

                Addressables.AddResourceLocator(catalogHandle.Result);
                Addressables.Release(catalogHandle);
            }
        }
    }
コード例 #2
0
        /// <summary>
        /// Addressable の初期化処理が失敗した場合に初期化前の状態に戻す為の関数
        /// </summary>
        public static void ResetInitializationFlag(bool version_1_9_2_OrNewer)
        {
            // Addressables.InitializeAsync に失敗した場合も、内部では初期化済みフラグが立ってしまうため、
            // リフレクションを使用して内部の初期化フラグを落とします
            var addressablesType     = typeof(Addressables);
            var assembly             = addressablesType.Assembly;
            var addressablesImplType = assembly.GetType("UnityEngine.AddressableAssets.AddressablesImpl");

            var addressablesImpl = version_1_9_2_OrNewer
                                ? addressablesType.GetProperty("m_Addressables", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null)
                                : addressablesType.GetField("m_Addressables", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

            var hasStartedInitializationField = addressablesImplType.GetField("hasStartedInitialization", BindingFlags.Instance | BindingFlags.NonPublic);

            hasStartedInitializationField.SetValue(addressablesImpl, false);

            // Addressables.InitializeAsync に失敗した場合も、
            // ローカルカタログから情報が読み込まれてしまうため、
            // 読み込まれているローカルカタログの情報を破棄します
            Addressables.ClearResourceLocators();
        }
コード例 #3
0
    IEnumerator Process()
    {
        Addressables.InitializeAsync().Completed += InitDone;

        while (isCloudInit != true)
        {
            yield return(new WaitForFixedUpdate());
        }
        Addressables.ClearResourceLocators();

        Addressables.LoadContentCatalogAsync("https://storage.googleapis.com/cloud_patching_sample/Android/catalog_" + catalogKeyname + ".json").Completed += Cloud_Completed;
        while (contentCatalogLoaded != true)
        {
            yield return(frequencyshort);
        }

        Addressables.CheckForCatalogUpdates(false).Completed += (AsyncOperationHandle <List <string> > cb_checkforupdates) => StartCoroutine(CheckCatalogVersion(cb_checkforupdates));
        //StartCoroutine(CheckCatalogVersion());

        while (isCheckedPatch != true)
        {
            yield return(new WaitForFixedUpdate());
        }

        Debug.Log("Patch checked!");

        if (requireDownloadPatch)
        {
            Debug.Log("Pending download...");
            while (pendingDownload != true)
            {
                yield return(new WaitForFixedUpdate());

                if (proceedDownloadingPatch)
                {
                    pendingDownload = proceedDownloadingPatch;
                    Debug.Log("patch responded");
                }
            }

            if (agreedDownload)
            {
                Debug.Log("Downloading patch...");

                AsyncOperationHandle cb_downloads = Addressables.DownloadDependenciesAsync(downloadKey, false);

                while (cb_downloads.PercentComplete < 1)
                {
                    yield return(new WaitForFixedUpdate());

                    Debug.Log(cb_downloads.PercentComplete);

                    UI_MANAGER.UpdateDynamicContent(cb_downloads.PercentComplete.ToString());
                }
                Debug.Log("Download done" + cb_downloads.Status);
                yield return(new WaitForSeconds(5f));

                UI_MANAGER.RemoveAndClear();

                Addressables.UpdateCatalogs().Completed += OnUpdateCatalogs;

                while (downloadDone != true)
                {
                    yield return(new WaitForSeconds(0.25f));
                }

                InitialiseAssetsSpawn();
            }
            else
            {
                Debug.Log("No downloading...");
            }
        }
        else
        {
            Debug.Log("No patch to update...");
            InitialiseAssetsSpawn();
        }
    }
コード例 #4
0
 /// <summary>
 /// Remove all locators.
 /// </summary>
 public static void ClearResourceLocators()
 {
     Addressables.ClearResourceLocators();
 }