Skip to content

Commit ce0704a

Browse files
committed
chore: handle alerts better (#49)
1 parent 24bd9c9 commit ce0704a

File tree

5 files changed

+56
-71
lines changed

5 files changed

+56
-71
lines changed

Assets/Rivet/Editor/UI/Tabs/DeployController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
@@ -102,11 +103,10 @@ private void OnBuildAndDeploy()
102103
string? serverPath = null;
103104
if (deployGameServer)
104105
{
105-
serverPath = Builder.BuildReleaseDedicatedServer();
106-
if (serverPath == null)
107-
{
108-
EditorUtility.DisplayDialog("Server Build Failed", "See Unity console for details.", "Dismiss");
109-
return;
106+
try {
107+
serverPath = Builder.BuildReleaseDedicatedServer();
108+
} catch (Exception e) {
109+
EditorUtility.DisplayDialog("Server Build Failed", e.Message, "Dismiss");
110110
}
111111
}
112112

Assets/Rivet/Editor/UI/Tabs/Develop.uxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<AttributeOverrides element-name="Label" text="Restart" />
2929
</ui:Instance>
3030
</ui:VisualElement>
31-
<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;" />
31+
<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;" />
3232
</ui:VisualElement>
3333
<ui:Instance template="Separator" name="Separator" />
3434
<ui:Instance template="Header" name="PlayerHeader">

Assets/Rivet/Editor/UI/Tabs/DevelopController.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Data.SqlClient;
34
using System.IO;
@@ -142,22 +143,24 @@ private void OnLocalGameServerStateChange(bool running)
142143

143144
private void OnLocalGameServerStart()
144145
{
145-
var serverPath = Builder.BuildDevDedicatedServer();
146-
if (serverPath != null)
147-
{
148-
_pluginWindow.LocalGameServerExecutablePath = serverPath;
149-
// _ = _pluginWindow.LocalGameServerManager.StartTask();
150-
_ = new RivetTask("show_term", new JObject
151-
{
152-
["command"] = _pluginWindow.LocalGameServerExecutablePath,
153-
// ["args"] = new JArray { "-batchmode", "-nographics", "-logFile", logPath, "-server" },
154-
["args"] = new JArray { "-batchmode", "-nographics", "-server" },
155-
}).RunAsync();
146+
string serverPath;
147+
try {
148+
serverPath = Builder.BuildDevDedicatedServer();
149+
} catch (Exception e) {
150+
EditorUtility.DisplayDialog("Server Build Failed", e.Message, "Dismiss");
151+
return;
156152
}
157-
else
153+
154+
_pluginWindow.LocalGameServerExecutablePath = serverPath;
155+
156+
// _ = _pluginWindow.LocalGameServerManager.StartTask();
157+
158+
_ = new RivetTask("show_term", new JObject
158159
{
159-
EditorUtility.DisplayDialog("Game Server Build Failed", "See Unity console for details.", "Dismiss");
160-
}
160+
["command"] = _pluginWindow.LocalGameServerExecutablePath,
161+
// ["args"] = new JArray { "-batchmode", "-nographics", "-logFile", logPath, "-server" },
162+
["args"] = new JArray { "-batchmode", "-nographics", "-server" },
163+
}).RunAsync();
161164
}
162165

163166
private void OnPlayerStart()

Assets/Rivet/Editor/UI/Tabs/Settings.uxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
<ui:Button text="Stop" parse-escape-sequences="true" display-tooltip-when-elided="true" name="StopButton" style="flex-shrink: 1; flex-grow: 1;" />
3030
<ui:Button text="Restart" parse-escape-sequences="true" display-tooltip-when-elided="true" name="RestartButton" style="flex-shrink: 1; flex-grow: 1;" />
3131
</ui:VisualElement>
32-
<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;" />
32+
<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;" />
3333
</ui:VisualElement>
3434
</ui:UXML>

Assets/Rivet/Editor/Util/Builder.cs

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ public static string GetUnityEditorPath()
2424
}
2525

2626
/// <summary>
27-
/// Builds a development player for the host OS.
27+
/// Build target for building for the current OS.
28+
///
29+
/// Used for player & dev server builds.
2830
/// </summary>
2931
/// <returns>Returns the path to the built player executable.</returns>
30-
public static BuildTarget GetPlayerBuildTarget()
32+
public static BuildTarget GetLocalBuildTarget()
3133
{
3234
switch (Application.platform)
3335
{
@@ -38,38 +40,33 @@ public static BuildTarget GetPlayerBuildTarget()
3840
case RuntimePlatform.LinuxEditor:
3941
return BuildTarget.StandaloneLinux64;
4042
default:
41-
Debug.LogError("Unsupported platform for player build");
43+
Debug.LogError("Unsupported platform for build");
4244
return BuildTarget.StandaloneWindows64; // Default to Windows as fallback
4345
}
4446
}
4547

46-
public static string? BuildDevPlayer()
48+
public static string BuildDevPlayer()
4749
{
4850
// Check if the target platform is supported
49-
if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, GetPlayerBuildTarget()))
51+
if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, GetLocalBuildTarget()))
5052
{
51-
RivetLogger.Error($"{GetPlayerBuildTarget()} build support is not installed");
52-
EditorUtility.DisplayDialog(
53-
$"{GetPlayerBuildTarget()} Build Support Missing",
54-
$"{GetPlayerBuildTarget()} build support is not installed. Please install it from the Unity Hub to proceed with the build process.",
55-
"Dismiss"
53+
throw new Exception(
54+
$"{GetLocalBuildTarget()} build support is not installed. Please install it from the Unity Hub to proceed with the build process."
5655
);
57-
return null;
5856
}
5957

6058
// Ensure a scene is included
6159
if (EditorBuildSettings.scenes.Length == 0)
6260
{
63-
RivetLogger.Error("No scenes in build settings. Please add at least one scene.");
64-
return null;
61+
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.");
6562
}
6663

6764
// Configure build settings
6865
var buildPlayerOptions = new BuildPlayerOptions
6966
{
7067
scenes = GetScenePaths(),
71-
locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "Player", GetPlatformArchFolder(GetPlayerBuildTarget()), GetBuildName("Player", GetPlayerBuildTarget())),
72-
target = GetPlayerBuildTarget(),
68+
locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "Player", GetPlatformArchFolder(GetLocalBuildTarget()), GetBuildName("Player", GetLocalBuildTarget())),
69+
target = GetLocalBuildTarget(),
7370
options = BuildOptions.Development | BuildOptions.AllowDebugging
7471
};
7572

