示例#1
0
 private void OnLoadDictionarySuccess(object sender, GameFramework.Localization.LoadDictionarySuccessEventArgs e)
 {
     if (m_EnableLoadDictionarySuccessEvent)
     {
         m_EventComponent.Fire(this, ReferencePool.Acquire <LoadDictionarySuccessEventArgs>().Fill(e));
     }
 }
 private void OnLoadDictionarySuccess(object sender, GameFramework.Localization.LoadDictionarySuccessEventArgs e)
 {
     if (m_EnableLoadDictionarySuccessEvent)
     {
         m_EventComponent.Fire(this, new LoadDictionarySuccessEventArgs(e));
     }
 }
        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;
            }
        }
示例#4
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);
            }
        }
        /// <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()));
            }
        }
 private void OnLoadDictionarySuccess(object sender, GameFramework.Localization.LoadDictionarySuccessEventArgs e)
 {
     m_EventComponent.Fire(this, LoadDictionarySuccessEventArgs.Create(e));
 }