Ejemplo n.º 1
0
        private IEnumerator LoadAssetBundle(string assetBundle)
        {
            if (_assetBundleList.ContainsKey(assetBundle))
            {
                Debug.LogWarning($"Already loaded asset - {assetBundle}");
                ++loadedAssetBundleCount;
                yield break;
            }

            var path    = Path.Combine(localAssetBundlePath, assetBundle);
            var request = AssetBundle.LoadFromFileAsync(path, 0);

            while (request.isDone == false)
            {
                currentAssetBundleProgress = request.progress;
                yield return(null);
            }

            var bundle = request.assetBundle;

            if (bundle == null)
            {
                Debug.LogError($"Failed to load - {assetBundle} is NULL!");
                state = STATE.ERROR;
                yield break;
            }

            _assetBundleList.Add(assetBundle, bundle);

            ++loadedAssetBundleCount;
            Debug.Log($"Succeeded to load - {assetBundle}");
        }
Ejemplo n.º 2
0
 public void UnBindButtonEvent(string bindName)
 {
     if (this._bindInfoGroup.ContainsKey(bindName) == false)
     {
         Debug.LogWarning($"Not Binding Info Bind Name : {bindName}");
         return;
     }
     this._bindInfoGroup.Remove(bindName);
 }
Ejemplo n.º 3
0
 public void BindButtonEvent(string bindName, IInputBindParam bindParam)
 {
     if (this._bindInfoGroup.ContainsKey(bindName) == true)
     {
         Debug.LogWarning($"Already Binding Info Bind Name : {bindName}");
         return;
     }
     this._bindInfoGroup.Add(bindName, bindParam);
 }
        public override T Load <T>(string assetBundleName, string assetName)
        {
            if (isInitialized == false)
            {
                Debug.LogWarning("Initialized FIRST!");
                return(null);
            }

            var result = assetBundleManager.LoadAsset <T>(assetBundleName, assetName);

            return(result);
        }
        public override async Task <T> LoadAsync <T>(string assetBundleName, string assetName)
        {
            if (isInitialized == false)
            {
                Debug.LogWarning("Initialized FIRST!");
                return(null);
            }

            var result = await Observable.Start(async() =>
            {
                var asset = await assetBundleManager.LoadAssetAsync <T>(assetBundleName, assetName);

                if (asset == null)
                {
                    Debug.LogError($"{assetName} is null");
                    return(null);
                }

                return(asset);
            });

            return(result.Result);
        }
