internal AssetAccessor LoadAsset(string assetPath, bool isScene, LoadAssetCallbackSet callbackSet, object context) { if (string.IsNullOrEmpty(assetPath)) { throw new ArgumentException("Shouldn't be null or empty.", "assetPath"); } if (!ReadWriteIndex.AssetInfos.TryGetValue(assetPath, out var assetInfo)) { throw new ArgumentException(Utility.Text.Format("Asset info for path '{0}' not found.", assetPath)); } int resourceGroup = ReadWriteIndex.ResourceBasicInfos[assetInfo.ResourcePath].GroupId; if (m_Owner.ResourceUpdater.GetResourceGroupStatus(resourceGroup) != ResourceGroupStatus.UpToDate) { throw new InvalidOperationException(Utility.Text.Format( "Asset '{0}' cannot be used until resource group '{1}' is done updating.", assetPath, resourceGroup)); } if (!m_AssetCaches.TryGetValue(assetPath, out var assetCache)) { assetCache = AcquireAssetCache(assetPath, assetInfo, isScene); } var ret = m_AssetAccessorPool.Acquire(); ret.Init(assetCache, callbackSet, context); return(ret); }
private AssetLoadingTask RunAssetLoadingTask(string assetPath, object resourceObject) { var task = m_AssetLoadingTaskPool.Acquire(); task.OnCreate(AssetLoadingTaskImplFactory); task.ResourceObject = resourceObject; task.AssetPath = assetPath; task.OnStart(); m_RunningAssetLoadingTasks.Add(task); return(task); }
private ResourceCache AcquireResourceCache(string resourcePath, bool fromReadWritePath) { ResourceCache resourceCache = m_ResourceCachePool.Acquire(); resourceCache.Path = resourcePath; resourceCache.ShouldLoadFromReadWritePath = fromReadWritePath; resourceCache.Owner = this; m_ResourceCaches[resourcePath] = resourceCache; resourceCache.Init(); return(resourceCache); }
private ResourceLoadingTask RunResourceLoadingTask(string resourcePath, string resourceParentDir) { var task = m_ResourceLoadingTaskPool.Acquire(); task.OnCreate(ResourceLoadingTaskImplFactory); task.ResourcePath = resourcePath; task.ResourceParentDir = resourceParentDir; task.OnStart(); m_RunningResourceLoadingTasks.Add(task); return(task); }
private AssetCache AcquireAssetCache(string assetPath, AssetInfo assetInfo, bool isScene) { AssetCache assetCache = m_AssetCachePool.Acquire(); assetCache.Path = assetPath; assetCache.DependencyAssetPaths = assetInfo.DependencyAssetPaths; assetCache.ResourcePath = assetInfo.ResourcePath; assetCache.Owner = this; assetCache.IsScene = isScene; m_AssetCaches[assetCache.Path] = assetCache; assetCache.Init(); return(assetCache); }
public void TestAcquireAndRelease() { List <PoolableObject> objects = new List <PoolableObject>(m_RefPool.Capacity + 1); // Acquire Capacity + 1 objects. for (int i = 0; i < m_RefPool.Capacity + 1; i++) { objects.Add(m_RefPool.Acquire()); Assert.AreEqual(i + 1, PoolableObject.CurrentIndex); Assert.AreEqual(i + 1, m_RefPool.Statistics.AcquireCount); Assert.AreEqual(i + 1, m_RefPool.Statistics.CreateCount); } // Release all of them. for (int i = m_RefPool.Capacity; i >= 0; i--) { var obj = objects[i]; m_RefPool.Release(obj); } Assert.AreEqual(m_RefPool.Capacity + 1, m_RefPool.Statistics.ReleaseCount); Assert.AreEqual(1, m_RefPool.Statistics.DropCount); Assert.AreEqual(m_RefPool.Count, m_RefPool.Capacity); objects.Clear(); // Acquire again. There should be only one new object. for (int i = 0; i < m_RefPool.Capacity + 1; i++) { m_RefPool.Acquire(); if (i < m_RefPool.Capacity) { Assert.AreEqual(m_RefPool.Capacity + 1, PoolableObject.CurrentIndex); Assert.AreEqual(m_RefPool.Capacity + 1, m_RefPool.Statistics.CreateCount); } else { Assert.AreEqual(m_RefPool.Capacity + 2, PoolableObject.CurrentIndex); Assert.AreEqual(m_RefPool.Capacity + 2, m_RefPool.Statistics.CreateCount); } } }
/// <summary> /// Acquire a download task to use. /// </summary> /// <returns>The download task.</returns> public IDownloadTask Acquire() { return(m_DownloadTaskRawPool.Acquire()); }