Example #1
0
        public IAssetLocatorRegistry AddAssetLocator(IAssetLocator locator)
        {
            if (locator is IComponent component)
            {
                AttachChild(component);
            }

            foreach (var assetType in locator.SupportedTypes)
            {
                if (_locators.ContainsKey(assetType))
                {
                    throw new InvalidOperationException($"A locator is already defined for {assetType}");
                }
                _locators[assetType] = locator;
            }

            return(this);
        }
Example #2
0
        public object LoadAssetCached <T>(AssetType type, T enumId, GameLanguage language = GameLanguage.English)
        {
            int    id    = Convert.ToInt32(enumId);
            var    key   = new AssetKey(type, id, language);
            object asset = _assetCache.Get(key);

            if (asset is Exception) // If it failed to load once then stop trying (at least until an asset:reload / cycle)
            {
                return(null);
            }

            if (asset != null)
            {
                return(asset);
            }

            var name =
                typeof(T) == typeof(int)
                ? $"{type}.{AssetNameResolver.GetName(type, (int)(object)enumId)}"
                : $"{type}.{enumId}";

            try
            {
                IAssetLocator locator = GetLocator(key.Type);
                asset = locator.LoadAsset(key, name, (x, y) => LoadAssetCached(x.Type, x.Id, x.Language));

                if (asset != null && PostProcessors.TryGetValue(asset.GetType(), out var processor))
                {
                    asset = processor.Process(name, asset);
                }
            }
            catch (Exception e)
            {
                Raise(new LogEvent(LogEvent.Level.Error, $"Could not load asset {name}: {e}"));
                asset = e;
            }

            _assetCache.Add(asset, key);
            return(asset is Exception ? null : asset);
        }
Example #3
0
        object LoadAssetInternal(AssetKey key)
        {
            var name = $"{key.Type}.{key.Id}";

            try
            {
                ICoreFactory  factory = Resolve <ICoreFactory>();
                IAssetLocator locator = GetLocator(key.Type);
                var           asset   = locator.LoadAsset(key, name, LoadAssetCached);

                if (asset != null && _postProcessors.TryGetValue(asset.GetType(), out var processor))
                {
                    asset = processor.Process(factory, key, asset, LoadAssetCached);
                }
                return(asset);
            }
            catch (Exception e)
            {
                Raise(new LogEvent(LogEvent.Level.Error, $"Could not load asset {name}: {e}"));
                return(e);
            }
        }
 public IAssetLocatorRegistry AddAssetLocator(IAssetLocator locator) => this;
 public HomeFeatureController(IConfiguration configuration, IAssetLocator assetLocator)
 {
     _configuration = configuration;
     _assetLocator  = assetLocator;
 }