@@ -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