Created
July 1, 2020 08:16
-
-
Save inertiave/1b353beef1b4066dce55895810aa3890 to your computer and use it in GitHub Desktop.
유니티 명령줄 인수(command line arguments) 사용을 위한 부트스트랩
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using UnityEngine; | |
using UnityEngine.UI; | |
using Application = UnityEngine.Application; | |
public class Bootstrap : MonoBehaviour | |
{ | |
public Text text; | |
public int estimatedArgsCount = 5; | |
const string errorMsg = | |
"You are trying to open the MyGame client in an invalid way. To successfully open the game client, click on the Play button and join a queue or create a custom game."; | |
void Start() | |
{ | |
string[] args = Environment.GetCommandLineArgs(); | |
if (estimatedArgsCount != args.Length) | |
{ | |
MsgBox.Show(errorMsg, "My Game Name", MsgBox.EMessageBoxButton.MB_OK); | |
Application.Quit(300); | |
return; | |
} | |
// implementation | |
var sb = new StringBuilder(); | |
foreach (string arg in args) | |
{ | |
sb.AppendLine($"{arg}"); | |
} | |
text.text = sb.ToString(); | |
} | |
} | |
public class MsgBox | |
{ | |
public enum EMessageBoxButton : uint | |
{ | |
MB_ABORTRETRYIGNORE = (uint) (0x00000002L | 0x00000010L), | |
MB_CANCELTRYCONTINUE = (uint) (0x00000006L | 0x00000030L), | |
MB_HELP = (uint) (0x00004000L | 0x00000040L), | |
MB_OK = (uint) (0x00000000L | 0x00000040L), | |
MB_OKCANCEL = (uint) (0x00000001L | 0x00000040L), | |
MB_RETRYCANCEL = (uint) 0x00000005L, | |
MB_YESNO = (uint) (0x00000004L | 0x00000040L), | |
MB_YESNOCANCEL = (uint) (0x00000003L | 0x00000040L), | |
} | |
[DllImport("user32.dll")] | |
private static extern System.IntPtr GetActiveWindow(); | |
[DllImport("user32.dll", SetLastError = true)] | |
static extern int MessageBox(IntPtr hwnd, String lpText, String lpCaption, uint uType); | |
public static System.IntPtr GetWindowHandle() | |
{ | |
return GetActiveWindow(); | |
} | |
public static void Show(string text, string caption, EMessageBoxButton type) | |
{ | |
try | |
{ | |
switch (type) | |
{ | |
case EMessageBoxButton.MB_ABORTRETRYIGNORE: | |
case EMessageBoxButton.MB_CANCELTRYCONTINUE: | |
case EMessageBoxButton.MB_HELP: | |
case EMessageBoxButton.MB_OK: | |
case EMessageBoxButton.MB_OKCANCEL: | |
case EMessageBoxButton.MB_RETRYCANCEL: | |
case EMessageBoxButton.MB_YESNO: | |
case EMessageBoxButton.MB_YESNOCANCEL: | |
MessageBox(GetWindowHandle(), text, caption, (uint) type); | |
break; | |
default: | |
MessageBox(GetWindowHandle(), text, caption, (uint) (0x00000000L | 0x00000010L)); | |
break; | |
} | |
} | |
catch | |
{ | |
// ignored | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment