@@ -105,14 +105,15 @@ func runLaunchWithDeps(ctx context.Context, options launchOptions, startPath str
105105 if ! deleteLaunchRecoveryIfRequested (options , projectRoot , stderr ) {
106106 return 1
107107 }
108+ v2Project , _ := detectV2DispatcherProject (projectRoot )
108109
109110 runningProcess , handled , code := findLaunchRunningProcess (ctx , options , projectRoot , stdout , stderr , deps )
110111 if handled {
111112 return code
112113 }
113114
114115 if runningProcess != nil {
115- if handled , code := handleExistingLaunchProcess (ctx , options , projectRoot , runningProcess , stdout , stderr , deps ); handled {
116+ if handled , code := handleExistingLaunchProcess (ctx , options , projectRoot , runningProcess , v2Project . IsV2 , stdout , stderr , deps ); handled {
116117 return code
117118 }
118119 }
@@ -121,7 +122,7 @@ func runLaunchWithDeps(ctx context.Context, options launchOptions, startPath str
121122 return writeLaunchQuitResponse (stdout , stderr , projectRoot , nil , launchNoProcessMessage )
122123 }
123124
124- return startUnityAndWaitForReadiness (ctx , options , projectRoot , runningProcess , stdout , stderr , deps )
125+ return startUnityAndWaitForReadiness (ctx , options , projectRoot , runningProcess , v2Project . IsV2 , stdout , stderr , deps )
125126}
126127
127128func writeLaunchProjectSearch (stdout io.Writer , options launchOptions , startPath string ) {
@@ -173,6 +174,7 @@ func handleExistingLaunchProcess(
173174 options launchOptions ,
174175 projectRoot string ,
175176 runningProcess * unityprocess.UnityProcess ,
177+ isV2 bool ,
176178 stdout io.Writer ,
177179 stderr io.Writer ,
178180 deps launchDeps ,
@@ -182,6 +184,9 @@ func handleExistingLaunchProcess(
182184 clierrors .WriteClassifiedError (stderr , launchEditorVersionRequiresRestartError (options .editorVersion ), clierrors.ErrorContext {ProjectRoot : projectRoot , Command : clicore .LaunchCommandName })
183185 return true , 1
184186 }
187+ if isV2 {
188+ return true , writeExistingV2LaunchOpenedResponse (stdout , stderr , projectRoot , runningProcess .Pid )
189+ }
185190 return true , waitForExistingLaunchReadiness (ctx , projectRoot , runningProcess .Pid , stdout , stderr , deps )
186191 }
187192 if err := deps .killUnityProcess (runningProcess .Pid ); err != nil {
@@ -228,6 +233,7 @@ func startUnityAndWaitForReadiness(
228233 options launchOptions ,
229234 projectRoot string ,
230235 runningProcess * unityprocess.UnityProcess ,
236+ isV2 bool ,
231237 stdout io.Writer ,
232238 stderr io.Writer ,
233239 deps launchDeps ,
@@ -265,6 +271,7 @@ func startUnityAndWaitForReadiness(
265271 clicore .WriteFormat (stdout , "Detected Unity version: %s\n " , unityVersion )
266272 clicore .WriteLine (stdout , "Unity Hub launch options: none" )
267273
274+ launchStartedAt := deps .now ()
268275 command := newUnityLaunchCommand (unityPath , buildUnityLaunchArgs (projectRoot , options ))
269276 if err := command .Start (); err != nil {
270277 clierrors .WriteClassifiedError (stderr , err , clierrors.ErrorContext {ProjectRoot : projectRoot , Command : clicore .LaunchCommandName })
@@ -275,6 +282,9 @@ func startUnityAndWaitForReadiness(
275282 clierrors .WriteClassifiedError (stderr , err , clierrors.ErrorContext {ProjectRoot : projectRoot , Command : clicore .LaunchCommandName })
276283 return 1
277284 }
285+ if isV2 {
286+ return waitForV2ProjectOpened (ctx , projectRoot , runningProcess , currentPid , stdout , stderr , launchStartedAt , deps )
287+ }
278288 if err := deps .waitForUnityStartupMarker (ctx , unityLockfilePath (projectRoot ), launchLockfilePoll , launchLockfileTimeout ); err != nil {
279289 clierrors .WriteClassifiedError (stderr , err , clierrors.ErrorContext {ProjectRoot : projectRoot , Command : clicore .LaunchCommandName })
280290 return 1
@@ -432,38 +442,6 @@ func unityExecutableCandidates(version string) []string {
432442 }
433443}
434444
435- func windowsUnityExecutableCandidates (version string ) []string {
436- candidates := []string {}
437- for _ , base := range []string {
438- os .Getenv ("ProgramFiles" ),
439- os .Getenv ("ProgramFiles(x86)" ),
440- os .Getenv ("LOCALAPPDATA" ),
441- `C:\Program Files` ,
442- } {
443- if base == "" {
444- continue
445- }
446- candidates = append (candidates , filepath .Join (base , "Unity" , "Hub" , "Editor" , version , "Editor" , "Unity.exe" ))
447- }
448- return candidates
449- }
450-
451- func readUnityEditorVersion (projectRoot string ) (string , error ) {
452- content , err := os .ReadFile (filepath .Join (projectRoot , projectVersionFilePath ))
453- if err != nil {
454- return "" , err
455- }
456- matches := editorVersionPattern .FindStringSubmatch (string (content ))
457- if len (matches ) != 2 {
458- return "" , fmt .Errorf ("unity editor version not found in %s" , projectVersionFilePath )
459- }
460- version := strings .TrimSpace (matches [1 ])
461- if version == "" {
462- return "" , fmt .Errorf ("unity editor version is empty in %s" , projectVersionFilePath )
463- }
464- return version , nil
465- }
466-
467445func killUnityProcess (pid int ) error {
468446 process , err := os .FindProcess (pid )
469447 if err != nil {
0 commit comments