コード例 #1
0
ファイル: GenerateCode.cs プロジェクト: ht290/gdk-for-unity
        private static void Generate()
        {
            try
            {
                EditorApplication.LockReloadAssemblies();

                // Ensure that all dependencies are in place.
                if (DownloadCoreSdk.TryDownload() == DownloadResult.Error)
                {
                    return;
                }

                CopySchema();

                var projectPath = Path.GetFullPath(Path.Combine(Common.GetThisPackagePath(),
                                                                CsProjectFile));

                var schemaCompilerPath =
                    Path.GetFullPath(Path.Combine(Application.dataPath, SchemaCompilerRelativePath));

                var workerJsonPath =
                    Path.GetFullPath(Path.Combine(Application.dataPath, ".."));

                switch (Application.platform)
                {
                case RuntimePlatform.WindowsEditor:
                    schemaCompilerPath = Path.ChangeExtension(schemaCompilerPath, ".exe");
                    break;

                case RuntimePlatform.LinuxEditor:
                case RuntimePlatform.OSXEditor:
                    // Ensure the schema compiler is executable.
                    var _ = RedirectedProcess.Command("chmod").WithArgs("+x", $"\"{schemaCompilerPath}\"").Run();
                    break;

                default:
                    throw new PlatformNotSupportedException(
                              $"The {Application.platform} platform does not support code generation.");
                }

                using (new ShowProgressBarScope("Generating code..."))
                {
                    var exitCode = RedirectedProcess.Command(Common.DotNetBinary)
                                   .WithArgs(ConstructArgs(projectPath, schemaCompilerPath, workerJsonPath))
                                   .RedirectOutputOptions(OutputRedirectBehaviour.None)
                                   .AddErrorProcessing(Debug.LogError)
                                   .AddOutputProcessing(ProcessStdOut)
                                   .Run();

                    if (exitCode != 0)
                    {
                        if (!Application.isBatchMode)
                        {
                            EditorApplication.delayCall += () =>
                            {
                                EditorUtility.DisplayDialog("Generate Code",
                                                            "Failed to generate code from schema.\nPlease view the console for errors.",
                                                            "Close");
                            };
                        }
                    }
                    else
                    {
                        File.WriteAllText(StartupCodegenMarkerFile, string.Empty);
                    }
                }

                AssetDatabase.Refresh();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            finally
            {
                EditorApplication.UnlockReloadAssemblies();
            }
        }
コード例 #2
0
        private static void Generate()
        {
            try
            {
                EditorApplication.LockReloadAssemblies();

                // Ensure that all dependencies are in place.
                if (DownloadCoreSdk.TryDownload() == DownloadResult.Error)
                {
                    return;
                }

                CopySchema();

                var projectPath = Path.GetFullPath(Path.Combine(Common.GetThisPackagePath(),
                                                                CsProjectFile));

                var schemaCompilerPath =
                    Path.GetFullPath(Path.Combine(Application.dataPath, SchemaCompilerRelativePath));

                var workerJsonPath =
                    Path.GetFullPath(Path.Combine(Application.dataPath, ".."));

                switch (Application.platform)
                {
                case RuntimePlatform.WindowsEditor:
                    schemaCompilerPath = Path.ChangeExtension(schemaCompilerPath, ".exe");
                    break;

                case RuntimePlatform.LinuxEditor:
                case RuntimePlatform.OSXEditor:
                    // Ensure the schema compiler is executable.
                    var _ = RedirectedProcess.Run("chmod", "+x", schemaCompilerPath);
                    break;

                default:
                    throw new PlatformNotSupportedException(
                              $"The {Application.platform} platform does not support code generation.");
                }

                using (new ShowProgressBarScope("Generating code..."))
                {
                    var exitCode = RedirectedProcess.Run(Common.DotNetBinary,
                                                         ConstructArgs(projectPath, schemaCompilerPath, workerJsonPath));

                    if (exitCode != 0)
                    {
                        Debug.LogError("Failed to generate code.");
                    }
                    else
                    {
                        File.WriteAllText(StartupCodegenMarkerFile, string.Empty);
                    }
                }

                AssetDatabase.Refresh();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            finally
            {
                EditorApplication.UnlockReloadAssemblies();
            }
        }
コード例 #3
0
        private static void Generate()
        {
            try
            {
                EditorApplication.LockReloadAssemblies();

                // Ensure that all dependencies are in place.
                if (DownloadCoreSdk.TryDownload() == DownloadResult.Error)
                {
                    return;
                }

                CopySchema(SchemaRootDir);

                var projectPath = Path.GetFullPath(Path.Combine(Common.GetThisPackagePath(),
                                                                CsProjectFile));

                var schemaCompilerPath =
                    Path.GetFullPath(Path.Combine(Application.dataPath, SchemaCompilerRelativePath));

                switch (Application.platform)
                {
                case RuntimePlatform.WindowsEditor:
                    schemaCompilerPath = Path.ChangeExtension(schemaCompilerPath, ".exe");
                    break;

                case RuntimePlatform.LinuxEditor:
                case RuntimePlatform.OSXEditor:
                    // Ensure the schema compiler is executable.
                    var _ = RedirectedProcess.Run("chmod", "+x", schemaCompilerPath);
                    break;

                default:
                    throw new PlatformNotSupportedException(
                              $"The {Application.platform} platform does not support code generation.");
                }

                using (new ShowProgressBarScope("Generating code..."))
                {
                    var exitCode = RedirectedProcess.Run(Common.DotNetBinary, "run", "-p", $"\"{projectPath}\"", "--",
                                                         $"--schema-path=\"{SchemaRootDir}\"",
                                                         $"--schema-path={SchemaStandardLibraryDir}",
                                                         $"--json-dir={ImprobableJsonDir}",
                                                         $"--native-output-dir={AssetsGeneratedSourceDir}",
                                                         $"--schema-compiler-path=\"{schemaCompilerPath}\"");

                    if (exitCode != 0)
                    {
                        Debug.LogError("Failed to generate code.");
                    }
                }

                AssetDatabase.Refresh();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            finally
            {
                EditorApplication.UnlockReloadAssemblies();
            }
        }