Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Assets/Rivet/Editor/UI/Tabs/DeployController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -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");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Rivet/Editor/UI/Tabs/Develop.uxml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<AttributeOverrides element-name="Label" text="Restart" />
</ui:Instance>
</ui:VisualElement>
<ui:Label tabindex="-1" text="&lt;u&gt;Show Logs&lt;/u&gt;" parse-escape-sequences="true" display-tooltip-when-elided="true" name="LogsButton" style="-unity-text-align: upper-center;" />
<ui:Label tabindex="-1" text="&lt;u&gt;Show Logs&lt;/u&gt;" parse-escape-sequences="true" display-tooltip-when-elided="true" name="LogsButton" style="-unity-text-align: upper-center; display: none;" />
</ui:VisualElement>
<ui:Instance template="Separator" name="Separator" />
<ui:Instance template="Header" name="PlayerHeader">
Expand Down
31 changes: 17 additions & 14 deletions Assets/Rivet/Editor/UI/Tabs/DevelopController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Rivet/Editor/UI/Tabs/Settings.uxml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
<ui:Button text="Stop" parse-escape-sequences="true" display-tooltip-when-elided="true" name="StopButton" style="flex-shrink: 1; flex-grow: 1;" />
<ui:Button text="Restart" parse-escape-sequences="true" display-tooltip-when-elided="true" name="RestartButton" style="flex-shrink: 1; flex-grow: 1;" />
</ui:VisualElement>
<ui:Label tabindex="-1" text="&lt;u&gt;Show Logs&lt;/u&gt;" parse-escape-sequences="true" display-tooltip-when-elided="true" name="LogsButton" style="-unity-text-align: upper-center;" />
<ui:Label tabindex="-1" text="&lt;u&gt;Show Logs&lt;/u&gt;" parse-escape-sequences="true" display-tooltip-when-elided="true" name="LogsButton" style="-unity-text-align: upper-center; display: none;" />
</ui:VisualElement>
</ui:UXML>
82 changes: 32 additions & 50 deletions Assets/Rivet/Editor/Util/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public static string GetUnityEditorPath()
}

/// <summary>
/// Builds a development player for the host OS.
/// Build target for building for the current OS.
///
/// Used for player & dev server builds.
/// </summary>
/// <returns>Returns the path to the built player executable.</returns>
public static BuildTarget GetPlayerBuildTarget()
public static BuildTarget GetLocalBuildTarget()
{
switch (Application.platform)
{
Expand All @@ -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
};

Expand All @@ -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.");
}
}

Expand All @@ -96,10 +92,11 @@ public static BuildTarget GetPlayerBuildTarget()
/// <param name="instanceCount">The number of player instances to run.</param>
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;
}

Expand Down Expand Up @@ -129,43 +126,30 @@ public static void BuildAndRunMultipleDevPlayers(int instanceCount)
}

// MARK: Run Game Server
public static BuildTarget GetGameServerBuildTarget()
{
// TODO:
return BuildTarget.StandaloneOSX;
}

/// <summary>
/// Builds a server used for local development.
/// </summary>
/// <returns>Returns the task config to run the server.</returns>
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
};
Expand All @@ -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
Expand All @@ -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.");
}
}

Expand All @@ -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}");
Expand Down Expand Up @@ -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;
}
Expand Down