/// <summary>
        /// Disposes the reference.
        /// </summary>
        private void Dispose()
        {
            Debug.LogWarningFormat("AssetBundleReference.Dispose(): {0}", m_AssetBundleName);

            if (References.ContainsKey(m_AssetBundleName))
            {
                References.Remove(m_AssetBundleName);
                m_AssetBundleName = null;
            }

            if (m_Coroutine != null)
            {
                if (AssetBundleLoader.Instance)
                {
                    AssetBundleLoader.Instance.StopCoroutine(m_Coroutine);
                }
                m_Coroutine = null;
            }

            if (m_AssetBundle != null)
            {
                m_AssetBundle.Unload(false);
                m_AssetBundle = null;
            }

            if (m_Adaptor != null)
            {
                m_Adaptor.Dispose();
                m_Adaptor = null;
            }

            m_Error       = null;
            m_KeepWaiting = false;
        }
        public void Dispose()
        {
            Debug.Log("LowDiskSpaceAssetBundleAdaptor-> Dispose", DebugContext.SagoApp);

            if (m_Adaptor != null)
            {
                m_Adaptor.Dispose();
                m_Adaptor = null;
            }

            if (m_LowDiskSpaceAssetBundleAdaptors.Contains(this))
            {
                m_LowDiskSpaceAssetBundleAdaptors.Remove(this);
            }
        }
        public LowDiskSpaceAssetBundleAdaptor(IAssetBundleAdaptor adaptor)
        {
            if (adaptor == null)
            {
                Debug.LogWarning("LowDiskSpaceAssetBundleAdaptor-> adaptor instance passed to constructor is null.", DebugContext.SagoApp);
                return;
            }

            m_IsCancelled = false;
            m_Adaptor     = adaptor;

            if (!m_LowDiskSpaceAssetBundleAdaptors.Contains(this))
            {
                m_LowDiskSpaceAssetBundleAdaptors.Add(this);
            }
        }
        /// <summary>
        /// <see cref="AssetBundleReference" />
        /// </summary>
        private IEnumerator AssetBundleReferenceImpl(string assetBundleName)
        {
            Retain();

            if (CreateAdaptor == null)
            {
                m_Error       = string.Format("Could not create adaptor: not implemented.");
                m_KeepWaiting = false;
                m_Progress    = -1;
                Release();
                yield break;
            }

            m_Adaptor = CreateAdaptor(assetBundleName);

            if (m_Adaptor == null)
            {
                m_Error       = string.Format("Could not create adaptor for asset bundle: {0}", assetBundleName);
                m_KeepWaiting = false;
                m_Progress    = -1;
                Release();
                yield break;
            }

            while (!m_Adaptor.isDone)
            {
                m_Progress = m_Adaptor.progress;
                yield return(null);
            }

            if (!string.IsNullOrEmpty(m_Adaptor.error))
            {
                m_Error = m_Adaptor.error;
                m_Adaptor.Dispose();
                m_Adaptor     = null;
                m_KeepWaiting = false;
                m_Progress    = -1;
                Release();
                yield break;
            }

            m_AssetBundle = m_Adaptor.assetBundle;
            m_KeepWaiting = false;
            m_Progress    = 1;
            Release();
            yield break;
        }
        /// <summary>
        /// Creates a new <see cref="AssetBundleReference" /> instance.
        /// <summary>
        /// <remarks>
        /// The constructor is private in order to make sure there are never two
        /// <see cref="AssetBundleReference" /> instances with the same asset bundle
        /// name. To create an <see create="AssetBundleReference" />, use the static
        /// <see cref="FindOrCreateReference()" /> method.
        /// </remarks>
        private AssetBundleReference(string assetBundleName)
        {
            if (AssetBundleLoader.Instance)
            {
                m_Adaptor         = null;
                m_AssetBundle     = null;
                m_AssetBundleName = assetBundleName;
                m_Error           = null;
                m_KeepWaiting     = true;
                m_ReferenceCount  = 0;

                Retain();
                Autorelease();

                m_Coroutine = AssetBundleReferenceImpl(assetBundleName);
                AssetBundleLoader.Instance.StartCoroutine(m_Coroutine);
            }
        }