diff --git a/Assets/Rivet/Editor/UI/Tabs/DeployController.cs b/Assets/Rivet/Editor/UI/Tabs/DeployController.cs index 15d930e..1472cca 100644 --- a/Assets/Rivet/Editor/UI/Tabs/DeployController.cs +++ b/Assets/Rivet/Editor/UI/Tabs/DeployController.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -102,11 +103,10 @@ private void OnBuildAndDeploy() string? serverPath = null; if (deployGameServer) { - serverPath = Builder.BuildReleaseDedicatedServer(); - if (serverPath == null) - { - EditorUtility.DisplayDialog("Server Build Failed", "See Unity console for details.", "Dismiss"); - return; + try { + serverPath = Builder.BuildReleaseDedicatedServer(); + } catch (Exception e) { + EditorUtility.DisplayDialog("Server Build Failed", e.Message, "Dismiss"); } } diff --git a/Assets/Rivet/Editor/UI/Tabs/Develop.uxml b/Assets/Rivet/Editor/UI/Tabs/Develop.uxml index 333346b..04c17db 100644 --- a/Assets/Rivet/Editor/UI/Tabs/Develop.uxml +++ b/Assets/Rivet/Editor/UI/Tabs/Develop.uxml @@ -28,7 +28,7 @@ - + diff --git a/Assets/Rivet/Editor/UI/Tabs/DevelopController.cs b/Assets/Rivet/Editor/UI/Tabs/DevelopController.cs index 6c7e108..65fbc99 100644 --- a/Assets/Rivet/Editor/UI/Tabs/DevelopController.cs +++ b/Assets/Rivet/Editor/UI/Tabs/DevelopController.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Data.SqlClient; using System.IO; @@ -142,22 +143,24 @@ private void OnLocalGameServerStateChange(bool running) private void OnLocalGameServerStart() { - var serverPath = Builder.BuildDevDedicatedServer(); - if (serverPath != null) - { - _pluginWindow.LocalGameServerExecutablePath = serverPath; - // _ = _pluginWindow.LocalGameServerManager.StartTask(); - _ = new RivetTask("show_term", new JObject - { - ["command"] = _pluginWindow.LocalGameServerExecutablePath, - // ["args"] = new JArray { "-batchmode", "-nographics", "-logFile", logPath, "-server" }, - ["args"] = new JArray { "-batchmode", "-nographics", "-server" }, - }).RunAsync(); + string serverPath; + try { + serverPath = Builder.BuildDevDedicatedServer(); + } catch (Exception e) { + EditorUtility.DisplayDialog("Server Build Failed", e.Message, "Dismiss"); + return; } - else + + _pluginWindow.LocalGameServerExecutablePath = serverPath; + + // _ = _pluginWindow.LocalGameServerManager.StartTask(); + + _ = new RivetTask("show_term", new JObject { - EditorUtility.DisplayDialog("Game Server Build Failed", "See Unity console for details.", "Dismiss"); - } + ["command"] = _pluginWindow.LocalGameServerExecutablePath, + // ["args"] = new JArray { "-batchmode", "-nographics", "-logFile", logPath, "-server" }, + ["args"] = new JArray { "-batchmode", "-nographics", "-server" }, + }).RunAsync(); } private void OnPlayerStart() diff --git a/Assets/Rivet/Editor/UI/Tabs/Settings.uxml b/Assets/Rivet/Editor/UI/Tabs/Settings.uxml index b55dc39..58b310a 100644 --- a/Assets/Rivet/Editor/UI/Tabs/Settings.uxml +++ b/Assets/Rivet/Editor/UI/Tabs/Settings.uxml @@ -29,6 +29,6 @@ - + diff --git a/Assets/Rivet/Editor/Util/Builder.cs b/Assets/Rivet/Editor/Util/Builder.cs index b475e70..9ab59cd 100644 --- a/Assets/Rivet/Editor/Util/Builder.cs +++ b/Assets/Rivet/Editor/Util/Builder.cs @@ -24,10 +24,12 @@ public static string GetUnityEditorPath() } /// - /// Builds a development player for the host OS. + /// Build target for building for the current OS. + /// + /// Used for player & dev server builds. /// /// Returns the path to the built player executable. - public static BuildTarget GetPlayerBuildTarget() + public static BuildTarget GetLocalBuildTarget() { switch (Application.platform) { @@ -38,38 +40,33 @@ public static BuildTarget GetPlayerBuildTarget() case RuntimePlatform.LinuxEditor: return BuildTarget.StandaloneLinux64; default: - Debug.LogError("Unsupported platform for player build"); + Debug.LogError("Unsupported platform for build"); return BuildTarget.StandaloneWindows64; // Default to Windows as fallback } } - public static string? BuildDevPlayer() + public static string BuildDevPlayer() { // Check if the target platform is supported - if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, GetPlayerBuildTarget())) + if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, GetLocalBuildTarget())) { - RivetLogger.Error($"{GetPlayerBuildTarget()} build support is not installed"); - EditorUtility.DisplayDialog( - $"{GetPlayerBuildTarget()} Build Support Missing", - $"{GetPlayerBuildTarget()} build support is not installed. Please install it from the Unity Hub to proceed with the build process.", - "Dismiss" + throw new Exception( + $"{GetLocalBuildTarget()} build support is not installed. Please install it from the Unity Hub to proceed with the build process." ); - return null; } // Ensure a scene is included if (EditorBuildSettings.scenes.Length == 0) { - RivetLogger.Error("No scenes in build settings. Please add at least one scene."); - return null; + throw new Exception("No scenes in build settings. Please add a scene under File > Build Settings. The first build is the scene the server will run."); } // Configure build settings var buildPlayerOptions = new BuildPlayerOptions { scenes = GetScenePaths(), - locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "Player", GetPlatformArchFolder(GetPlayerBuildTarget()), GetBuildName("Player", GetPlayerBuildTarget())), - target = GetPlayerBuildTarget(), + locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "Player", GetPlatformArchFolder(GetLocalBuildTarget()), GetBuildName("Player", GetLocalBuildTarget())), + target = GetLocalBuildTarget(), options = BuildOptions.Development | BuildOptions.AllowDebugging }; @@ -85,8 +82,7 @@ public static BuildTarget GetPlayerBuildTarget() } else { - Debug.LogError("Dev player build failed"); - return null; + throw new Exception("Dev player build failed. Check console for errors."); } } @@ -96,10 +92,11 @@ public static BuildTarget GetPlayerBuildTarget() /// The number of player instances to run. public static void BuildAndRunMultipleDevPlayers(int instanceCount) { - string? playerPath = BuildDevPlayer(); - if (playerPath == null) - { - Debug.LogError("Failed to build dev player. Cannot run instances."); + string playerPath; + try { + playerPath = BuildDevPlayer(); + } catch (Exception e) { + EditorUtility.DisplayDialog("Player Build Failed", e.Message, "Dismiss"); return; } @@ -129,43 +126,30 @@ public static void BuildAndRunMultipleDevPlayers(int instanceCount) } // MARK: Run Game Server - public static BuildTarget GetGameServerBuildTarget() - { - // TODO: - return BuildTarget.StandaloneOSX; - } - /// /// Builds a server used for local development. /// /// Returns the task config to run the server. - public static string? BuildDevDedicatedServer() + public static string BuildDevDedicatedServer() { // Check if the target platform is supported - if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, GetGameServerBuildTarget())) + if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, GetLocalBuildTarget())) { - RivetLogger.Error($"{GetGameServerBuildTarget()} build support is not installed"); - EditorUtility.DisplayDialog( - $"{GetGameServerBuildTarget()} Build Support Missing", - $"{GetGameServerBuildTarget()} build support is not installed. Please install it from the Unity Hub to proceed with the build process.", - "Dismiss" - ); - return null; + throw new Exception($"{GetLocalBuildTarget()} build support is not installed. Please install it from the Unity Hub to proceed with the build process."); } // Ensure a scene is included if (EditorBuildSettings.scenes.Length == 0) { - RivetLogger.Error("No scenes in build settings. Please add at least one scene."); - return null; + throw new Exception("No scenes in build settings. Please add a scene under File > Build Settings. The first build is the scene the server will run."); } // Configure build settings var buildPlayerOptions = new BuildPlayerOptions { scenes = GetScenePaths(), - locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "DedicatedServer", GetPlatformArchFolder(GetGameServerBuildTarget()), GetBuildName("DedicatedServer", GetGameServerBuildTarget(), true)), - target = GetGameServerBuildTarget(), + locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "DedicatedServer", GetPlatformArchFolder(GetLocalBuildTarget()), GetBuildName("DedicatedServer", GetLocalBuildTarget(), true)), + target = GetLocalBuildTarget(), options = BuildOptions.Development | BuildOptions.CompressWithLz4 | BuildOptions.EnableHeadlessMode, subtarget = (int)StandaloneBuildSubtarget.Server }; @@ -183,30 +167,27 @@ public static BuildTarget GetGameServerBuildTarget() } else { - RivetLogger.Error("Dedicated server build failed."); - return null; + throw new Exception("Dedicated server build failed. Ensure the \"Dedicated Server\" Unity module is installed for your platform in the Unity Hub. Check the console for errors."); } } - public static string? BuildReleaseDedicatedServer() + public static string BuildReleaseDedicatedServer() { // Ensure a scene is included if (EditorBuildSettings.scenes.Length == 0) { - RivetLogger.Error("No scenes in build settings. Please add at least one scene."); - return null; + throw new Exception("No scenes in build settings. Please add a scene under File > Build Settings. The first build is the scene the server will run."); } // Check if Linux build support is installed if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, BuildTarget.StandaloneLinux64)) { - RivetLogger.Error("Linux build support is not installed"); EditorUtility.DisplayDialog( "Linux Build Support Missing", "Linux build support is not installed. Please install it from the Unity Hub to proceed with the build and deploy process.", "Dismiss" ); - return null; + throw new Exception("Linux build support is not installed"); } // Configure build settings @@ -231,8 +212,7 @@ public static BuildTarget GetGameServerBuildTarget() } else { - RivetLogger.Error("Production server build failed."); - return null; + throw new Exception("Production server build failed. Ensure the \"Dedicated Server\" Unity module is installed for Linux in the Unity Hub. Check console for errors."); } } @@ -257,7 +237,7 @@ public static string FindServerExecutablePath(string serverPath, BuildTarget bui break; case BuildTarget.StandaloneWindows: case BuildTarget.StandaloneWindows64: - executableFile = Path.Combine(serverPath, $"{productName}.exe"); + executableFile = serverPath; break; default: throw new ArgumentException($"Unsupported build target: {buildTarget}"); @@ -312,6 +292,8 @@ public static string GetBuildName(string baseName, BuildTarget target, bool isSe if (target == BuildTarget.StandaloneOSX && !isServer) { return baseName + ".app"; + } else if (target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64) { + return baseName + ".exe"; } return baseName; }