Esempio n. 1
0
 private void UpdateAssetBundleRequest()
 {
     if (m_AssetBundleRequest != null)
     {
         if (m_AssetBundleRequest.isDone)
         {
             if (m_AssetBundleRequest.asset != null)
             {
                 InnerLoadResourceAgentHelperLoadCompleteEventArgs loadResourceAgentHelperLoadCompleteEventArgs = InnerLoadResourceAgentHelperLoadCompleteEventArgs.Create(m_AssetBundleRequest.asset);
                 m_LoadResourceAgentHelperLoadCompleteEventHandler(this, loadResourceAgentHelperLoadCompleteEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperLoadCompleteEventArgs);
                 m_AssetName          = null;
                 m_LastProgress       = 0f;
                 m_AssetBundleRequest = null;
             }
             else
             {
                 InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = InnerLoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.AssetError, DBD.Utility.Text.Format("Can not load asset '{0}' from asset bundle which is not exist.", m_AssetName));
                 m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperErrorEventArgs);
             }
         }
         else if (m_AssetBundleRequest.progress != m_LastProgress)
         {
             m_LastProgress = m_AssetBundleRequest.progress;
             InnerLoadResourceAgentHelperUpdateEventArgs loadResourceAgentHelperUpdateEventArgs = InnerLoadResourceAgentHelperUpdateEventArgs.Create(LoadResourceProgress.LoadAsset, m_AssetBundleRequest.progress);
             m_LoadResourceAgentHelperUpdateEventHandler(this, loadResourceAgentHelperUpdateEventArgs);
             ReferencePool.Release(loadResourceAgentHelperUpdateEventArgs);
         }
     }
 }
Esempio n. 2
0
 private void UpdateAsyncOperation()
 {
     if (m_AsyncOperation != null)
     {
         if (m_AsyncOperation.isDone)
         {
             if (m_AsyncOperation.allowSceneActivation)
             {
                 InnerLoadResourceAgentHelperLoadCompleteEventArgs loadResourceAgentHelperLoadCompleteEventArgs = InnerLoadResourceAgentHelperLoadCompleteEventArgs.Create(new SceneAsset());
                 m_LoadResourceAgentHelperLoadCompleteEventHandler(this, loadResourceAgentHelperLoadCompleteEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperLoadCompleteEventArgs);
                 m_AssetName      = null;
                 m_LastProgress   = 0f;
                 m_AsyncOperation = null;
             }
             else
             {
                 InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = InnerLoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.AssetError, DBD.Utility.Text.Format("Can not load scene asset '{0}' from asset bundle.", m_AssetName));
                 m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperErrorEventArgs);
             }
         }
         else if (m_AsyncOperation.progress != m_LastProgress)
         {
             m_LastProgress = m_AsyncOperation.progress;
             InnerLoadResourceAgentHelperUpdateEventArgs loadResourceAgentHelperUpdateEventArgs = InnerLoadResourceAgentHelperUpdateEventArgs.Create(LoadResourceProgress.LoadScene, m_AsyncOperation.progress);
             m_LoadResourceAgentHelperUpdateEventHandler(this, loadResourceAgentHelperUpdateEventArgs);
             ReferencePool.Release(loadResourceAgentHelperUpdateEventArgs);
         }
     }
 }
