//加载资源成功的回调
 private void OnLoadDictionaryFailure(object sender, GameFramework.Localization.LoadDictionaryFailureEventArgs e)
 {
     if (m_EnableLoadDictionaryFailureEvent)
     {
         m_EventComponent.Fire(this, ReferencePool.Acquire <LoadDictionaryFailureEventArgs>().Fill(e));
     }
 }
Esempio n. 2
0
        private void LoadBinarySuccessCallback(string dictionaryAssetName, byte[] dictionaryBytes, float duration, object userData)
        {
            try
            {
                if (!m_LocalizationHelper.LoadDictionary(dictionaryAssetName, dictionaryBytes, userData))
                {
                    throw new GameFrameworkException(Utility.Text.Format("Load dictionary failure in helper, asset name '{0}'.", dictionaryAssetName));
                }

                if (m_LoadDictionarySuccessEventHandler != null)
                {
                    LoadDictionarySuccessEventArgs loadDictionarySuccessEventArgs = LoadDictionarySuccessEventArgs.Create(dictionaryAssetName, duration, userData);
                    m_LoadDictionarySuccessEventHandler(this, loadDictionarySuccessEventArgs);
                    ReferencePool.Release(loadDictionarySuccessEventArgs);
                }
            }
            catch (Exception exception)
            {
                if (m_LoadDictionaryFailureEventHandler != null)
                {
                    LoadDictionaryFailureEventArgs loadDictionaryFailureEventArgs = LoadDictionaryFailureEventArgs.Create(dictionaryAssetName, exception.ToString(), userData);
                    m_LoadDictionaryFailureEventHandler(this, loadDictionaryFailureEventArgs);
                    ReferencePool.Release(loadDictionaryFailureEventArgs);
                    return;
                }

                throw;
            }
        }
Esempio n. 3
0
 private void OnLoadDictionaryFailure(object sender, GameFramework.Localization.LoadDictionaryFailureEventArgs e)
 {
     Log.Warning("Load dictionary failure, asset name '{0}', error message '{1}'.", e.DictionaryAssetName, e.ErrorMessage);
     if (m_EnableLoadDictionaryFailureEvent)
     {
         m_EventComponent.Fire(this, ReferencePool.Acquire <LoadDictionaryFailureEventArgs>().Fill(e));
     }
 }
Esempio n. 4
0
        private void LoadAssetOrBinaryFailureCallback(string dictionaryAssetName, LoadResourceStatus status, string errorMessage, object userData)
        {
            string appendErrorMessage = Utility.Text.Format("Load dictionary failure, asset name '{0}', status '{1}', error message '{2}'.", dictionaryAssetName, status.ToString(), errorMessage);

            if (m_LoadDictionaryFailureEventHandler != null)
            {
                LoadDictionaryFailureEventArgs loadDictionaryFailureEventArgs = LoadDictionaryFailureEventArgs.Create(dictionaryAssetName, appendErrorMessage, userData);
                m_LoadDictionaryFailureEventHandler(this, loadDictionaryFailureEventArgs);
                ReferencePool.Release(loadDictionaryFailureEventArgs);
                return;
            }

            throw new GameFrameworkException(appendErrorMessage);
        }
