Exemplo n.º 1
0
        public void LoadBundle(BundleLoaderTypes type, Action <Figure> OnSuccess, Action <Exception> OnFail)
        {
            if (cacheResults && cachedBundles.TryGetValue(type, out Figure figure))
            {
                OnSuccess(figure);
                StopPendingCoroutine();
                return;
            }

            StopPendingCoroutine();
            _pendingCoroutine = StartCoroutine(WaitForRequest(type, OnSuccess, OnFail));
        }
Exemplo n.º 2
0
        IEnumerator WaitForRequest(BundleLoaderTypes type, Action <Figure> OnSuccess, Action <Exception> OnFail)
        {
            UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle($"{url}/{type}");

            yield return(www.SendWebRequest());


            if (www.result != UnityWebRequest.Result.Success)
            {
                OnFail(new Exception(www.error));
            }
            else
            {
                try
                {
                    var content = DownloadHandlerAssetBundle.GetContent(www);
                    var figure  = content.LoadAsset <GameObject>($"{type.ToString()}.prefab").GetComponent <Figure>();
                    if (figure != null)
                    {
                        OnSuccess(figure);
                        if (cacheResults ! && cachedBundles.TryGetValue(type, out Figure cachedFigure))
                        {
                            cachedBundles.Add(type, figure);
                        }
                    }
                    else
                    {
                        OnFail(new Exception("no element in bundle"));
                    }
                }
                catch (Exception _)
                {
                    OnFail(_);
                }
                finally
                {
                    AssetBundle.UnloadAllAssetBundles(false);
                }
            }
        }
Exemplo n.º 3
0
 private void SpawnFigure(BundleLoaderTypes type)
 {
     asyncBundleLoader.LoadBundle(type, OnLoadSuccess, OnLoadFailed);
     spawnUIController.StartSpawn();
 }
Exemplo n.º 4
0
 private void OnCancelClicked()
 {
     spawnType = BundleLoaderTypes.none;
     StartSpawn();
 }
Exemplo n.º 5
0
 private void OnSelectButtonClicked(BundleLoaderTypes type)
 {
     spawnType = type;
     selectPage.Close();
     spawnPage.Open();
 }
Exemplo n.º 6
0
 public void StartSpawn()
 {
     selectPage.Open();
     spawnPage.Close();
     spawnType = BundleLoaderTypes.none;
 }
Exemplo n.º 7
0
 private void OnSpawnButtonClicked(BundleLoaderTypes types)
 {
     SelectFigureAction?.Invoke(types);
 }