Esempio n. 3
0
 private void UpdateBytesAssetBundleCreateRequest()
 {
     if (m_BytesAssetBundleCreateRequest != null)
     {
         if (m_BytesAssetBundleCreateRequest.isDone)
         {
             AssetBundle assetBundle = m_BytesAssetBundleCreateRequest.assetBundle;
             if (assetBundle != null)
             {
                 AssetBundleCreateRequest oldBytesAssetBundleCreateRequest = m_BytesAssetBundleCreateRequest;
                 InnerLoadResourceAgentHelperParseBytesCompleteEventArgs loadResourceAgentHelperParseBytesCompleteEventArgs = InnerLoadResourceAgentHelperParseBytesCompleteEventArgs.Create(assetBundle);
                 m_LoadResourceAgentHelperParseBytesCompleteEventHandler(this, loadResourceAgentHelperParseBytesCompleteEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperParseBytesCompleteEventArgs);
                 if (m_BytesAssetBundleCreateRequest == oldBytesAssetBundleCreateRequest)
                 {
                     m_BytesAssetBundleCreateRequest = null;
                     m_LastProgress = 0f;
                 }
             }
             else
             {
                 InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = InnerLoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.NotExist, "Can not load asset bundle from memory which is not a valid asset bundle.");
                 m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperErrorEventArgs);
             }
         }
         else if (m_BytesAssetBundleCreateRequest.progress != m_LastProgress)
         {
             m_LastProgress = m_BytesAssetBundleCreateRequest.progress;
             InnerLoadResourceAgentHelperUpdateEventArgs loadResourceAgentHelperUpdateEventArgs = InnerLoadResourceAgentHelperUpdateEventArgs.Create(LoadResourceProgress.LoadResource, m_BytesAssetBundleCreateRequest.progress);
             m_LoadResourceAgentHelperUpdateEventHandler(this, loadResourceAgentHelperUpdateEventArgs);
             ReferencePool.Release(loadResourceAgentHelperUpdateEventArgs);
         }
     }
 }
Esempio n. 4
0
 private void UpdateFileAssetBundleCreateRequest()
 {
     if (m_FileAssetBundleCreateRequest != null)
     {
         if (m_FileAssetBundleCreateRequest.isDone)
         {
             AssetBundle assetBundle = m_FileAssetBundleCreateRequest.assetBundle;
             if (assetBundle != null)
             {
                 AssetBundleCreateRequest oldFileAssetBundleCreateRequest = m_FileAssetBundleCreateRequest;
                 InnerLoadResourceAgentHelperReadFileCompleteEventArgs loadResourceAgentHelperReadFileCompleteEventArgs = InnerLoadResourceAgentHelperReadFileCompleteEventArgs.Create(assetBundle);
                 m_LoadResourceAgentHelperReadFileCompleteEventHandler(this, loadResourceAgentHelperReadFileCompleteEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperReadFileCompleteEventArgs);
                 if (m_FileAssetBundleCreateRequest == oldFileAssetBundleCreateRequest)
                 {
                     m_FileAssetBundleCreateRequest = null;
                     m_LastProgress = 0f;
                 }
             }
             else
             {
                 InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = InnerLoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.NotExist, Utility.Text.Format("Can not load asset bundle from file '{0}' which is not a valid asset bundle.", m_FileName == null ? m_FileFullPath : Utility.Text.Format("{0} | {1}", m_FileFullPath, m_FileName)));
                 m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperErrorEventArgs);
             }
         }
         else if (m_FileAssetBundleCreateRequest.progress != m_LastProgress)
         {
             m_LastProgress = m_FileAssetBundleCreateRequest.progress;
             InnerLoadResourceAgentHelperUpdateEventArgs loadResourceAgentHelperUpdateEventArgs = InnerLoadResourceAgentHelperUpdateEventArgs.Create(LoadResourceProgress.LoadResource, m_FileAssetBundleCreateRequest.progress);
             m_LoadResourceAgentHelperUpdateEventHandler(this, loadResourceAgentHelperUpdateEventArgs);
             ReferencePool.Release(loadResourceAgentHelperUpdateEventArgs);
         }
     }
 }
        /// <summary>
        /// 创建加载资源代理辅助器错误事件。
        /// </summary>
        /// <param name="status">加载资源状态。</param>
        /// <param name="errorMessage">错误信息。</param>
        /// <returns>创建的加载资源代理辅助器错误事件。</returns>
        public static InnerLoadResourceAgentHelperErrorEventArgs Create(LoadResourceStatus status, string errorMessage)
        {
            InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = ReferencePool.Acquire <InnerLoadResourceAgentHelperErrorEventArgs>();

            loadResourceAgentHelperErrorEventArgs.Status       = status;
            loadResourceAgentHelperErrorEventArgs.ErrorMessage = errorMessage;
            return(loadResourceAgentHelperErrorEventArgs);
        }
