コード例 #1
0
        private static bool BuildProjectBlocking(BuildInfo buildInfo)
        {
            if (!File.Exists(buildInfo.Solution))
            {
                return(true); // No solution to build
            }
            // Make sure the API assemblies are up to date before building the project.
            // We may not have had the chance to update the release API assemblies, and the debug ones
            // may have been deleted by the user at some point after they were loaded by the Godot editor.
            string apiAssembliesUpdateError = Internal.UpdateApiAssembliesFromPrebuilt(buildInfo.Configuration == "ExportRelease" ? "Release" : "Debug");

            if (!string.IsNullOrEmpty(apiAssembliesUpdateError))
            {
                ShowBuildErrorDialog("Failed to update the Godot API assemblies");
                return(false);
            }

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public static bool BuildProjectBlocking(string config, IEnumerable <string> godotDefines)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return(true); // No solution to build
            }
            // Make sure the API assemblies are up to date before building the project.
            // We may not have had the chance to update the release API assemblies, and the debug ones
            // may have been deleted by the user at some point after they were loaded by the Godot editor.
            string apiAssembliesUpdateError = Internal.UpdateApiAssembliesFromPrebuilt(config == "ExportRelease" ? "Release" : "Debug");

            if (!string.IsNullOrEmpty(apiAssembliesUpdateError))
            {
                ShowBuildErrorDialog("Failed to update the Godot API assemblies");
                return(false);
            }

            var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
            var buildTool      = (BuildTool)editorSettings.GetSetting("mono/builds/build_tool");

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, targets: new[] { "Restore", "Build" }, config);

                bool escapeNeedsDoubleBackslash = buildTool == BuildTool.MsBuildMono || buildTool == BuildTool.DotnetCli;

                // Add Godot defines
                string constants = !escapeNeedsDoubleBackslash ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";

                foreach (var godotDefine in godotDefines)
                {
                    constants += $"GODOT_{godotDefine.ToUpper().Replace("-", "_").Replace(" ", "_").Replace(";", "_")};";
                }

                if (Internal.GodotIsRealTDouble())
                {
                    constants += "GODOT_REAL_T_IS_DOUBLE;";
                }

                constants += !escapeNeedsDoubleBackslash ? "\"" : "\\\"";

                buildInfo.CustomProperties.Add(constants);

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
        private bool CreateProjectSolution()
        {
            using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...".TTR(), 2))
            {
                pr.Step("Generating C# project...".TTR());

                string resourceDir = ProjectSettings.GlobalizePath("res://");

                string path = resourceDir;
                string name = GodotSharpDirs.ProjectAssemblyName;

                string guid = CsProjOperations.GenerateGameProject(path, name);

                if (guid.Length > 0)
                {
                    var solution = new DotNetSolution(name)
                    {
                        DirectoryPath = path
                    };

                    var projectInfo = new DotNetSolution.ProjectInfo
                    {
                        Guid = guid,
                        PathRelativeToSolution = name + ".csproj",
                        Configs = new List <string> {
                            "Debug", "ExportDebug", "ExportRelease"
                        }
                    };

                    solution.AddNewProject(name, projectInfo);

                    try
                    {
                        solution.Save();
                    }
                    catch (IOException e)
                    {
                        ShowErrorDialog("Failed to save solution. Exception message: ".TTR() + e.Message);
                        return(false);
                    }

                    pr.Step("Done".TTR());

                    // Here, after all calls to progress_task_step
                    CallDeferred(nameof(_RemoveCreateSlnMenuOption));
                }
                else
                {
                    ShowErrorDialog("Failed to create C# project.".TTR());
                }

                return(true);
            }
        }
コード例 #4
0
        private static bool PublishProjectBlocking(BuildInfo buildInfo)
        {
            using var pr = new EditorProgress("dotnet_publish_project", "Publishing .NET project...", 1);

            pr.Step("Running dotnet publish", 0);

            if (!Publish(buildInfo))
            {
                ShowBuildErrorDialog("Failed to publish .NET project");
                return(false);
            }

            return(true);
        }
