런쳐 만들어서 외부 프로세스 실행
public class ScProcessStarter : MonoBehaviour
{
[System.Runtime.InteropServices.DllImport("User32", EntryPoint = "FindWindow")]
private static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void SetForegroundWindow(System.IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool ShowWindow(System.IntPtr hWnd, int nCmdShow);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool ShowWindowAsync(System.IntPtr hWnd, int nCmdShow);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern System.IntPtr GetActiveWindow();
private System.IntPtr iMyIntPtr;
private void Awake()
{
iMyIntPtr = GetActiveWindow();
// 나의(런쳐) 핸들 얻어오기
}
public void Play_Casual_CPR()
{
ShowWindow(iMyIntPtr, 2);
// 2는 [SW_SHOWMINIMIZED]
// 창을 활성화하고 최소화된 창으로 표시합니다.
System.Diagnostics.ProcessStartInfo _psi = new System.Diagnostics.ProcessStartInfo();
_psi.FileName = System.IO.Directory.GetCurrentDirectory() + "\\외부콘텐츠\\콘텐츠.exe";
_psi.Arguments = "/AUTH_PASS";
System.Diagnostics.Process _p = System.Diagnostics.Process.Start(_psi);
_p.EnableRaisingEvents = true;
_p.Exited += _p_Exited;
}
private void _p_Exited(object sender, System.EventArgs e)
{
ShowWindow(iMyIntPtr, 1);
// 1은 [SW_SHOWNORMAL]
// 창을 활성화하고 표시합니다.
// 창이 최소화되거나 최대화되면 시스템은 창을 원래 크기와 위치로 복원합니다.
// 처음으로 창을 표시할 때 애플리케이션에서 이 플래그를 지정해야 합니다.
}
}
외부 프로세스에서 인수 받아서 처리하기
public class ScProcessParamReader : MonoBehaviour
{
string[] arguments;
private void Awake()
{
arguments = System.Environment.GetCommandLineArgs();
}
private IEnumerator Start()
{
yield return new WaitForSeconds(1.0f);
if (arguments.Length <= 1)
{
// 인수값이 1이면 아무런 인수를 받지 않았다는 뜻.
yield break;
}
else
{
string _strParam = arguments[1].ToString();
if (_strParam.Contains("/AUTH_PASS") == false) // /AUTH_PASS 라는 인자를 받지 않았다면? 종료한다.
{
Application.Quit();
}
}
}
}
'Programming > Unity 3D' 카테고리의 다른 글
Serial to Keyboard (Win, C#, Unity3D) (0) | 2023.08.25 |
---|---|
SteamVR Error - "No pose action set for this component" (0) | 2020.05.11 |
Unity에서 쓸만한 user32.dll 와드 (0) | 2020.04.08 |
Vive Controller Binding 검은화면 띄우는 문제... (1) | 2018.12.11 |
스크립트템플릿 변경 (0) | 2014.08.25 |