1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Runtime . InteropServices ;
6
+ using System . Diagnostics ;
7
+
8
+ namespace FbxExporters
9
+ {
10
+ class Program
11
+ {
12
+
13
+ [ DllImport ( "USER32.DLL" , CharSet = CharSet . Unicode ) ]
14
+ public static extern IntPtr FindWindow ( String lpClassName , String lpWindowName ) ;
15
+
16
+ [ DllImport ( "USER32.DLL" ) ]
17
+ public static extern bool SetForegroundWindow ( IntPtr hWnd ) ;
18
+ [ DllImport ( "User32.dll" ) ]
19
+ private static extern bool IsIconic ( IntPtr handle ) ;
20
+ [ DllImport ( "User32.dll" ) ]
21
+ private static extern bool ShowWindow ( IntPtr handle , int nCmdShow ) ;
22
+ const int SW_RESTORE = 9 ;
23
+ public static void bringToFront ( string title )
24
+ {
25
+ // Get a handle to the application.
26
+ IntPtr handle = FindWindow ( null , title ) ;
27
+
28
+ // Verify that this is a running process.
29
+ if ( handle == IntPtr . Zero )
30
+ {
31
+ return ;
32
+ }
33
+ if ( IsIconic ( handle ) )
34
+ {
35
+ ShowWindow ( handle , SW_RESTORE ) ;
36
+ }
37
+
38
+ SetForegroundWindow ( handle ) ;
39
+ }
40
+
41
+ static void Main ( string [ ] args )
42
+ {
43
+ Process [ ] processlist = Process . GetProcessesByName ( "Unity" ) ;
44
+
45
+ bool found = false ;
46
+ foreach ( Process process in processlist )
47
+ {
48
+ if ( ! String . IsNullOrEmpty ( process . MainWindowTitle ) )
49
+ {
50
+ bringToFront ( process . MainWindowTitle ) ;
51
+ found = true ;
52
+ }
53
+ }
54
+
55
+ if ( ! found ) {
56
+ Process myProcess = new Process ( ) ;
57
+ myProcess . StartInfo . FileName = args [ 0 ] ;
58
+ if ( args . Length > 1 ) {
59
+ myProcess . StartInfo . Arguments = args [ 1 ] ;
60
+ }
61
+ myProcess . Start ( ) ;
62
+ }
63
+ }
64
+ }
65
+ }
0 commit comments