コード例 #5
0
        public static bool BuildProjectBlocking(string config, IEnumerable <string> godotDefines)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return(true); // No solution to build
            }
            string apiConfig = config == "Release" ? "Release" : "Debug";

            if (!MakeApiAssembly(ApiAssemblyType.Core, apiConfig))
            {
                return(false);
            }

            if (!MakeApiAssembly(ApiAssemblyType.Editor, apiConfig))
            {
                return(false);
            }

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                var buildInfo = new MonoBuildInfo(GodotSharpDirs.ProjectSlnPath, config);

                // Add Godot defines
                string constants = OS.IsWindows() ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";

                foreach (var godotDefine in godotDefines)
                {
                    constants += $"GODOT_{godotDefine.ToUpper().Replace("-", "_").Replace(" ", "_").Replace(";", "_")};";
                }

                if (Internal.GodotIsRealTDouble())
                {
                    constants += "GODOT_REAL_T_IS_DOUBLE;";
                }

                constants += OS.IsWindows() ? "\"" : "\\\"";

                buildInfo.CustomProperties.Add(constants);

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        public static bool BuildProjectBlocking(string config, IEnumerable <string> godotDefines)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return(true); // No solution to build
            }
            // Make sure to update the API assemblies if they happen to be missing. Just in
            // case the user decided to delete them at some point after they were loaded.
            Internal.UpdateApiAssembliesFromPrebuilt();

            var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
            var buildTool      = (BuildTool)editorSettings.GetSetting("mono/builds/build_tool");

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, config);

                // Add Godot defines
                string constants = buildTool == BuildTool.MsBuildVs ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";

                foreach (var godotDefine in godotDefines)
                {
                    constants += $"GODOT_{godotDefine.ToUpper().Replace("-", "_").Replace(" ", "_").Replace(";", "_")};";
                }

                if (Internal.GodotIsRealTDouble())
                {
                    constants += "GODOT_REAL_T_IS_DOUBLE;";
                }

                constants += buildTool == BuildTool.MsBuildVs ? "\"" : "\\\"";

                buildInfo.CustomProperties.Add(constants);

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #7
0
        private static bool CleanProjectBlocking(BuildInfo buildInfo)
        {
            if (!File.Exists(buildInfo.Solution))
            {
                return(true); // No solution to clean
            }
            using var pr = new EditorProgress("dotnet_clean_project", "Cleaning .NET project...", 1);

            pr.Step("Cleaning project solution", 0);

            if (!Build(buildInfo))
            {
                ShowBuildErrorDialog("Failed to clean project solution");
                return(false);
            }

            return(true);
        }
コード例 #8
0
ファイル: BuildManager.cs プロジェクト: Edelweiss303/godot-1
        public static bool BuildProjectBlocking(string config, [CanBeNull] string platform = null)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return(true); // No solution to build
            }
            // Make sure the API assemblies are up to date before building the project.
            // We may not have had the chance to update the release API assemblies, and the debug ones
            // may have been deleted by the user at some point after they were loaded by the Godot editor.
            string apiAssembliesUpdateError = Internal.UpdateApiAssembliesFromPrebuilt(config == "ExportRelease" ? "Release" : "Debug");

            if (!string.IsNullOrEmpty(apiAssembliesUpdateError))
            {
                ShowBuildErrorDialog("Failed to update the Godot API assemblies");
                return(false);
            }

            using (var pr = new EditorProgress("mono_project_debug_build", "Building project solution...", 1))
            {
                pr.Step("Building project solution", 0);

                var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, targets: new[] { "Build" }, config, restore: true);

                // If a platform was not specified, try determining the current one. If that fails, let MSBuild auto-detect it.
                if (platform != null || OS.PlatformNameMap.TryGetValue(Godot.OS.GetName(), out platform))
                {
                    buildInfo.CustomProperties.Add($"GodotTargetPlatform={platform}");
                }

                if (Internal.GodotIsRealTDouble())
                {
                    buildInfo.CustomProperties.Add("GodotRealTIsDouble=true");
                }

                if (!Build(buildInfo))
                {
                    ShowBuildErrorDialog("Failed to build project solution");
                    return(false);
                }
            }

            return(true);
        }
