.net./C#/UE4: UE4 製ã®ã¢ããªã C# ããèµ·åãããçµäºãããããããå ´åã®ã¡ã¢ããããã¯éãã¦ãéãã¦ã殺ãã¦ãæ»ãªãªãã¢ããªã殺ãã¡ã¢ã
// Process using System.Diagnostics;
// C# ã¢ããªãã UE4 製ã®ã¢ããªï¼ã«éããï¼ãèµ·åãã¦ããã»ã¹ããã³ãã«ãã var p = Process.Start( "your-executable-path.exe" );
// æ¢ã«åä½ãã¦ãã UE4 製ã®ã¢ããªï¼ã«éããï¼ãæ¢ãã¦ããã»ã¹ããã³ãã«ãã // note: hoge.uproject ã§ä½ã£ã hoge.exe ãªã hoge ã§æ¢ããã var ps = Process.GetProcessesByName( "your-ue4-project-name" ); if ( ps.Length > 0 ) var p = ps.First();
// ãã³ãã«ãã¦ãã UE4 製ã®ã¢ããªï¼ã«éããï¼ã®ããã»ã¹ã殺ãï¼ã¤ããã ãæ»ãªãªãï¼ p.Close(); // <-- æ®å¿µã§ãããæ»ã«ã¾ããã // ã¡ã¤ã³ã¦ã£ã³ãã¦ã殺ãï¼ã¤ããã ãæ»ãªãªãï¼ p.CloseMainWindow(); // <-- æ®å¿µã§ãããæ»ã«ã¾ããã // ãåãâ¦æ®ºãï¼ã¤ããã ãæ»ãªãªãï¼ p.Kill(); // <-- æ®å¿µã§ãããæ»ã«ã¾ããã
å®ã¯æ»ãã§ããã®ã ãæ»ãã§ããªããUE4製ã®ã¢ããªã¯å
æ°ã«ä½äºãç¡ãåä½ãã¦ããä¸ã«ã GetProcessByName
ã«çºè¦ãããªãã¹ãã«ã¹ç¶æ
ã«ãªã£ã¦ããâ¦ãã®ãããªæåã観測ãããããã«ãªãã
ãã㧠UE4 製ã®ã¢ããªã®ããã»ã¹ãã©ããªã£ã¦ããã®ã Process Monitor ã¨ãããããä½ãã§ããã»ã¹ããªã¼ã確èªããããï¼Windows ã® PowerShell
ã§ã ps
ãã¨ã¤ãªã¢ã¹ã¨ãã¦åä½ããããã ãã©ãããªã¼è¡¨ç¤ºã¯ã§ããªããããã WSL
ããã§ã¯ Windows ã®ããã»ã¹ã¯è¦ããªãããä¸ä¾¿ããã®ã
â¦ð
ï¼
ä»å㯠G5
ã¨ãã UE4 製ã®ã¢ããªã§ãã UE4 ã®ããã±ã¼ã¸æ©è½ã使ã Windows åãã«ãããã¯ããåºåããã¨ãåºåãã£ã¬ã¯ããªã¼ç´ä¸ã« <project-name>.exe
ãçæãããä¸è¬çã«ã¯é
å¸å
ã®ã¦ã¼ã¶ã¼ã¯ãããèµ·åãã¦ã¢ããªã使ãã¾ãã
ããããå®éã«ã¯ãã®åºåãã£ã¬ã¯ããªã¼ç´ä¸ã® <project-name>.exe
㯠Binaries/Win64/<project-name>-Win64-Shipping.exe
ãªã©ãåããã»ã¹ã¨ãã¦èµ·åãããäºã§ UE4 製ã®ã¢ããªã®"æ¬ä½"ï¼ã¨ããã"å®ä½"ï¼ãéæ¥çã«èµ·åãããããã»ã¹ã®ã©ããã¼ãã ãã C# ã®å®è£
㧠<project-name>
ã§èµ·åãããæ¢ãããããããã»ã¹ã Close
ãã¦ã CloseMainWindow
ãã¦ã Kill
ãã¦ãã¦ã¼ã¶ã¼ã®ç®ã«æ ãåä½ä¸ã® UE4 製ã®ã¢ããªã® "æ¬ä½" ã¯æ»ãªãã«åä½ãç¶ãã¾ããããã»ã¹åãå°¾ã³ããä»ãã¦ãã¦ç°ãªããããç®ã«è¦ãã UE4 製ã®ã¢ããªã¯åãç¶ãã¦ããã®ã« GetProcessesByName
ã§æ¢ããªãä¸è¦ããã¨è¬ã®ã¹ãã«ã¹ç¶æ
ã®ããã«è¦³æ¸¬ãããããã«ãªãã¾ãã
// UE4 製ã®ã¢ããªãèµ·åãã¦ããã»ã¹ããã³ãã« var p = Process.Start( "your-executable-path.exe" ); // ã¶ã¡æ®ºã using ( var killer = new Process() ) { killer.StartInfo.FileName = System.IO.Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.System ), "taskkill.exe" ); killer.StartInfo.Arguments = string.Format( "/PID {0} /T /F", p.Id ); killer.StartInfo.CreateNoWindow = true; killer.StartInfo.UseShellExecute = false; killer.Start(); killer.WaitForExit(); } // â ref. https://qiita.com/yohhoy/items/b6e32e17c9d568f927d8 // @yohhoy ãããããã¨ãâ¥ï¼2014å¹´ã®è¨äºãªã®ã§ææ°ã®ãã«ãã«ãã¤ã¯ãã½ããAPIã§ã¯ãããªãã¨ããªãã¦æ¸ãã®ãç¥ãããã©ãï¼
çç´ã«è¨ã£ã¦ã¦ã±ã«â¦ç¬ã£ã¦ããã¨æãã¾ããã§ãã Windows ã£ã¦ãã¾ã«ãã¼ãã¼ãã¨ããæ¹ã楽ã ã£ããé«éã ã£ããã£ã¦äºããã®ããâ¦ãä¾ãã°çé¢ç®ã« WMI ã使ãããã³ãã³ãå¼ãã§æååã®çµæããã¼ã¹ããæ¹ãæ©ãã£ããéãã£ããããªãã¦ãã¨ããã£ãã
UE4 ã¢ããªã®å ´åã¯åããã»ã¹ã§èµ·åãããäºã«æ°ã¥ãã¦ãã¾ãã°åããã»ã¹ã確å®ããæ¹æ³ã¯ããã¡ãã£ã¨ä¸å¯§ã ã£ããããããã¯ãã¡ã¤ã«ããæ³¥èãæ¾ã£ã¦ããã«ãã Close
ãå¼ãã§ãããäºãã§ããããã©ãæ±ç¨æ§ãããã®ã§ããã°ã«ãã®æ¹æ³ãã¡ã¢ãã¦ããäºã«ãã¾ããã
ããããçµäºã«éããå¥ããã»ã¹ããã«ããã«ãããããªãé©å½ãªããã»ã¹ééä¿¡ã®æ段ãç¨æããæ¹ããããã©ãð