unity 在pc平台 重启应用程序

void ReStart()

    {

//延迟5秒启动

        string[] strs = new string[]
         {
            "@echo off",
            "echo wscript.sleep 5000 > sleep.vbs",
            "start /wait sleep.vbs",
            "start /d \"{0}\" {1}",
            "del /f /s /q sleep.vbs",
            "exit"
         };
        string path = Application.dataPath + "/../";


        List prefabs = new List();
        prefabs = new List(Directory.GetFiles(Application.dataPath + "/../", "*.exe", SearchOption.AllDirectories));
        foreach (string keyx in prefabs)
        {
            string _path = Application.dataPath;
            _path = _path.Remove(_path.LastIndexOf("/"))+"/";
            Debug.LogError(_path);
            string _name = Path.GetFileName(keyx);
            strs[3] = string.Format(strs[3], _path,_name);
            Application.OpenURL(path);
        }


      
        string batPath = Application.dataPath + "/../restart.bat";
        if (File.Exists(batPath))
        {
            File.Delete(batPath);
        }
        using (FileStream fileStream = File.OpenWrite(batPath))
        {
            using (StreamWriter writer = new StreamWriter(fileStream,System.Text.Encoding.GetEncoding("UTF-8")))
            {
                foreach (string s in strs)
                {
                    writer.WriteLine(s);
                }
                writer.Close();
            }
        }
        Application.Quit();
        Application.OpenURL(batPath);
        
    }

你可能感兴趣的:(Unity3D,unity,应用,pc)