Beispiel #1
0
        /// <summary>
        /// Loads an individual asset
        /// </summary>
        /// <param name="asset"></param>
        public void Load(AssetDefinition assetDef)
        {
            //Console.WriteLine($"Loading asset: {assetDef.Name} ({assetDef.Path})");
            GeneralUtils.LogInfo($"Loading asset: {assetDef.Name} ({assetDef.Path})");

            Asset <dynamic> asset = new Asset <dynamic>(assetDef);

            try {
                if (assetDef.Type == typeof(Texture2D))
                {
                    asset.Assign(content.Load <Texture2D>(assetDef.Path));
                }
                else if (assetDef.Type == typeof(SpriteFont))
                {
                    asset.Assign(content.Load <SpriteFont>(assetDef.Path));
                }
                else if (assetDef.Type == typeof(SoundEffect))
                {
                    asset.Assign(content.Load <SoundEffect>(assetDef.Path));
                }
                else if (assetDef.Type == typeof(Song))
                {
                    asset.Assign(content.Load <Song>(assetDef.Path));
                }
                else if (assetDef.Type == typeof(Model))
                {
                    asset.Assign(content.Load <Model>(assetDef.Path));
                }
                else if (assetDef.Type == typeof(Effect))
                {
                    asset.Assign(content.Load <Effect>(assetDef.Path));
                }
                else if (assetDef.Type == typeof(TextureCube))
                {
                    asset.Assign(content.Load <TextureCube>(assetDef.Path));
                }
                else
                {
                    throw new NotSupportedException();
                }

                assets.Add(assetDef.Name, asset);
            }
            catch (Exception ex) {
                if (ex is ContentLoadException)
                {
                    GeneralUtils.LogError($" => Could not find/load {assetDef.Name} ({assetDef.Path}). {ex}");
                }
                else if (ex is NotSupportedException)
                {
                    GeneralUtils.LogError($" => The type {assetDef.Type.ToString().Split('.').Last()} for {assetDef.Name} ({assetDef.Path}) isn't supported.");
                }
                else if (ex is InvalidCastException)
                {
                    GeneralUtils.LogWarning($" => Skipping {assetDef.Name} ({assetDef.Path}). {ex.Message}");
                }
                else
                {
                    GeneralUtils.LogError($" => An unknown error has occured. {ex}");
                }
            }
        }
Beispiel #2
0
 public Asset(AssetDefinition assetDef)
 {
     AssetDefinition = assetDef;
 }