Unity에서 Windows Build에서 매개변수를 가져오는 방법

5119 단어 WindowsUnity

Unity에서 Windows Build에서 매개변수를 가져오는 방법


필요에 부닥쳐서 녹음을 잊어버렸어요.
using UnityEngine;
using System;

public class Init{

    [RuntimeInitializeOnLoadMethod]
    static void OnRuntimeMethodLoad()
    {
        string[] cmds = System.Environment.GetCommandLineArgs();
    }
}

이렇게 하면 cmds에 파라미터가 있어요.
(cmds[0]는 명령 자체를 포함합니다)

응용 프로그램

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;

public class Init :MonoBehaviour{

    static List<String> s = new List<string>();


    [RuntimeInitializeOnLoadMethod]
    static void OnRuntimeMethodLoad()
    {
        string[] cmds = System.Environment.GetCommandLineArgs();

        foreach(string cmd in cmds)
        {
            s.Add((cmd));
        }
    }

    private void Start()
    {
        Text t = GetComponent<Text>();
        if(t != null)
        {
            t.text = "";
            for(int i = 0; i < s.Count; i ++)
            {
                t.text += " " +s[i];
            }
        }
    }
}
Text가 있는 UI를 적당히 만들어서 붙여서 Exe를 만들어요.
생성된 Exe 파일의 바로 가기를 만들고 바로 가기 속성에 링크 대상에 매개변수를 추가합니다.

하면, 만약, 만약...

파라미터를 뺐습니다.

좋은 웹페이지 즐겨찾기