@@ -85,8 +82,7 @@ public static BuildTarget GetPlayerBuildTarget()
8582
}
8683
else
8784
{
88-
Debug.LogError("Dev player build failed");
89-
return null;
85+
throw new Exception("Dev player build failed. Check console for errors.");
9086
}
9187
}
9288

@@ -96,10 +92,11 @@ public static BuildTarget GetPlayerBuildTarget()
9692
/// <param name="instanceCount">The number of player instances to run.</param>
9793
public static void BuildAndRunMultipleDevPlayers(int instanceCount)
9894
{
99-
string? playerPath = BuildDevPlayer();
100-
if (playerPath == null)
101-
{
102-
Debug.LogError("Failed to build dev player. Cannot run instances.");
95+
string playerPath;
96+
try {
97+
playerPath = BuildDevPlayer();
98+
} catch (Exception e) {
99+
EditorUtility.DisplayDialog("Player Build Failed", e.Message, "Dismiss");
103100
return;
104101
}
105102

@@ -129,43 +126,30 @@ public static void BuildAndRunMultipleDevPlayers(int instanceCount)
129126
}
130127

131128
// MARK: Run Game Server
132-
public static BuildTarget GetGameServerBuildTarget()
133-
{
134-
// TODO:
135-
return BuildTarget.StandaloneOSX;
136-
}
137-
138129
/// <summary>
139130
/// Builds a server used for local development.
140131
/// </summary>
141132
/// <returns>Returns the task config to run the server.</returns>
142-
public static string? BuildDevDedicatedServer()
133+
public static string BuildDevDedicatedServer()
143134
{
144135
// Check if the target platform is supported
145-
if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, GetGameServerBuildTarget()))
136+
if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, GetLocalBuildTarget()))
146137
{
147-
RivetLogger.Error($"{GetGameServerBuildTarget()} build support is not installed");
148-
EditorUtility.DisplayDialog(
149-
$"{GetGameServerBuildTarget()} Build Support Missing",
150-
$"{GetGameServerBuildTarget()} build support is not installed. Please install it from the Unity Hub to proceed with the build process.",
151-
"Dismiss"
152-
);
153-
return null;
138+
throw new Exception($"{GetLocalBuildTarget()} build support is not installed. Please install it from the Unity Hub to proceed with the build process.");
154139
}
155140

156141
// Ensure a scene is included
157142
if (EditorBuildSettings.scenes.Length == 0)
158143
{
159-
RivetLogger.Error("No scenes in build settings. Please add at least one scene.");
160-
return null;
144+
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.");
161145
}
162146

163147
// Configure build settings
164148
var buildPlayerOptions = new BuildPlayerOptions
165149
{
166150
scenes = GetScenePaths(),
167-
locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "DedicatedServer", GetPlatformArchFolder(GetGameServerBuildTarget()), GetBuildName("DedicatedServer", GetGameServerBuildTarget(), true)),
168-
target = GetGameServerBuildTarget(),
151+
locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "DedicatedServer", GetPlatformArchFolder(GetLocalBuildTarget()), GetBuildName("DedicatedServer", GetLocalBuildTarget(), true)),
152+
target = GetLocalBuildTarget(),
169153
options = BuildOptions.Development | BuildOptions.CompressWithLz4 | BuildOptions.EnableHeadlessMode,
170154
subtarget = (int)StandaloneBuildSubtarget.Server
171155
};
@@ -183,30 +167,27 @@ public static BuildTarget GetGameServerBuildTarget()
183167
}
184168
else
185169
{
186-
RivetLogger.Error("Dedicated server build failed.");
187-
return null;
170+
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.");
188171
}
189172
}
190173

191-
public static string? BuildReleaseDedicatedServer()
174+
public static string BuildReleaseDedicatedServer()
192175
{
193176
// Ensure a scene is included
194177
if (EditorBuildSettings.scenes.Length == 0)
195178
{
196-
RivetLogger.Error("No scenes in build settings. Please add at least one scene.");
197-
return null;
179+
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.");
198180
}
199181

200182
// Check if Linux build support is installed
201183
if (!BuildPipeline.IsBuildTargetSupported(BuildTargetGroup.Standalone, BuildTarget.StandaloneLinux64))
202184
{
203-
RivetLogger.Error("Linux build support is not installed");
204185
EditorUtility.DisplayDialog(
205186
"Linux Build Support Missing",
206187
"Linux build support is not installed. Please install it from the Unity Hub to proceed with the build and deploy process.",
207188
"Dismiss"
208189
);
209-
return null;
190+
throw new Exception("Linux build support is not installed");
210191
}
211192

212193
// Configure build settings
@@ -231,8 +212,7 @@ public static BuildTarget GetGameServerBuildTarget()
231212
}
232213
else
233214
{
234-
RivetLogger.Error("Production server build failed.");
235-
return null;
215+
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.");
236216
}
237217
}
238218

@@ -257,7 +237,7 @@ public static string FindServerExecutablePath(string serverPath, BuildTarget bui
257237
break;
258238
case BuildTarget.StandaloneWindows:
259239
case BuildTarget.StandaloneWindows64:
260-
executableFile = Path.Combine(serverPath, $"{productName}.exe");
240+
executableFile = serverPath;
261241
break;
262242
default:
263243
throw new ArgumentException($"Unsupported build target: {buildTarget}");
@@ -312,6 +292,8 @@ public static string GetBuildName(string baseName, BuildTarget target, bool isSe
312292
if (target == BuildTarget.StandaloneOSX && !isServer)
313293
{
314294
return baseName + ".app";
295+
} else if (target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64) {
296+
return baseName + ".exe";
315297
}
316298
return baseName;
317299
}

0 commit comments

Comments
 (0)