u3d 怎么调用windsform程序
答案:1 悬赏:80 手机版
解决时间 2021-04-02 16:20
- 提问者网友:容嬷嬷拿针来
- 2021-04-01 23:01
u3d 怎么调用windsform程序
最佳答案
- 五星知识达人网友:末日狂欢
- 2021-04-02 00:19
using UnityEngine;
using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
#if UNITY_STANDALONE_WIN
public class CallExeModule : MonoBehaviour
{
Process myProcess;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnGUI()
{
if (GUI.Button(new Rect(20, 20, 100, 45), "TestPrinter"))
{
OpenAProgress(Application.dataPath + "/StreamingAssets/PosPrinter.exe");
}
}
void OpenAProgress(string filepath)
{
try
{
if (myProcess != null)
{
myProcess.Close();
myProcess.Dispose();
}
myProcess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(filepath, StringToBase64(MakeBill()));
myProcess.StartInfo = startInfo;
myProcess.StartInfo.UseShellExecute = false;
myProcess.Start();
}
catch (Exception ex)
{
Debuger.Log("出错原因:" + ex.Message);
}
}
string MakeBill()
{
StringBuilder cache = new StringBuilder();
cache.AppendLine("------------------------------------------------------------- ");
cache.AppendLine("消费日期:2016-06-03");
cache.AppendLine("单号:0020002 桌号 :20");
cache.AppendLine("服务员:02 餐段:全天");
cache.AppendLine("名称 数量 价格 小计");
cache.AppendLine("------------------------------------------------------------- ");
cache.AppendLine("鸡翅 1份 34 34");
cache.AppendLine("牛肉 1份 34 34");
cache.AppendLine("肥肠 1份 34 34");
cache.AppendLine("鲜虾 1份 34 34");
cache.AppendLine("千叶豆腐 1份 34 34");
cache.AppendLine("莲菜 1份 34 34");
cache.AppendLine("------------------------------------------------------------- ");
cache.AppendLine("原价合计:207.00 ");
cache.AppendLine("如果您是会员可以优惠:12 ");
cache.AppendLine("消费实收 : 195.00");
cache.AppendLine("------------------------------------------------------------- ");
cache.AppendLine("打印时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
return cache.ToString();
}
string StringToBase64(string value)
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(value));
}
}
#endif之前写的调用Winform打印机程序,PosPrinter.exe我放在了StreamingAssets中,可以传递值
using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
#if UNITY_STANDALONE_WIN
public class CallExeModule : MonoBehaviour
{
Process myProcess;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnGUI()
{
if (GUI.Button(new Rect(20, 20, 100, 45), "TestPrinter"))
{
OpenAProgress(Application.dataPath + "/StreamingAssets/PosPrinter.exe");
}
}
void OpenAProgress(string filepath)
{
try
{
if (myProcess != null)
{
myProcess.Close();
myProcess.Dispose();
}
myProcess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(filepath, StringToBase64(MakeBill()));
myProcess.StartInfo = startInfo;
myProcess.StartInfo.UseShellExecute = false;
myProcess.Start();
}
catch (Exception ex)
{
Debuger.Log("出错原因:" + ex.Message);
}
}
string MakeBill()
{
StringBuilder cache = new StringBuilder();
cache.AppendLine("------------------------------------------------------------- ");
cache.AppendLine("消费日期:2016-06-03");
cache.AppendLine("单号:0020002 桌号 :20");
cache.AppendLine("服务员:02 餐段:全天");
cache.AppendLine("名称 数量 价格 小计");
cache.AppendLine("------------------------------------------------------------- ");
cache.AppendLine("鸡翅 1份 34 34");
cache.AppendLine("牛肉 1份 34 34");
cache.AppendLine("肥肠 1份 34 34");
cache.AppendLine("鲜虾 1份 34 34");
cache.AppendLine("千叶豆腐 1份 34 34");
cache.AppendLine("莲菜 1份 34 34");
cache.AppendLine("------------------------------------------------------------- ");
cache.AppendLine("原价合计:207.00 ");
cache.AppendLine("如果您是会员可以优惠:12 ");
cache.AppendLine("消费实收 : 195.00");
cache.AppendLine("------------------------------------------------------------- ");
cache.AppendLine("打印时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
return cache.ToString();
}
string StringToBase64(string value)
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(value));
}
}
#endif之前写的调用Winform打印机程序,PosPrinter.exe我放在了StreamingAssets中,可以传递值
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