public SceneAsyncLoader(string name, bool additive)
 {
     _assetLoader      = null;
     _async            = null;
     _lastShowProgress = 0f;
     _sceneName        = name;
     _additive         = additive;
     GameClient.Instance.StartCoroutine(LoadScene());
 }
        public void Dispose()
        {
            string key = ResourceManager.Instance.GetResourceKey(_sceneName + ".unity");

            if (!string.IsNullOrEmpty(key))
            {
                ResourceManager.Instance.RemoveUnreferenceAssetBundle(key);
            }
            _assetLoader = null;
            _async       = null;

            GC.SuppressFinalize(this);
        }
        IEnumerator LoadScene()
        {
            string key = ResourceManager.Instance.GetResourceKey(_sceneName + ".unity");

            if (!string.IsNullOrEmpty(key))
            {
                _assetLoader = new AssertBundleAsyncLoader();
                yield return(ResourceManager.Instance.LoadAssetBundleAsync(key, _assetLoader));

                _assetLoader.progress = 1f;
            }

            yield return(0);

            _async = SceneManager.LoadSceneAsync(_sceneName, _additive ? LoadSceneMode.Additive : LoadSceneMode.Single);
        }
        public IEnumerator LoadAssetBundleAsync(string key, AssertBundleAsyncLoader asyncLoader)
        {
            asyncLoader.progress = 0;

            if (_resourceList == null)
            {
                yield break;
            }

            if (!_resourceList.Resources.ContainsKey(key))
            {
                yield break;
            }

            AssetBundle asset = null;

            if (_loadedAssetBundles.ContainsKey(key))
            {
                asset = _loadedAssetBundles[key];

                if (asset != null)
                {
                    asyncLoader.assetBundle = asset;

                    yield break;
                }
            }

            ResourceData rd        = _resourceList.Resources[key];
            float        childRate = 1 / (rd.Depends.Count + 1);
            int          loadCount = 0;

            for (int i = 0; i < rd.Depends.Count; ++i)
            {
                LoadAssetBundle(rd.Depends[i], key);
                asyncLoader.progress = (++loadCount) * childRate;
                TimeSpan ts = DateTime.Now - asyncLoader.lastUpdateTime;
                if (ts.TotalSeconds > 0.3d)
                {
                    asyncLoader.lastUpdateTime = DateTime.Now;
                    yield return(0);
                }
            }

            string filename    = GetResourceFileName(key);
            string assetFile   = "";
            bool   isStreaming = false;

            if (rd.IsOptional())
            {
                assetFile = _optionalPath + filename;
            }
            else
            {
                assetFile = _dataPath + filename;
                if (!File.Exists(assetFile))
                {
#if UNITY_ANDROID && !UNITY_EDITOR
                    assetFile = filename;
#else
                    assetFile = _streamingPath + filename;
#endif
                    isStreaming = true;
                }
            }

            if (asset == null)
            {
                asset = LoadAssetBundleFile(assetFile, isStreaming);
            }

            if (asset == null)
            {
                Debugger.LogError("Load AssetBundle : " + key + " fail! 2");
                Debugger.LogError("Resource path : " + rd.Path);
            }
            else
            {
                AddUnreferenceAssetBundle(key, asset);
                asyncLoader.assetBundle = asset;
            }

            asyncLoader.progress = 1;
        }