Beispiel #1
0
                private void OnDependencyAssetReady()
                {
                    if (IsResourceLoading(m_Task.ResourceInfo.ResourceName.Name))
                    {
                        m_WaitingType = WaitingType.WaitForResource;
                        return;
                    }

                    ResourceObject resourceObject = m_ResourcePool.Spawn(m_Task.ResourceInfo.ResourceName.Name);

                    if (resourceObject != null)
                    {
                        OnResourceObjectReady(resourceObject);
                        return;
                    }

                    m_LoadingResource = true;
                    s_LoadingResourceNames.Add(m_Task.ResourceInfo.ResourceName.Name);

                    string fullPath = Utility.Path.GetCombinePath(m_Task.ResourceInfo.StorageInReadOnly ? m_ReadOnlyPath : m_ReadWritePath, Utility.Path.GetResourceNameWithSuffix(m_Task.ResourceInfo.ResourceName.FullName));

                    if (m_Task.ResourceInfo.LoadType == LoadType.LoadFromFile)
                    {
                        m_Helper.ReadFile(fullPath);
                    }
                    else
                    {
                        m_Helper.ReadBytes(fullPath, (int)m_Task.ResourceInfo.LoadType);
                    }
                }
Beispiel #2
0
        void OnDependencyAssetReady()
        {
            ResourceObject resourceObject = m_ResourcePool.Spawn(m_Task.ResourceInfo.ResourceName.Name);
            if (resourceObject != null)
            {
                OnResourceObjectReady(resourceObject);
                return;
            }

            m_LoadingResource = true;
            s_LoadingResourceNames.Add(m_Task.ResourceInfo);

            string fullPath = Utility.Path.GetCombinePath(m_Task.ResourceInfo);
            if (m_Task.ResourceInfo.LoadType == LoadType.LoadFromFile)
            {
                m_Helper.ReadFile(fullPath);
            }
            else
            {
                m_Helper.ReadBytes(fullPath);
            }

        }
Beispiel #3
0
                /// <summary>
                /// 开始处理加载资源任务。
                /// </summary>
                /// <param name="task">要处理的加载资源任务。</param>
                /// <returns>开始处理任务的状态。</returns>
                public StartTaskStatus Start(LoadResourceTaskBase task)
                {
                    if (task == null)
                    {
                        throw new GameFrameworkException("Task is invalid.");
                    }

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

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

                    if (!m_Task.IsScene)
                    {
                        AssetObject assetObject = m_ResourceLoader.m_AssetPool.Spawn(m_Task.AssetName);
                        if (assetObject != null)
                        {
                            OnAssetObjectReady(assetObject);
                            return(StartTaskStatus.Done);
                        }
                    }

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

                    string resourceName = m_Task.ResourceInfo.ResourceName.Name;

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

                    s_LoadingAssetNames.Add(m_Task.AssetName);

                    ResourceObject resourceObject = m_ResourceLoader.m_ResourcePool.Spawn(resourceName);

                    if (resourceObject != null)
                    {
                        OnResourceObjectReady(resourceObject);
                        return(StartTaskStatus.CanResume);
                    }

                    s_LoadingResourceNames.Add(resourceName);

                    string fullPath = null;

                    if (!s_CachedResourceNames.TryGetValue(resourceName, out fullPath))
                    {
                        fullPath = Utility.Path.GetRegularPath(Path.Combine(m_Task.ResourceInfo.StorageInReadOnly ? m_ReadOnlyPath : m_ReadWritePath, Utility.Path.GetResourceNameWithSuffix(m_Task.ResourceInfo.ResourceName.FullName)));
                        s_CachedResourceNames.Add(resourceName, fullPath);
                    }

                    if (m_Task.ResourceInfo.LoadType == LoadType.LoadFromFile)
                    {
                        m_Helper.ReadFile(fullPath);
                    }
                    else
                    {
                        m_Helper.ReadBytes(fullPath, (int)m_Task.ResourceInfo.LoadType);
                    }

                    return(StartTaskStatus.CanResume);
                }
                /// <summary>
                /// 开始处理加载资源任务。
                /// </summary>
                /// <param name="task">要处理的加载资源任务。</param>
                /// <returns>开始处理任务的状态。</returns>
                public StartTaskStatus Start(LoadResourceTaskBase task)
                {
                    if (task == null)
                    {
                        throw new GameFrameworkException("Task is invalid.");
                    }

                    m_Task           = task;
                    m_Task.StartTime = DateTime.UtcNow;
                    ResourceInfo resourceInfo = m_Task.ResourceInfo;

                    if (!resourceInfo.Ready)
                    {
                        m_Task.StartTime = default(DateTime);
                        return(StartTaskStatus.HasToWait);
                    }

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

                    if (!m_Task.IsScene)
                    {
                        AssetObject assetObject = m_ResourceLoader.m_AssetPool.Spawn(m_Task.AssetName);
                        if (assetObject != null)
                        {
                            OnAssetObjectReady(assetObject);
                            return(StartTaskStatus.Done);
                        }
                    }

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

                    string resourceName = resourceInfo.ResourceName.Name;

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

                    s_LoadingAssetNames.Add(m_Task.AssetName);

                    ResourceObject resourceObject = m_ResourceLoader.m_ResourcePool.Spawn(resourceName);

                    if (resourceObject != null)
                    {
                        OnResourceObjectReady(resourceObject);
                        return(StartTaskStatus.CanResume);
                    }

                    s_LoadingResourceNames.Add(resourceName);

                    string fullPath = null;

                    if (!s_CachedResourceNames.TryGetValue(resourceName, out fullPath))
                    {
                        fullPath = Utility.Path.GetRegularPath(Path.Combine(resourceInfo.StorageInReadOnly ? m_ReadOnlyPath : m_ReadWritePath, resourceInfo.UseFileSystem ? resourceInfo.FileSystemName : resourceInfo.ResourceName.FullName));
                        s_CachedResourceNames.Add(resourceName, fullPath);
                    }

                    if (resourceInfo.LoadType == LoadType.LoadFromFile)
                    {
                        if (resourceInfo.UseFileSystem)
                        {
                            IFileSystem fileSystem = m_ResourceLoader.m_ResourceManager.GetFileSystem(resourceInfo.FileSystemName, resourceInfo.StorageInReadOnly);
                            m_Helper.ReadFile(fileSystem, resourceInfo.ResourceName.FullName);
                        }
                        else
                        {
                            m_Helper.ReadFile(fullPath);
                        }
                    }
                    else if (resourceInfo.LoadType == LoadType.LoadFromMemory || resourceInfo.LoadType == LoadType.LoadFromMemoryAndQuickDecrypt || resourceInfo.LoadType == LoadType.LoadFromMemoryAndDecrypt)
                    {
                        if (resourceInfo.UseFileSystem)
                        {
                            IFileSystem fileSystem = m_ResourceLoader.m_ResourceManager.GetFileSystem(resourceInfo.FileSystemName, resourceInfo.StorageInReadOnly);
                            m_Helper.ReadBytes(fileSystem, resourceInfo.ResourceName.FullName);
                        }
                        else
                        {
                            m_Helper.ReadBytes(fullPath);
                        }
                    }
                    else
                    {
                        throw new GameFrameworkException(Utility.Text.Format("Resource load type '{0}' is not supported.", resourceInfo.LoadType.ToString()));
                    }

                    return(StartTaskStatus.CanResume);
                }