Exemplo n.º 1
0
 /// <summary>
 /// 读写目录读文件
 /// </summary>
 /// <param name="assetName">资源名称</param>
 private void ReadWriteByte(string assetName)
 {
     m_FilePath = TextUtil.Format("{0}/{1}", GameEntry.Resource.ReadWritePath, PathUtil.GetResourceNameWithSuffix(assetName));
     System.Threading.Tasks.Task.Factory.StartNew(ReadWriteByteAsync);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 开始处理加载资源任务
        /// </summary>
        /// <param name="task">要处理的加载资源任务</param>
        /// <returns>开始处理任务的状态</returns>
        public StartTaskStatus StartTask(ResourceLoaderTask task)
        {
            if (task == null)
            {
                throw new Exception("Task is invalid.");
            }

            m_Task           = task;
            m_Task.StartTime = DateTime.Now;

            if (string.IsNullOrEmpty(m_Task.AssetName))
            {
                if (IsResourceLoading(m_Task.AssetBundleName))
                {
                    m_Task.StartTime = default(DateTime);
                    return(StartTaskStatus.HasToWait);
                }

                AssetBundleInfo bundleInfo = m_AssetBundlePool.SpawnAsset(m_Task.AssetBundleName);
                if (bundleInfo != null)
                {
                    OnResourceObjectReady((AssetBundle)bundleInfo.Asset);
                    return(StartTaskStatus.CanResume);
                }

                s_LoadingResourceNames.Add(m_Task.AssetBundleName);

                ResourceInfo resourcinfo = GameEntry.Resource.GetResourceInfo(m_Task.AssetBundleName);
                string       fullpath    = PathUtil.GetCombinePath(resourcinfo.StorageInReadOnly ? GameEntry.Resource.ReadOnlyPath : GameEntry.Resource.ReadWritePath, PathUtil.GetResourceNameWithSuffix(resourcinfo.ResourceName));
                ReadBytes(fullpath);
                //if (resourceInfo.StorageInReadOnly)
                //{
                //    ReadOnlyByte(resourcinfo.ResourceName);
                //}
                //else
                //{
                //    ReadWriteByte(resourcinfo.ResourceName);
                //}
                return(StartTaskStatus.CanResume);
            }

            if (IsAssetLoading(m_Task.AssetName))
            {
                m_Task.StartTime = default(DateTime);
                return(StartTaskStatus.HasToWait);
            }

            if (!m_Task.IsScene)
            {
                AssetInfo assetInfo = m_AssetPool.SpawnAsset(m_Task.AssetName);
                if (assetInfo != null)
                {
                    OnAssetObjectReady((UnityEngine.Object)assetInfo.Asset);
                    return(StartTaskStatus.Done);
                }
            }

            foreach (string dependencyAssetName in m_Task.GetDependencyAssetNames())
            {
                if (!m_AssetBundlePool.CanSpawnAsset(dependencyAssetName))
                {
                    m_Task.StartTime = default(DateTime);
                    return(StartTaskStatus.HasToWait);
                }
            }

            if (IsResourceLoading(m_Task.AssetBundleName))
            {
                m_Task.StartTime = default(DateTime);
                return(StartTaskStatus.HasToWait);
            }

            s_LoadingAssetNames.Add(m_Task.AssetName);

            AssetBundleInfo assetBundleInfo = m_AssetBundlePool.SpawnAsset(m_Task.AssetBundleName);

            if (assetBundleInfo != null)
            {
                OnResourceObjectReady((AssetBundle)assetBundleInfo.Asset);
                return(StartTaskStatus.CanResume);
            }

            s_LoadingResourceNames.Add(m_Task.AssetBundleName);

            ResourceInfo resourceInfo = GameEntry.Resource.GetResourceInfo(m_Task.AssetBundleName);
            string       fullPath     = PathUtil.GetCombinePath(resourceInfo.StorageInReadOnly ? GameEntry.Resource.ReadOnlyPath : GameEntry.Resource.ReadWritePath, PathUtil.GetResourceNameWithSuffix(resourceInfo.ResourceName));

            ReadBytes(fullPath);
            //if (resourceInfo.StorageInReadOnly)
            //{
            //    ReadOnlyByte(resourceInfo.ResourceName);
            //}
            //else
            //{
            //    ReadWriteByte(resourceInfo.ResourceName);
            //}
            return(StartTaskStatus.CanResume);
        }