public Pipeline(string inputPath, string outputRoot, string outputFolder, string layer1) { _inputPath = fixPath(inputPath); _outputRoot = fixPath(outputRoot); _outputPath = fixPath(Path.Combine(outputRoot, outputFolder)); _layer1 = fixPath(layer1); Console.WriteLine($"Input path: {_inputPath}"); Console.WriteLine($"Output path: {_outputPath}"); Console.WriteLine($"Output root: {_outputRoot}"); List <string> result = new List <string>(); searchDirectory(_inputPath, result); Target target = new Target(TargetPlatform.Windows, TargetGraphicsBackend.OpenGL); Dictionary <string, ICompilerPreset> compilerPreset = new Dictionary <string, ICompilerPreset>(); compilerPreset.Add(".txt", new CompilerPreset <string, Settings <string> >(new CompileString(), new Settings <string>(target))); if (result.Count > 0) { Console.WriteLine("Found content:"); RecurseDirectory links = new RecurseDirectory(); foreach (string f in result) { string trimFilePath = trimPathRoot(_inputPath, f); string fileInputPath = createInputPath(_inputPath, trimFilePath); string fileOutputPath = createOutputPath(_outputPath, trimFilePath); string trimOutputPath = trimPathRoot(_outputRoot, fileOutputPath); try { compilerPreset[Path.GetExtension(f)].Build(fileInputPath, fileOutputPath); Console.WriteLine($"\tCompiled: {trimFilePath} to {fileOutputPath}"); string left; string right; trimOutputPath.ParseDirectory(out left, out right); links.Add(right, Path.GetFileName(trimFilePath).NormalizePath()); } catch (Exception) { Console.WriteLine($"\tFailed: {trimFilePath}"); } } generateClass(links, Path.Combine(_layer1, "AssetLinks.cs")); Console.WriteLine("Done building content."); } else { Console.WriteLine("Didn't find any content."); } }
private void generateClass(RecurseDirectory links, string outputFile) { StringBuilder sb = new StringBuilder(); sb.AppendLine("namespace GameProject {"); sb.AppendLine($" public static class {Path.GetFileNameWithoutExtension(outputFile)}" + " {"); links.GenerateClass(sb, " ", "Assets/"); sb.AppendLine(" }"); sb.AppendLine("}"); using (FileStream fs = new FileStream(outputFile, FileMode.Create)) using (StreamWriter sw = new StreamWriter(fs)){ sw.Write(sb.ToString()); } }