コード例 #9
0
        private bool CreateProjectSolution()
        {
            using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...".TTR(), 3))
            {
                pr.Step("Generating C# project...".TTR());

                string resourceDir = ProjectSettings.GlobalizePath("res://");

                string path = resourceDir;
                string name = (string)ProjectSettings.GetSetting("application/config/name");
                if (name.Empty())
                {
                    name = "UnnamedProject";
                }

                string guid = CsProjOperations.GenerateGameProject(path, name);

                if (guid.Length > 0)
                {
                    var solution = new DotNetSolution(name)
                    {
                        DirectoryPath = path
                    };

                    var projectInfo = new DotNetSolution.ProjectInfo
                    {
                        Guid = guid,
                        PathRelativeToSolution = name + ".csproj",
                        Configs = new List <string> {
                            "Debug", "Release", "Tools"
                        }
                    };

                    solution.AddNewProject(name, projectInfo);

                    try
                    {
                        solution.Save();
                    }
                    catch (IOException e)
                    {
                        ShowErrorDialog("Failed to save solution. Exception message: ".TTR() + e.Message);
                        return(false);
                    }

                    pr.Step("Updating Godot API assemblies...".TTR());

                    string debugApiAssembliesError = Internal.UpdateApiAssembliesFromPrebuilt("Debug");

                    if (!string.IsNullOrEmpty(debugApiAssembliesError))
                    {
                        ShowErrorDialog("Failed to update the Godot API assemblies: " + debugApiAssembliesError);
                        return(false);
                    }

                    string releaseApiAssembliesError = Internal.UpdateApiAssembliesFromPrebuilt("Release");

                    if (!string.IsNullOrEmpty(releaseApiAssembliesError))
                    {
                        ShowErrorDialog("Failed to update the Godot API assemblies: " + releaseApiAssembliesError);
                        return(false);
                    }

                    pr.Step("Done".TTR());

                    // Here, after all calls to progress_task_step
                    CallDeferred(nameof(_RemoveCreateSlnMenuOption));
                }
                else
                {
                    ShowErrorDialog("Failed to create C# project.".TTR());
                }

                return(true);
            }
        }
コード例 #10
0
ファイル: GodotSharpEditor.cs プロジェクト: vkkevin/godot
        private bool CreateProjectSolution()
        {
            using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...".TTR(), 2))
            {
                pr.Step("Generating C# project...".TTR());

                string resourceDir = ProjectSettings.GlobalizePath("res://");

                string path = resourceDir;
                string name = (string)ProjectSettings.GetSetting("application/config/name");
                if (name.Empty())
                {
                    name = "UnnamedProject";
                }

                string guid = CSharpProject.GenerateGameProject(path, name);

                if (guid.Length > 0)
                {
                    var solution = new DotNetSolution(name)
                    {
                        DirectoryPath = path
                    };

                    var projectInfo = new DotNetSolution.ProjectInfo
                    {
                        Guid = guid,
                        PathRelativeToSolution = name + ".csproj",
                        Configs = new List <string> {
                            "Debug", "Release", "Tools"
                        }
                    };

                    solution.AddNewProject(name, projectInfo);

                    try
                    {
                        solution.Save();
                    }
                    catch (IOException e)
                    {
                        ShowErrorDialog("Failed to save solution. Exception message: ".TTR() + e.Message);
                        return(false);
                    }

                    // Make sure to update the API assemblies if they happen to be missing. Just in
                    // case the user decided to delete them at some point after they were loaded.
                    Internal.UpdateApiAssembliesFromPrebuilt();

                    pr.Step("Done".TTR());

                    // Here, after all calls to progress_task_step
                    CallDeferred(nameof(_RemoveCreateSlnMenuOption));
                }
                else
                {
                    ShowErrorDialog("Failed to create C# project.".TTR());
                }

                return(true);
            }
        }
