Ejemplo n.º 1
0
        /// <summary>
        /// 读取数据。
        /// </summary>
        /// <param name="dataAssetName">内容资源名称。</param>
        /// <param name="priority">加载数据资源的优先级。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void ReadData(string dataAssetName, int priority, object userData, AssetCategory assetCategory)
        {
            if (m_ResourceManager == null)
            {
                throw new Exception("You must set resource manager first.");
            }

            if (m_DataProviderHelper == null)
            {
                throw new Exception("You must set data provider helper first.");
            }

            HasAssetResult result = m_ResourceManager.HasAsset(dataAssetName, assetCategory);

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

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

            case HasAssetResult.BinaryOnFileSystem:
                int dataLength = m_ResourceManager.GetBinaryLength(dataAssetName);
                EnsureCachedBytesSize(dataLength);
                if (dataLength != m_ResourceManager.LoadBinaryFromFileSystem(dataAssetName, s_CachedBytes))
                {
                    throw new Exception(Utility.Text.Format("Load binary '{0}' from file system with internal error.", dataAssetName));
                }

                try
                {
                    if (!m_DataProviderHelper.ReadData(m_Owner, dataAssetName, s_CachedBytes, 0, dataLength, userData))
                    {
                        throw new Exception(Utility.Text.Format("Load data failure in data provider helper, data asset name '{0}'.", dataAssetName));
                    }

                    //if (m_ReadDataSuccessEventHandler != null)
                    //{
                    //    ReadDataSuccessEventArgs loadDataSuccessEventArgs = ReadDataSuccessEventArgs.Create(dataAssetName, 0f, userData);
                    //    m_ReadDataSuccessEventHandler(this, loadDataSuccessEventArgs);
                    //    ReferencePool.Release(loadDataSuccessEventArgs);
                    //}
                }
                catch (Exception exception)
                {
                    Log.Error(dataAssetName, exception.ToString());

                    throw;
                }

                break;

            default:
                throw new Exception(Utility.Text.Format("Data asset '{0}' is '{1}'.", dataAssetName, result.ToString()));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 检查场景资源是否存在。
 /// </summary>
 /// <param name="sceneAssetName">要检查场景资源的名称。</param>
 /// <returns>场景资源是否存在。</returns>
 public bool HasScene(string sceneAssetName)
 {
     return(m_ResourceMethods.HasAsset(sceneAssetName, AssetCategory.Scene) != HasAssetResult.NotExist);
 }