unity3D打开其他软件客户端并传送参数

被打开端:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.IO;
using System;

public class OpenGameobject : MonoBehaviour {
    WWW loadscene;
    AsyncOperation ao;
    public Slider jindutiao;//加载进度条
    uint nowprocess = 0;
    public static AssetBundle abcde;//本地全局bundle文件

    string CommandLine;
    string[] CommandLineArgs;
    int num;
    string[] arr;
    public Text tip;
    bool load = false;
    //Playvideo pv;
    private void Start()
    {
        Screen.SetResolution(1024,768,false);
        CommandLine = Environment.CommandLine;
        CommandLineArgs = Environment.GetCommandLineArgs();
        if (CommandLineArgs.Length <10)
        {
            Debug.Log(CommandLineArgs.Length.ToString());
            Debug.Log(CommandLineArgs[0]);
            arr = CommandLineArgs[1].Split('=');
            if (arr.Length >= 2)
            {
                num = int.Parse(arr[1]);
                load = true;
            }
            tip.text = CommandLineArgs[1]+"***"+num;
            
         
            // Application.Quit();
        }
        else
        {
            if (CommandLineArgs[1] == "")
            {

            }
            else
            {
                Debug.Log("启动失败:" + CommandLineArgs[1] + "");
                tip.text = "启动失败:" + CommandLineArgs[1] + "";
                // Application.Quit();
            }
        }
       
    }
    void OnLoadScene(int index)
    {
     
      
            if (abcde != null)
            {
                abcde.Unload(false);
            }
            StartCoroutine(LoadScene(Application.dataPath, index.ToString()));
      
    }
    // Update is called once per frame
    void Update () {
        if (arr.Length >= 2&&load)
        {
            OnLoadScene(num);
            load = false;
        }
        if (loadscene != null && jindutiao != null && !loadscene.isDone)
        {
        //    jztell.text = "场景在加载中,请等候……";
           jindutiao.value = loadscene.progress;
       //    jzbl.text = (int)(jindutiao.value * 100) + "%";

        }
        if (loadscene != null && loadscene.isDone && ao != null && !ao.isDone)
        {
        //    //jindutiao.gameObject.SetActive(true);
        //    jztell.text = "场景正在初始化,请等待……";
            uint toProcess;
            if (ao.progress < 0.9f)
            {
                toProcess = (uint)(ao.progress * 100);
                //jzbl.text = (int)(ao.progress * 100) + "%";

            }
           else
           {
            toProcess = 100;
           }
           if (nowprocess < toProcess)
            {
                nowprocess++;
            }
            jindutiao.value = nowprocess / 100f;
        //    jzbl.text = (int)(jindutiao.value * 100) + "%";

        }
        if (nowprocess == 100)
        {
            ao.allowSceneActivation = true;
            jindutiao.gameObject.SetActive(false);
        //    jzbl.text = "";
        //    jztell.text = "";
            nowprocess = 0;
            ao = null;
        }
    }


    

    IEnumerator DownloadScene(string url, string name2)
    {
        WWW ws = new WWW(url);
        yield return ws;
        if (ws.error != null)
        {
            Debug.Log(ws.error);
        }
        else
        {
            if (ws.isDone)
            {
                byte[] scenebyte = ws.bytes;
                int length222 = scenebyte.Length;
                CreatPCFile(Application.dataPath, name2, scenebyte, length222);
            }
        }

    }
    void CreatPCFile(string paths, string name1, byte[] info, int length)
    {
        Stream st;
        FileInfo t = new FileInfo(paths + "/" + name1 + ".unity3d");
        if (!t.Exists)
        {
            st = t.Create();
        }
        else
        {
            return;
        }
        st.Write(info, 0, length);
        st.Close();
        st.Dispose();

    }
   IEnumerator LoadScene(string pathp, string name3)
    {
        string s = null;
#if UNITY_STANDALONE_WIN||UNITY_EDITOR
        s = "file:///" + pathp + "/" + name3 + ".unity3d";
#elif UNITY_IPHONE
        s=pathp+"/"+name3+".unity3d";
#elif UNITY_ANDROID
        s="jar:file:///"+pathp+"/"+name3+".unity3d";
#endif
        FileInfo tt = new FileInfo(pathp + "/" + name3 + ".unity3d");
        if (!tt.Exists)
        {
            Debug.Log("该文件不存在");
        }
        else
        {
            loadscene =WWW.LoadFromCacheOrDownload(s,18);
            yield return loadscene;
            if (loadscene.error != null)
            {
                Debug.Log(loadscene.error);
            }
            else
            {
                if (loadscene.isDone)
                {
                    //jindutiao.value = 0;
                    abcde = loadscene.assetBundle;
                    StartCoroutine(LD(name3));
                    
                }

            }
        }

    }
    IEnumerator LD(string name6)
    {
        ao = SceneManager.LoadSceneAsync(name6);
        ao.allowSceneActivation = false;
        yield return ao;
    }

}
 

 

打开端(测试时用到了6个场景,所以到最后一个场景后再打开的是第一个):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Diagnostics;
using UnityEngine.UI;
public class OpenDaiCan : MonoBehaviour {
    int index = 0;
    public Button btn;
    Process process;
    string arg = "sc=";
    // Use this for initialization
    void Start () {
        btn.onClick.AddListener(OnclickEvent);
    }
    void OnclickEvent()
    {
        ProcessStartInfo info = new ProcessStartInfo();
        info.FileName = "C:/Users/YF/Desktop/ARUseVr/test.exe";//文件名还是原名,不用带快捷方式四个字
        info.WorkingDirectory = "C:/Users/YF/Desktop/ARUseVr";//运行文件夹
       
        info.Arguments = arg+index;//赋值的参数
        info.UseShellExecute = true;
        UnityEngine.Debug.Log(info.Arguments);
        UnityEngine.Debug.Log(index);
        //process = Process.Start("C:/Users/YF/Desktop/ARUseVr/test.exe", arg + index);//这个可行
        index++;
        if(index>5)
        {
            index = 0;
        }
       process = Process.Start(info);
       
    }

}
 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值