Ejemplo n.º 6
0
        public IEnumerator PrepareDownload(string url, string manifestName)
        {
            // NOTE(JJO): url이 비어있다면 EDITOR모드임을 가정함.
            if (string.IsNullOrEmpty(url))
            {
                state = STATE.LOADED;
                yield break;
            }

            state = STATE.PREPARING;

            downloadUrl = url;

            // TODO(JJO): StreamingAssets에서 로드한 흔적을 찾는다.
            string manifestSA     = null;
            string manifestRemote = null;

            var pathSA = Path.Combine(Application.streamingAssetsPath, "Bundle");
            var path   = Path.Combine(pathSA, $"{manifestName}.manifest");

            using (var request = UnityWebRequest.Get(path))
            {
                yield return(request.SendWebRequest());

                if (string.IsNullOrEmpty(request.error) == false)
                {
                    Debug.LogWarning($"{manifestName} is NOT FOUND from StreamingAssets");
                }
                else
                {
                    manifestSA = request.downloadHandler.text;
                }
            }

            path = $"{downloadUrl}{manifestName}.manifest";
            using (var request = UnityWebRequest.Get(path))
            {
                yield return(request.SendWebRequest());

                if (string.IsNullOrEmpty(request.error) == false)
                {
                    Debug.LogError($"Failed to download - {path}\nReason: {request.error}");
                    state = STATE.ERROR;
                    yield break;
                }

                manifestRemote = request.downloadHandler.text;
            }

            if (string.IsNullOrEmpty(manifestSA) == false &&
                manifestSA == manifestRemote)
            {
                // NOTE(JJO): 그냥 여기에서 바로 S.A로부터 로드해버리자.
                path = Path.Combine(pathSA, manifestName);
                var request = AssetBundle.LoadFromFileAsync(path);

                yield return(request);

                _assetBundleManifestObject = request.assetBundle;
                if (_assetBundleManifestObject == null)
                {
                    Debug.LogError($"Failed to load - {path}\nReason: Unknown");
                    state = STATE.ERROR;
                    yield break;
                }

                _assetBundleManifest = _assetBundleManifestObject.LoadAsset <AssetBundleManifest>(nameof(AssetBundleManifest));

                var assetList = _assetBundleManifest.GetAllAssetBundles();
                var listCount = assetList.Length;
                for (int i = 0; i < listCount; ++i)
                {
                    path    = Path.Combine(pathSA, assetList[i]);
                    request = AssetBundle.LoadFromFileAsync(path);

                    yield return(request);

                    var bundle = request.assetBundle;
                    if (bundle == null)
                    {
                        Debug.LogError($"Failed to load - {path}\nReason: Unknown");
                        state = STATE.ERROR;
                        yield break;
                    }

                    _assetBundleList.Add(assetList[i], bundle);
                    Debug.Log($"Preload from StreamingAssets - {assetList[i]}");
                }
            }
            else
            {
                path = $"{downloadUrl}{manifestName}";
                using (var req = UnityWebRequestAssetBundle.GetAssetBundle(path))
                {
                    yield return(req.SendWebRequest());

                    if (string.IsNullOrEmpty(req.error) == false)
                    {
                        Debug.LogError($"Failed to download - {path}\nReason: Unknown");
                        state = STATE.ERROR;
                        yield break;
                    }

                    _assetBundleManifestObject = DownloadHandlerAssetBundle.GetContent(req);
                    _assetBundleManifest       = _assetBundleManifestObject.LoadAsset <AssetBundleManifest>(nameof(AssetBundleManifest));
                }

                var assetList = _assetBundleManifest.GetAllAssetBundles();
                var listCount = assetList.Length;
                for (int i = 0; i < listCount; ++i)
                {
                    path = Path.Combine(pathSA, $"{assetList[i]}.manifest");
                    using (var req = UnityWebRequest.Get(path))
                    {
                        yield return(req.SendWebRequest());

                        // NOTE(JJO): StreamingAssets에 파일이 없다면 바로 다운로드 리스트에 추가함.
                        if (string.IsNullOrEmpty(req.error))
                        {
                            manifestSA = req.downloadHandler.text;
                        }
                    }

                    path = $"{downloadUrl}{assetList[i]}.manifest";
                    using (var req = UnityWebRequest.Get(path))
                    {
                        yield return(req.SendWebRequest());

                        if (string.IsNullOrEmpty(req.error) == false)
                        {
                            Debug.LogError($"Network Error - {assetList[i]}\n{req.error}");
                            state = STATE.ERROR;
                            yield break;
                        }

                        manifestRemote = req.downloadHandler.text;
                    }

                    // NOTE(JJO): Manifest가 다르다면 다운로드 리스트에 추가함.
                    if (string.IsNullOrEmpty(manifestSA) ||
                        manifestSA != manifestRemote)
                    {
                        _downloadingAssetBundleList.Add(assetList[i], GetCRC(manifestRemote));
                    }
                    else
                    {
                        path = Path.Combine(pathSA, assetList[i]);
                        var request = AssetBundle.LoadFromFileAsync(path);

                        yield return(request);

                        var bundle = request.assetBundle;
                        if (bundle == null)
                        {
                            Debug.LogError($"{assetList[i]} NOT FOUND!");
                            state = STATE.ERROR;
                            yield break;
                        }

                        _assetBundleList.Add(assetList[i], bundle);
                        Debug.Log($"Preload from StreamingAssets - {assetList[i]}");
                    }
                }

                maximumAssetBundleCount = _downloadingAssetBundleList.Count;
            }
        }