private static void UnloadAsset(string path) { var extension = AssetPath.GetExtension(path); var type = LookupType(extension); if (type != null) { if (type.Compound) { var loadedCompound = LookupCompound(path); if (loadedCompound != null) { // Unload an asset s_loadedCompoundAssets.Remove(path); loadedCompound.Asset.Dispose(); } } else { var loadedBasic = LookupBasic(path); if (loadedBasic != null) { // Unload an asset s_loadedBasicAssets.Remove(path); loadedBasic.Asset.Dispose(); } } } }
public static IReadOnlyList <IAssetSource> GetSources(string path) { var extension = AssetPath.GetExtension(path); var type = LookupType(extension); if (type != null) { if (type.Compound) { var loadedCompoundAsset = LookupCompound(path); if (loadedCompoundAsset != null) { return(loadedCompoundAsset.Sources.ToReadOnly()); } } else { var loadedAsset = LookupBasic(path); if (loadedAsset != null) { var list = new List <IAssetSource>(); list.Add(loadedAsset.Source); return(list.ToReadOnly()); } } } return(s_emptyAssetSourceList); }
public IBasicAsset LoadBasic(string path) { try { //App.Log( "Loading {0}", path ); var assetType = Assets.GetType(AssetPath.GetExtension(path)); var constructor = assetType.GetConstructor(new Type[] { typeof(string), typeof(IFileStore) }); try { return((IBasicAsset)constructor.Invoke(new object[] { path, m_fileStore })); } catch (TargetInvocationException e) { throw e.InnerException; } } catch (Exception e) { throw new AssetLoadException(path, e); } }
private IEnumerable <string> EnumeratePaths(string root = "") { if (m_fileStore.FileExists(root)) { if (Assets.GetType(AssetPath.GetExtension(root)) != null) { yield return(root); } } else if (m_fileStore.DirectoryExists(root)) { foreach (var dirName in m_fileStore.ListDirectories(root)) { var dirPath = AssetPath.Combine(root, dirName); foreach (var filePath in EnumeratePaths(dirPath)) { yield return(filePath); } } foreach (var fileName in m_fileStore.ListFiles(root)) { var filePath = AssetPath.Combine(root, fileName); if (Assets.GetType(AssetPath.GetExtension(filePath)) != null) { yield return(filePath); } } } }
public static IEnumerable <string> ListAll <TAsset>(this IAssetSource source, string dir) where TAsset : IBasicAsset { var extension = Assets.GetExtension <TAsset>(); if (extension != null) { foreach (var path in source.AllLoadablePaths) { if (AssetPath.GetDirectoryName(path) == dir && AssetPath.GetExtension(path) == extension) { yield return(path); } } } }
private static ICompoundAsset ConstructCompoundAsset(string path) { var assetType = Assets.GetType(AssetPath.GetExtension(path)); var constructor = assetType.GetConstructor(new Type[] { typeof(string) }); try { return((ICompoundAsset)constructor.Invoke(new object[] { path })); } catch (TargetInvocationException e) { throw e.InnerException; } }
private static void LoadAsset(string path, bool reloadIfSourceUnchanged) { var extension = AssetPath.GetExtension(path); var type = LookupType(extension); if (type != null) { if (type.Compound) { var sources = new List <IAssetSource>(); for (int i = 0; i < s_assetSources.Count; ++i) { var source = s_assetSources[i]; if (source.CanLoad(path)) { sources.Add(source); } } if (sources.Count > 0) { LoadCompoundAsset(path, sources, reloadIfSourceUnchanged); } } else { for (int i = s_assetSources.Count - 1; i >= 0; --i) { var source = s_assetSources[i]; if (source.CanLoad(path)) { LoadBasicAsset(path, source, reloadIfSourceUnchanged); return; } } } } }
public bool CanLoad(string path) { return (Assets.GetType(AssetPath.GetExtension(path)) != null && m_fileStore.FileExists(path)); }