Esempio n. 5
0
        private void LoadAssetSuccessCallback(string dictionaryAssetName, object dictionaryAsset, float duration, object userData)
        {
            LoadDictionaryInfo loadDictionaryInfo = (LoadDictionaryInfo)userData;

            if (loadDictionaryInfo == null)
            {
                throw new GameFrameworkException("Load dictionary info is invalid.");
            }

            try
            {
                if (!m_LocalizationHelper.LoadDictionary(dictionaryAsset, loadDictionaryInfo.LoadType, loadDictionaryInfo.UserData))
                {
                    throw new GameFrameworkException(Utility.Text.Format("Load dictionary failure in helper, asset name '{0}'.", dictionaryAssetName));
                }

                if (m_LoadDictionarySuccessEventHandler != null)
                {
                    LoadDictionarySuccessEventArgs loadDictionarySuccessEventArgs = LoadDictionarySuccessEventArgs.Create(dictionaryAssetName, loadDictionaryInfo.LoadType, duration, loadDictionaryInfo.UserData);
                    m_LoadDictionarySuccessEventHandler(this, loadDictionarySuccessEventArgs);
                    ReferencePool.Release(loadDictionarySuccessEventArgs);
                }
            }
            catch (Exception exception)
            {
                if (m_LoadDictionaryFailureEventHandler != null)
                {
                    LoadDictionaryFailureEventArgs loadDictionaryFailureEventArgs = LoadDictionaryFailureEventArgs.Create(dictionaryAssetName, loadDictionaryInfo.LoadType, exception.ToString(), loadDictionaryInfo.UserData);
                    m_LoadDictionaryFailureEventHandler(this, loadDictionaryFailureEventArgs);
                    ReferencePool.Release(loadDictionaryFailureEventArgs);
                    return;
                }

                throw;
            }
            finally
            {
                ReferencePool.Release(loadDictionaryInfo);
                m_LocalizationHelper.ReleaseDictionaryAsset(dictionaryAsset);
            }
        }
 private void OnLoadDictionaryFailure(object sender, GameFramework.Localization.LoadDictionaryFailureEventArgs e)
 {
     Log.Warning("Load dictionary failure, asset name '{0}', error message '{1}'.", e.DictionaryAssetName, e.ErrorMessage);
     m_EventComponent.Fire(this, new LoadDictionaryFailureEventArgs(e));
 }
Esempio n. 7
0
        /// <summary>
        /// 加载字典。
        /// </summary>
        /// <param name="dictionaryAssetName">字典资源名称。</param>
        /// <param name="priority">加载字典资源的优先级。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void LoadDictionary(string dictionaryAssetName, int priority, object userData)
        {
            if (m_ResourceManager == null)
            {
                throw new GameFrameworkException("You must set resource manager first.");
            }

            if (m_LocalizationHelper == null)
            {
                throw new GameFrameworkException("You must set localization helper first.");
            }

            HasAssetResult result = m_ResourceManager.HasAsset(dictionaryAssetName);

            switch (result)
            {
            case HasAssetResult.AssetOnDisk:
            case HasAssetResult.AssetOnFileSystem:
                m_ResourceManager.LoadAsset(dictionaryAssetName, priority, m_LoadAssetCallbacks, userData);
                break;

            case HasAssetResult.BinaryOnDisk:
                m_ResourceManager.LoadBinary(dictionaryAssetName, m_LoadBinaryCallbacks, userData);
                break;

            case HasAssetResult.BinaryOnFileSystem:
                int    dictionaryLength = m_ResourceManager.GetBinaryLength(dictionaryAssetName);
                byte[] dictionaryBytes  = GlobalBytes.Get(dictionaryLength);
                if (dictionaryLength != m_ResourceManager.LoadBinaryFromFileSystem(dictionaryAssetName, dictionaryBytes))
                {
                    throw new GameFrameworkException(Utility.Text.Format("Load binary '{0}' from file system internal error.", dictionaryAssetName));
                }

                try
                {
                    if (!m_LocalizationHelper.LoadDictionary(dictionaryAssetName, dictionaryBytes, 0, dictionaryLength, userData))
                    {
                        throw new GameFrameworkException(Utility.Text.Format("Load dictionary failure in helper, asset name '{0}'.", dictionaryAssetName));
                    }

                    if (m_LoadDictionarySuccessEventHandler != null)
                    {
                        LoadDictionarySuccessEventArgs loadDictionarySuccessEventArgs = LoadDictionarySuccessEventArgs.Create(dictionaryAssetName, 0f, userData);
                        m_LoadDictionarySuccessEventHandler(this, loadDictionarySuccessEventArgs);
                        ReferencePool.Release(loadDictionarySuccessEventArgs);
                    }
                }
                catch (Exception exception)
                {
                    if (m_LoadDictionaryFailureEventHandler != null)
                    {
                        LoadDictionaryFailureEventArgs loadDictionaryFailureEventArgs = LoadDictionaryFailureEventArgs.Create(dictionaryAssetName, exception.ToString(), userData);
                        m_LoadDictionaryFailureEventHandler(this, loadDictionaryFailureEventArgs);
                        ReferencePool.Release(loadDictionaryFailureEventArgs);
                        return;
                    }

                    throw;
                }
                break;

            default:
                throw new GameFrameworkException(Utility.Text.Format("Dictionary asset '{0}' is '{1}'.", dictionaryAssetName, result.ToString()));
            }
        }