private static AssetSerializerPair[] GetSerializableAssets() { List <AssetSerializerPair> assetSerializerPairs = new List <AssetSerializerPair>(); GameAsset[] assets = Assets.Values.ToArray(); foreach (GameAsset asset in assets) { GameAssetSerializer serializer = GetSuitableSerializer(asset.AssetType); if (serializer == null) { continue; } assetSerializerPairs.Add(new AssetSerializerPair(asset, serializer)); } return(assetSerializerPairs.ToArray()); }
public static void LoadAssetsFromFile(string path) { using (FileStream stream = new FileStream(path, FileMode.Open)) { BinaryReader reader = new BinaryReader(stream); int assetsCount = reader.ReadInt32(); for (int i = 0; i < assetsCount; i++) { string id = reader.ReadString(); GameAssetType assetType = (GameAssetType)reader.ReadInt32(); GameAssetSerializer serializer = GetSuitableSerializer(assetType); if (serializer == null) { throw new Exception("No suitable serializer found!"); } GameAsset.SetNextID(id); serializer.ReadFromStream(reader); } } }
public AssetSerializerPair(GameAsset asset, GameAssetSerializer serializer) { Asset = asset; Serializer = serializer; }