예제 #1
0
 public CacheEntry(Guid id, Guid containerId, AssetSource source, Object asset, ColliderGeometry collider = null)
 {
     Id               = id;
     ContainerId      = containerId;
     Source           = source;
     Asset            = asset;
     ColliderGeometry = collider;
 }
예제 #2
0
 public AssetMetadata(Guid id, Guid containerId, Object asset,
                      ColliderGeometry collider = null, AssetSource source = null)
 {
     Id               = id;
     ContainerId      = containerId;
     Source           = source;
     Asset            = asset;
     ColliderGeometry = collider;
 }
        /// <summary>
        /// Track a new asset reference. Will be called during asset creation, after the asset content is downloaded
        /// or retrieved from cache.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="containerId"></param>
        /// <param name="asset"></param>
        /// <param name="colliderGeo"></param>
        /// <param name="source"></param>
        public void Set(Guid id, Guid containerId, Object asset,
                        ColliderGeometry colliderGeo = null, AssetSource source = null)
        {
            if (!Assets.ContainsKey(id))
            {
                Assets[id] = new AssetMetadata(id, containerId, asset, colliderGeo, source);
            }

            if (Callbacks.TryGetValue(id, out List <AssetCallback> callbacks))
            {
                Callbacks.Remove(id);
                foreach (var cb in callbacks)
                {
                    try
                    {
                        cb?.Invoke(Assets[id]);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
            }
        }
예제 #4
0
        /// <inheritdoc cref="CacheAsset"/>
        public void CacheAsset(Object asset, Guid id, Guid containerId, AssetSource source = null, ColliderGeometry colliderGeo = null)
        {
            if (!cache.Any(c => c.Id == id))
            {
                cache.Add(new CacheEntry(id, containerId, source, asset, colliderGeo));
            }

            if (cacheCallbacks.TryGetValue(id, out List <CacheCallback> callbacks))
            {
                cacheCallbacks.Remove(id);
                foreach (var cb in callbacks)
                {
                    try
                    {
                        cb?.Invoke(asset);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
            }
        }