Exemplo n.º 1
0
 public static AssetReference <T> LoadOrRegisterAsset <T>(string assetName) where T : class, IAsset, new()
 {
     if (assetNameToHolder.TryGetValue(assetName, out int idx))
     {
         if (assets[idx].assetType != typeof(T))
         {
             throw new AssetTypeException("The type of reference does not match type of asset");
         }
         return(new AssetReference <T>(idx));
     }
     else
     {
         AssetPackage package = GetAssetPackageForAsset(assetName);
         var          header  = package.GetAssetHeader(assetName);
         if (header.assetType != typeof(T))
         {
             throw new AssetTypeException("The type of reference does not match type of asset");
         }
         AssetReference <T> newRef = new AssetReference <T>(assets.Count + 1);
         assets.Add(new AssetHolder()
         {
             asset     = new T(),
             assetType = typeof(T),
             assetName = assetName,
             state     = AssetState.Unloaded
         });
         return(newRef);
     }
 }
Exemplo n.º 2
0
        public static void LoadAssetPackage(string filename)
        {
            FileInfo file = new FileInfo(filename);

            if (!file.Exists)
            {
                throw new FileNotFoundException("Asset package was not found at location " + file.FullName);
            }
            AssetPackage package = new AssetPackage(file);

            foreach (string assetName in package.GetAssetNames())
            {
                assetNameToPackage[assetName] = package;
            }
            assetPackages.Add(package);
        }