Esempio n. 6
0
        /// <summary>
        /// 通过加载资源代理辅助器开始异步加载资源。
        /// </summary>
        /// <param name="resource">资源。</param>
        /// <param name="assetName">要加载的资源名称。</param>
        /// <param name="assetType">要加载资源的类型。</param>
        /// <param name="isScene">要加载的资源是否是场景。</param>
        public override void LoadAsset(object resource, string assetName, Type assetType, bool isScene)
        {
            if (m_LoadResourceAgentHelperLoadCompleteEventHandler == null || m_LoadResourceAgentHelperUpdateEventHandler == null || m_LoadResourceAgentHelperErrorEventHandler == null)
            {
                Log.Fatal("Load resource agent helper handler is invalid.");
                return;
            }

            AssetBundle assetBundle = resource as AssetBundle;

            if (assetBundle == null)
            {
                InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = InnerLoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.TypeError, "Can not load asset bundle from loaded resource which is not an asset bundle.");
                m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs);
                ReferencePool.Release(loadResourceAgentHelperErrorEventArgs);
                return;
            }

            if (string.IsNullOrEmpty(assetName))
            {
                InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = InnerLoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.AssetError, "Can not load asset from asset bundle which child name is invalid.");
                m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs);
                ReferencePool.Release(loadResourceAgentHelperErrorEventArgs);
                return;
            }

            m_AssetName = assetName;
            if (isScene)
            {
                int sceneNamePositionStart = assetName.LastIndexOf('/');
                int sceneNamePositionEnd   = assetName.LastIndexOf('.');
                if (sceneNamePositionStart <= 0 || sceneNamePositionEnd <= 0 || sceneNamePositionStart > sceneNamePositionEnd)
                {
                    InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = InnerLoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.AssetError, DBD.Utility.Text.Format("Scene name '{0}' is invalid.", assetName));
                    m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs);
                    ReferencePool.Release(loadResourceAgentHelperErrorEventArgs);
                    return;
                }

                string sceneName = assetName.Substring(sceneNamePositionStart + 1, sceneNamePositionEnd - sceneNamePositionStart - 1);
                m_AsyncOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
            }
            else
            {
                if (assetType != null)
                {
                    m_AssetBundleRequest = assetBundle.LoadAssetAsync(assetName, assetType);
                }
                else
                {
                    m_AssetBundleRequest = assetBundle.LoadAssetAsync(assetName);
                }
            }
        }
Esempio n. 7
0
        private void UpdateUnityWebRequest()
        {
            if (m_UnityWebRequest != null)
            {
                if (m_UnityWebRequest.isDone)
                {
                    if (string.IsNullOrEmpty(m_UnityWebRequest.error))
                    {
                        InnerLoadResourceAgentHelperReadBytesCompleteEventArgs loadResourceAgentHelperReadBytesCompleteEventArgs = InnerLoadResourceAgentHelperReadBytesCompleteEventArgs.Create(m_UnityWebRequest.downloadHandler.data);
                        m_LoadResourceAgentHelperReadBytesCompleteEventHandler(this, loadResourceAgentHelperReadBytesCompleteEventArgs);
                        ReferencePool.Release(loadResourceAgentHelperReadBytesCompleteEventArgs);
                        m_UnityWebRequest.Dispose();
                        m_UnityWebRequest = null;
                        m_BytesFullPath   = null;
                        m_LastProgress    = 0f;
                    }
                    else
                    {
                        bool isError = false;

                        isError = m_UnityWebRequest.isNetworkError || m_UnityWebRequest.isHttpError;

                        InnerLoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = InnerLoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.NotExist, DBD.Utility.Text.Format("Can not load asset bundle '{0}' with error message '{1}'.", m_BytesFullPath, isError ? m_UnityWebRequest.error : null));
                        m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs);
                        ReferencePool.Release(loadResourceAgentHelperErrorEventArgs);
                    }
                }
                else if (m_UnityWebRequest.downloadProgress != m_LastProgress)
                {
                    m_LastProgress = m_UnityWebRequest.downloadProgress;
                    InnerLoadResourceAgentHelperUpdateEventArgs loadResourceAgentHelperUpdateEventArgs = InnerLoadResourceAgentHelperUpdateEventArgs.Create(LoadResourceProgress.ReadResource, m_UnityWebRequest.downloadProgress);
                    m_LoadResourceAgentHelperUpdateEventHandler(this, loadResourceAgentHelperUpdateEventArgs);
                    ReferencePool.Release(loadResourceAgentHelperUpdateEventArgs);
                }
            }
        }