protected void BuildSingleFileAssets(string dir, AssetTypeEnum assetType, AssetFileEnum fileType) { List<string> extensions = AssetFile.AllExtensionsForEnum(fileType); DirectoryInfo info = new DirectoryInfo(MakeRepositoryFilePath(dir)); FileInfo[] files = info.GetFiles(); foreach (FileInfo fileInfo in files) { string extension = fileInfo.Extension.ToLower(); if (extensions.IndexOf(extension) < 0) continue; string baseName = Path.GetFileNameWithoutExtension(fileInfo.Name) + "_" + AssetTypeDesc.AssetTypeEnumFileName(assetType); string defPath = MakeRepositoryFilePath("AssetDefinitions" + Path.DirectorySeparatorChar + baseName + ".asset"); if (new FileInfo(defPath).Exists) { Warn("Skipping generated of asset definition '{0}', because it already exists", defPath); continue; } AssetFile file = new AssetFile(MakeFullFilePath(dir, fileInfo.Name), fileType); AssetDefinition def = new AssetDefinition(baseName, assetType, file); def.SetDescriptionFromName(); def.WriteXmlFile(defPath); } }
public static AssetDefinition ReadXmlFile(string path, List<string> log) { AssetDefinition assetDefinition = new AssetDefinition(); if (assetDefinition.ReadXmlFileInternal(path, log)) return assetDefinition; else return null; }
protected void BuildAllParticleScriptAssets() { AssetTypeEnum assetType = AssetTypeEnum.ParticleScript; AssetFileEnum fileType = AssetFileEnum.ParticleScript; List<string> extensions = AssetFile.AllExtensionsForEnum(fileType); string particleDir = AssetFile.DirectoryForFileEnum(assetType, true, fileType); DirectoryInfo info = new DirectoryInfo(MakeRepositoryFilePath(particleDir)); FileInfo[] files = info.GetFiles(); foreach (FileInfo fileInfo in files) { string extension = fileInfo.Extension.ToLower(); if (extensions.IndexOf(extension) < 0) continue; string baseName = Path.GetFileNameWithoutExtension(fileInfo.Name) + "_" + AssetTypeDesc.AssetTypeEnumFileName(assetType); string defPath = MakeRepositoryFilePath("AssetDefinitions" + Path.DirectorySeparatorChar + baseName + ".asset"); if (new FileInfo(defPath).Exists) { Warn("Skipping generated of asset definition '{0}', because it already exists", defPath); continue; } AssetFile assetFile = new AssetFile(MakeFullFilePath(particleDir, fileInfo.Name), fileType); AssetDefinition def = new AssetDefinition(baseName, assetType, assetFile); // Add the textures Dictionary<string, List<string>> uses = ScriptParser.ParseParticleScript(fileInfo.FullName); List<string> references = new List<string>(); AddParsedReferences(def, fileInfo.FullName, references, uses, "material", assetType, AssetFileEnum.Material); def.SetDescriptionFromName(); def.WriteXmlFile(defPath); } }
protected void AddReferencedShaders(AssetDefinition def, string referee, List<string> shaderFiles, Dictionary<string, List<string>> introducers, string introducer) { List<string> shaderNames; string dir = AssetFile.DirectoryForFileEnum(AssetTypeEnum.Material, false, AssetFileEnum.Shader); if (introducers.TryGetValue(introducer, out shaderNames)) { foreach (string shaderName in shaderNames) { List<string> shaderPathnames; if (shaderNameToShaderFileNames.TryGetValue(shaderName, out shaderPathnames)) { foreach (string shaderFile in shaderPathnames) { string file = MakeFullFilePath(dir, Path.GetFileName(shaderFile)); ScriptParser.AddIfNotPresent(shaderFiles, file); } } else Warn("Shader '{0}', referenced by material script '{1}', does not exist in any shader file", shaderName, referee); } } }
protected void AddParsedReferences(AssetDefinition def, string referee, List<string> references, Dictionary<string, List<string>> introducers, string introducer, AssetTypeEnum assetType, AssetFileEnum fileType) { List<string> usedNames; if (introducers.TryGetValue(introducer, out usedNames)) { string dir = AssetFile.DirectoryForFileEnum(assetType, false, fileType); foreach (string referredTo in usedNames) { string referredToFile = MakeFullFilePath(dir, referredTo); if (references.IndexOf(referredToFile) >= 0) continue; if (!new FileInfo(MakeRepositoryFilePath(referredToFile)).Exists) { Warn("Skipping file '{0}', referenced by '{1}', because the file does not exist", referredToFile, referee); continue; } references.Add(referredToFile); AssetFile assetFile = new AssetFile(referredToFile, fileType); def.Files.Add(assetFile); } } }
public void BuildPlantTypeAssets() { AssetTypeEnum assetType = AssetTypeEnum.PlantType; XmlDocument doc = new XmlDocument(); doc.Load(MakeRepositoryFilePath("Textures" + Path.DirectorySeparatorChar + "DetailVeg.imageset")); XmlElement root = doc.DocumentElement; XmlElement child = (XmlElement)root.FirstChild; while (child != null) { switch (child.LocalName) { case "ImageRect": string name = (string)child.Attributes[0].InnerText; AssetFile file = new AssetFile("Textures" + Path.DirectorySeparatorChar + "DetailVeg.imageset", AssetFileEnum.ImageSet); AssetDefinition def = new AssetDefinition(name, AssetTypeEnum.PlantType, file); def.Files.Add(new AssetFile("AssetDefinitions" + Path.DirectorySeparatorChar + "DetailVeg_Material.asset", AssetFileEnum.AssetDef)); string baseName = name + "_" + AssetTypeDesc.AssetTypeEnumFileName(assetType); def.SetDescriptionFromName(); string defPath = "AssetDefinitions" + Path.DirectorySeparatorChar + baseName + ".asset"; def.WriteXmlFile(MakeRepositoryFilePath(defPath)); break; default: break; } child = (XmlElement)child.NextSibling; } }
public void BuildAllMeshAssets() { AssetTypeEnum assetType = AssetTypeEnum.Mesh; AssetFileEnum fileType = AssetFileEnum.Mesh; string meshDir = AssetFile.DirectoryForFileEnum(assetType, true, fileType); List<string> extensions = AssetFile.AllExtensionsForEnum(fileType); DirectoryInfo info = new DirectoryInfo(MakeRepositoryFilePath(meshDir)); FileInfo[] files = info.GetFiles(); foreach (FileInfo fileInfo in files) { string extension = fileInfo.Extension.ToLower(); if (extensions.IndexOf(extension) < 0) continue; string fileName = Path.GetFileNameWithoutExtension(fileInfo.Name); string baseName = fileName + "_" + AssetTypeDesc.AssetTypeEnumFileName(assetType); string meshFile = MakeFullFilePath(meshDir, fileInfo.Name); AssetFile file = new AssetFile(meshFile, fileType); AssetDefinition def = new AssetDefinition(baseName, assetType, file); // Find the corresponding material and physics files string materialFile = MakeFullFilePath(AssetFile.DirectoryForFileEnum(assetType, false, AssetFileEnum.Material), fileName + ".material"); if (File.Exists(MakeRepositoryFilePath(materialFile))) { string assetDir = AssetFile.DirectoryForFileEnum(AssetTypeEnum.Mesh, false, AssetFileEnum.AssetDef); string materialAsset = MakeFullFilePath(assetDir, fileName + "_Material.asset"); file = new AssetFile(materialAsset, AssetFileEnum.AssetDef); def.Files.Add(file); } else Warn("For mesh '{0}', didn't find material file '{1}'", meshFile, materialFile); string physicsFile = MakeFullFilePath(AssetFile.DirectoryForFileEnum(assetType, false, AssetFileEnum.Physics), fileName + ".physics"); if (File.Exists(MakeRepositoryFilePath(physicsFile))) { file = new AssetFile(physicsFile, AssetFileEnum.Physics); def.Files.Add(file); } else Warn("For mesh '{0}', didn't find physics file '{1}'", meshFile, physicsFile); // It's a long shot, and misleading in the case of the // rocketboxers, but see if there is a matching skeleton string skeletonFile = MakeFullFilePath(AssetFile.DirectoryForFileEnum(assetType, false, AssetFileEnum.Skeleton), fileName + ".skeleton"); if (File.Exists(MakeRepositoryFilePath(skeletonFile))) { file = new AssetFile(skeletonFile, AssetFileEnum.Skeleton); def.Files.Add(file); } else Warn("For mesh '{0}', didn't find skeleton file '{1}'", meshFile, skeletonFile); def.SetDescriptionFromName(); string defPath = MakeRepositoryFilePath("AssetDefinitions" + Path.DirectorySeparatorChar + baseName + ".asset"); def.WriteXmlFile(defPath); } }