Unity 双开脚本

  • Unity调用本地shell
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = "/bin/sh";
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = true;
        psi.Arguments = Application.dataPath + "/test.sh" + " arg1 arg2";

        Process p = Process.Start(psi); 
        string strOutput = p.StandardOutput.ReadToEnd(); 
        p.WaitForExit(); 
        UnityEngine.Debug.Log(strOutput);
  • 双开命令
  open -n /Users/zcw/Desktop/Unity560f3.app
保存成脚本double_open.sh

替换arguments,文件double_open.sh 路径的字符串

  • 完整例子
using System;
using System.Diagnostics;


namespace DelegateDemo
{
    public delegate void GreetingDelegate(string name);

    class Program
    {

        private static void EnglishGreeting(string name)
        {
            Console.WriteLine("Good Morning, " + name);
        }

        private static void ChineseGreeting(string name)
        {
            Console.WriteLine("早上好, " + name);
        }

        private static void GreetPeople(string name, GreetingDelegate MakeGreeting)
        {
            MakeGreeting(name);
        }
        static void Main(string[] args)
        {
            GreetingDelegate delegate1;
            delegate1 = EnglishGreeting;
            delegate1 += ChineseGreeting;
            GreetPeople("Liker", delegate1);
            Console.ReadLine();

            ProcessStartInfo psi = new ProcessStartInfo();

            psi.FileName = "/bin/sh";
            psi.UseShellExecute = false;
            psi.RedirectStandardOutput = true;
            psi.Arguments = "/Users/zcw/dev/double_open.sh";
            Process p = Process.Start(psi);
            string strOutput = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            Console.WriteLine(strOutput);
        }
    }
}

你可能感兴趣的:(Unity 双开脚本)