コード例 #11
0
ファイル: GodotSharpEditor.cs プロジェクト: rohithbt/godot
        private bool CreateProjectSolution()
        {
            using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...", 2)) // TTR("Generating solution...")
            {
                pr.Step("Generating C# project...");                                                   // TTR("Generating C# project...")

                string resourceDir = ProjectSettings.GlobalizePath("res://");

                string path = resourceDir;
                string name = (string)ProjectSettings.GetSetting("application/config/name");
                if (name.Empty())
                {
                    name = "UnnamedProject";
                }

                string guid = CSharpProject.GenerateGameProject(path, name);

                if (guid.Length > 0)
                {
                    var solution = new DotNetSolution(name)
                    {
                        DirectoryPath = path
                    };

                    var projectInfo = new DotNetSolution.ProjectInfo
                    {
                        Guid = guid,
                        PathRelativeToSolution = name + ".csproj",
                        Configs = new List <string> {
                            "Debug", "Release", "Tools"
                        }
                    };

                    solution.AddNewProject(name, projectInfo);

                    try
                    {
                        solution.Save();
                    }
                    catch (IOException e)
                    {
                        ShowErrorDialog($"Failed to save solution. Exception message: {e.Message}"); // TTR
                        return(false);
                    }

                    string apiConfig = "Debug";

                    if (!GodotSharpBuilds.MakeApiAssembly(ApiAssemblyType.Core, apiConfig))
                    {
                        return(false);
                    }

                    if (!GodotSharpBuilds.MakeApiAssembly(ApiAssemblyType.Editor, apiConfig))
                    {
                        return(false);
                    }

                    pr.Step("Done"); // TTR("Done")

                    // Here, after all calls to progress_task_step
                    CallDeferred(nameof(_RemoveCreateSlnMenuOption));
                }
                else
                {
                    ShowErrorDialog("Failed to create C# project."); // TTR
                }

                return(true);
            }
        }
コード例 #12
0
        public override void OnInspectorGUI()
        {
            var obj = (TextureToGameObjectImporter)target;

            base.OnInspectorGUI();
            EditorGUILayout.Space();
            if (GUILayout.Button("Generate"))
            {
                if (!obj.texture)
                {
                    EditorUtils.userInfo(
                        "Texture not set!", "Please set the texture before generating.", Log.Level.ERROR
                        );
                    return;
                }

                var        width              = obj.texture.width;
                var        height             = obj.texture.height;
                var        unknownColorsFound = new HashSet <Color32>();
                const byte maxAlpha           = byte.MaxValue;
                var        ignoredColors      = obj.ignoredColors.Select(_ => _.with32Alpha(maxAlpha)).toHashSet();
                var        dictV              = obj.pallete
                                                .GroupBy(_ => _.color.with32Alpha(maxAlpha))
                                                .Select(group => {
                    var count = group.Count();
                    return((
                               count == 1
              ? Either <string, KeyValuePair <Color32, GameObject[]> > .Right(F.kv(
                                                                                  group.Key, group.SelectMany(_ => _.gameObjects).ToArray()
                                                                                  ))
              : Either <string, KeyValuePair <Color32, GameObject[]> > .Left(
                                   $"#{group.Key.toHex()} should have 1 entry: {count} entries found."
                                   )
                               ).asValidation());
                })
                                                .sequenceValidations();
                if (dictV.isLeft)
                {
                    EditorUtils.userInfo(
                        "Invalid pallete!",
                        dictV.__unsafeGetLeft.mkString("\n"),
                        Log.Level.ERROR
                        );
                    return;
                }
                var dict = dictV.__unsafeGetRight.toDict();

                using (var progress = new EditorProgress("Generating objects")) {
                    var pixels = progress.execute("Getting pixels", obj.texture.GetPixels32);
                    var parent = new GameObject(obj.holderGameObjectName).transform;

                    progress.execute("Reading pixels", () => {
                        var rng = new Rng(new Rng.Seed(obj.randomSeed));
                        for (var y = 0; y < height; y++)
                        {
                            for (var x = 0; x < width; x++)
                            {
                                var idx = y * width + x;
                                // ReSharper disable once AccessToDisposedClosure
                                progress.progress(idx, pixels.Length);
                                var pixel = pixels[idx].with32Alpha(maxAlpha);
                                if (dict.TryGetValue(pixel, out var gameObjects))
                                {
                                    var position          = obj.startPoint + new Vector3(x * obj.spacing.x, y * obj.spacing.y);
                                    var go                = gameObjects.random(ref rng).getOrThrow($"No objects for #{pixel.toHex()} found!");
                                    var instantiated      = ((GameObject)PrefabUtility.InstantiatePrefab(go)).transform;
                                    instantiated.parent   = parent;
                                    instantiated.position = position;
                                }
                                else if (!ignoredColors.Contains(pixel))
                                {
                                    unknownColorsFound.Add(pixel);
                                }
                            }
                        }
                    });
                }

                if (unknownColorsFound.nonEmpty())
                {
                    EditorUtils.userInfo(
                        "Found unknown colors!", level: Log.Level.ERROR,
                        body:
                        "These colors were not defined:\n" +
                        unknownColorsFound.Select(_ => $"#{_.toHex()}").OrderBySafe(_ => _).mkString("\n")
                        );
                }
            }
        }
