近日接到一个新任务,大概意思是把好多exe文件组合到一起,然后可以随意在此场景进入某个exe程序,退出的时候再回到这个场景,说实话这个要求真是策划突发奇想!怎莫会有这种要求?一开始为神魔不做到一个工程下?原因很简单,太大了。。。。。不过,有幸来这里的同志们我已经给你们铺好路了!!!!!(我的主程序是<开始.exe>,化工.exe与中医.exe都在StreamingAssets目录下)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
public class TotalManager : MonoBehaviour {
//课程字符串集合
List<string> _process = new List<string>();
public GameObject totalProcess;
//获取htc手柄按键
SteamVR_Controller.Device devicedemo;
//获取htc手柄
SteamVR_TrackedObject trackobject;
//定义一个加载路径(化工与中医的)
private string path;
public bool stop;
// Use this for initialization
void Start () {
trackobject = transform.GetComponent<SteamVR_TrackedObject>();
//便历压到集合中来
for (int i = 0; i < totalProcess.transform.childCount; i++)
{
_process.Add(totalProcess.transform.GetChild(i).name);
}
}
// Update is called once per frame
void Update () {
devicedemo = SteamVR_Controller.Input((int)trackobject.index);
}
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("touch"))
{
//当按下圆盘键 跟要选的课相碰
if (devicedemo.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
{
if (_process.Contains(other.transform.name))
{
print("aaaa");
//所有计算机内活着的进程(每一个exe都是一个进程)
Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
{
try
{
//只执行一遍(不加bool 有可能卡死)
if (stop ==false)
{
// 打开streamingAssets下的exe
Process.Start(Application.streamingAssetsPath+"/"+ other.gameObject.name);
stop = true;
}
if (!process.HasExited)
{
//关闭主程序(貌似可以不管。。)
if (process.ProcessName == "开始")
{
process.Kill();
UnityEngine.Debug.Log("已杀死进程");
}
}
}
catch (System.InvalidOperationException ex)
{
UnityEngine.Debug.Log(ex);
}
}
}
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
using System;
using UnityEngine.UI;
public class Back_huangong : MonoBehaviour
{
public Text obj;
SteamVR_Controller.Device devicedemo;
SteamVR_TrackedObject trackobject;
public bool stop;
private string totalpath;
private string currentpath;
// Use this for initialization
void Start()
{
trackobject = transform.GetComponent<SteamVR_TrackedObject>();
}
// Update is called once per frame
void Update()
{
devicedemo = SteamVR_Controller.Input((int)trackobject.index);
}
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("touch"))
{
if (devicedemo.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
{
//streamAssets总路径
totalpath = Application.streamingAssetsPath;
string[] strArr = totalpath.Split(new char[] { '开' });
//开始路径也就是主程序(这个最重要)
currentpath = strArr[0] + "开始";
if (other.gameObject.name == "开始")
{
obj.text = "化工回城";
Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
{
try
{
if (stop == false)
{
Process.Start(currentpath);
stop = true;
obj.text = "化工回城lelel";
}
if (!process.HasExited)
{
if (process.ProcessName == "化工")
{
process.Kill();
UnityEngine.Debug.Log("已杀死进程");
}
}
}
catch (System.InvalidOperationException ex)
{
UnityEngine.Debug.Log(ex);
}
}
}
}
}
}
}