コード例 #1
0
ファイル: ExeRunner.cs プロジェクト: Wunder9l/UnityFbs
        private string MakeArguments(List <string> inputFiles, GeneratedOutputEnum output)
        {
            var outputDir = Path.GetDirectoryName(inputFiles.First());
            var builder   = new StringBuilder(output.ToArgument());

            builder.Append(" --gen-onefile");
            builder.Append($" -o {outputDir}");
            GetAdditionalArgs(output).ForEach(arg => builder.Append($" {arg}"));
            inputFiles.ForEach(f => builder.Append($" {f}"));
            return(builder.ToString());
        }
コード例 #2
0
ファイル: ExeRunner.cs プロジェクト: Wunder9l/UnityFbs
        private List <string> GetAdditionalArgs(GeneratedOutputEnum output)
        {
            switch (output)
            {
            case GeneratedOutputEnum.cs:
                return(UnityFbsSettings.GetOrCreateSettings().CsAdditionalArguments);

            case GeneratedOutputEnum.python:
                return(UnityFbsSettings.GetOrCreateSettings().PythonAdditionalArguments);

            case GeneratedOutputEnum.cpp:
                return(UnityFbsSettings.GetOrCreateSettings().CppAdditionalArguments);
            }
            return(new List <string>());
        }
コード例 #3
0
        private static void GenerateDefinition(GeneratedOutputEnum target)
        {
            var    files       = GetSelectedFbsFiles();
            string fileOrFiles = (files.Count == 1) ? "file" : "files";

            Debug.Log($"Generating {target} {fileOrFiles} for {string.Join(", ", files)}");

            var exe    = new ExeRunner(UnityFbsSettings.GetOrCreateSettings().FlatcPath);
            var errors = exe.Run(files, target);

            if (errors.Length > 0)
            {
                EditorUtility.DisplayDialog(FAIL_DIALOG_TITLE, $"Generating {target} definition for [{string.Join(", ", files)}] failed:\n{errors}", "Ok");
            }
            AssetDatabase.Refresh();
        }
コード例 #4
0
        public static string ToArgument(this GeneratedOutputEnum en)
        {
            Type type = en.GetType();

            MemberInfo[] memInfo = type.GetMember(en.ToString());

            if (memInfo != null && memInfo.Length > 0)
            {
                object[] attrs = memInfo[0].GetCustomAttributes(typeof(Argument), false);
                if (attrs != null && attrs.Length > 0)
                {
                    return(((Argument)attrs[0]).Text);
                }
            }

            return(en.ToString());
        }
コード例 #5
0
ファイル: ExeRunner.cs プロジェクト: Wunder9l/UnityFbs
        public string Run(List <string> inputFiles, GeneratedOutputEnum output)
        {
            if (inputFiles.Count == 0)
            {
                return("");
            }
            if (!CheckFile(flatcPath))
            {
                return($"flatc-executable file not found, please check UnityFbsSettings for correctness. Current file path is {flatcPath}");
            }

            string arguments = MakeArguments(inputFiles, output);

            UnityEngine.Debug.Log($"Run fltac with args: {arguments}");
            var process = new Process {
                StartInfo = new ProcessStartInfo {
                    FileName        = Path.GetFullPath(flatcPath),
                    Arguments       = MakeArguments(inputFiles, output),
                    UseShellExecute = false,
                    //RedirectStandardError = true,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };
            var started = process.Start();

            if (!started)
            {
                return("Process flatc was not started");
            }

            StringBuilder errors = new StringBuilder();

            while (!process.StandardOutput.EndOfStream)
            {
                var line = process.StandardOutput.ReadLine();
                UnityEngine.Debug.LogError(line);
                errors.Append(line);
            }

            process.WaitForExit();
            return(errors.ToString());
        }