コード例 #13
0
        public static bool MakeApiAssembly(ApiAssemblyType apiType, string config)
        {
            string apiName = apiType == ApiAssemblyType.Core ? ApiAssemblyNames.Core : ApiAssemblyNames.Editor;

            string editorPrebuiltApiDir = Path.Combine(GodotSharpDirs.DataEditorPrebuiltApiDir, config);
            string resAssembliesDir     = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, config);

            if (File.Exists(Path.Combine(editorPrebuiltApiDir, $"{apiName}.dll")))
            {
                using (var copyProgress = new EditorProgress("mono_copy_prebuilt_api_assembly", $"Copying prebuilt {apiName} assembly...", 1))
                {
                    copyProgress.Step($"Copying {apiName} assembly", 0);
                    return(CopyApiAssembly(editorPrebuiltApiDir, resAssembliesDir, apiName, apiType));
                }
            }

            const string apiSolutionName = ApiAssemblyNames.SolutionName;

            using (var pr = new EditorProgress($"mono_build_release_{apiSolutionName}", $"Building {apiSolutionName} solution...", 3))
            {
                pr.Step($"Generating {apiSolutionName} solution", 0);

                string apiSlnDir  = Path.Combine(GodotSharpDirs.MonoSolutionsDir, _ApiFolderName(ApiAssemblyType.Core));
                string apiSlnFile = Path.Combine(apiSlnDir, $"{apiSolutionName}.sln");

                if (!Directory.Exists(apiSlnDir) || !File.Exists(apiSlnFile))
                {
                    var bindingsGenerator = new BindingsGenerator();

                    if (!Godot.OS.IsStdoutVerbose())
                    {
                        bindingsGenerator.LogPrintEnabled = false;
                    }

                    Error err = bindingsGenerator.GenerateCsApi(apiSlnDir);
                    if (err != Error.Ok)
                    {
                        ShowBuildErrorDialog($"Failed to generate {apiSolutionName} solution. Error: {err}");
                        return(false);
                    }
                }

                pr.Step($"Building {apiSolutionName} solution", 1);

                if (!BuildApiSolution(apiSlnDir, config))
                {
                    return(false);
                }

                pr.Step($"Copying {apiName} assembly", 2);

                // Copy the built assembly to the assemblies directory
                string apiAssemblyDir = Path.Combine(apiSlnDir, apiName, "bin", config);
                if (!CopyApiAssembly(apiAssemblyDir, resAssembliesDir, apiName, apiType))
                {
                    return(false);
                }
            }

            return(true);
        }