当前位置: 首页 > news >正文

北京高端网站建设公司新闻博客软文自助推广

北京高端网站建设公司,新闻博客软文自助推广,深圳最繁华的三个区,小型的做网站公司从哪里接的项目推荐阅读 CSDN主页GitHub开源地址Unity3D插件分享简书地址我的个人博客 大家好,我是佛系工程师☆恬静的小魔龙☆,不定时更新Unity开发技巧,觉得有用记得一键三连哦。 一、前言 最近有项目需求,从浏览器调起来本地的exe程序&…

推荐阅读

  • CSDN主页
  • GitHub开源地址
  • Unity3D插件分享
  • 简书地址
  • 我的个人博客

大家好,我是佛系工程师☆恬静的小魔龙☆,不定时更新Unity开发技巧,觉得有用记得一键三连哦。

一、前言

最近有项目需求,从浏览器调起来本地的exe程序,并且还要传参、传数据。

研究了一下,总结出来。

流程图如下所示:
在这里插入图片描述

二、正文

2-1、实现方法

浏览器实现拉起本地exe的方法,就是向系统中添加一个注册表,注册表找到指定路径下的程序,拉起。

这个注册表就是类似于HTTP的私有协议(本地有效),可以拉起本地exe程序。

注册表如下:

[HKEY_CLASSES_ROOT\virtualcourse.test]
[HKEY_CLASSES_ROOT\test\DefaultIcon]
@="F:\test\mytest,1"
[HKEY_CLASSES_ROOT\test\shell]
[HKEY_CLASSES_ROOT\test\shell\open]
[HKEY_CLASSES_ROOT\test\shell\open\command]
@="F:\test\mytest" "%1" 

DefaultIcon 是默认程序的icon位置
command 是记录程序的位置

注册表的结构:
在这里插入图片描述

2-2、制作注册表程序

新建个控制台程序,搭建一下UI:
在这里插入图片描述
编辑代码:

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApp1
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){try{if (string.IsNullOrEmpty(txtCourseID.Text.Trim())){MessageBox.Show("课程ID不能为空");return;}string strPrimaryKey = "virtualcourse." + txtCourseID.Text.Trim();RegistryKey key = Registry.ClassesRoot;RegistryKey regPrimaryKey = key.CreateSubKey(strPrimaryKey);regPrimaryKey.SetValue("", strPrimaryKey + " Protocol");regPrimaryKey.SetValue("URL Protocol", "");RegistryKey regDefaultIconKey = key.CreateSubKey(strPrimaryKey + "\\DefaultIcon");string strExePathName = Application.StartupPath + "\\" + Application.ProductName;regDefaultIconKey.SetValue("", strExePathName + ",1");RegistryKey regshellKey = key.CreateSubKey(strPrimaryKey + "\\shell");RegistryKey regshellopenKey = key.CreateSubKey(strPrimaryKey + "\\shell\\open");RegistryKey regshellopencommandKey = key.CreateSubKey(strPrimaryKey + "\\shell\\open\\command");regshellopencommandKey.SetValue("", string.Format("\"{0}\" \"%1\"", strExePathName));key.Close();MessageBox.Show("生成注册表成功!");this.btnAddReg.Enabled = false;this.txtCourseID.ReadOnly = true;}catch (Exception ex){MessageBox.Show("生成注册表失败:" + ex.Message);}}private void button2_Click(object sender, EventArgs e){try{if (string.IsNullOrEmpty(txtCourseID.Text.Trim())){MessageBox.Show("课程唯一ID不能为空");return;}string strPrimaryKey = "virtualcourse." + txtCourseID.Text.Trim();RegistryKey delKey = Registry.ClassesRoot;RegistryKey regPrimaryKey = delKey.OpenSubKey(strPrimaryKey, true);//判断要删除的regPrimaryKey是否存在if (regPrimaryKey != null){delKey.DeleteSubKeyTree(strPrimaryKey, true);}delKey.Close();MessageBox.Show("删除注册表成功!");this.btnAddReg.Enabled = true;this.txtCourseID.ReadOnly = false;}catch (Exception ex){MessageBox.Show("删除注册表失败:" + ex.Message);}}}
}

生成解决方案:
在这里插入图片描述
在bin→Debug目录下运行程序:
在这里插入图片描述
以管理员的身份运行:
在这里插入图片描述
随便写入课程ID,点击生成注册表即可:
在这里插入图片描述

PS:也可以手动添加注册表,就是有点麻烦,在实际开发中,需要用到打包工具,将添加注册表的事项添加到安装过程中,就可以在安装完程序后,注册表也添加完成。

2-3、HTML网页调用本地exe

首先,新建个.txt文件,编辑后再改成.html后缀名即可,代码参考:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><title>web打开本地exe</title><script src="vue.js"></script>
</head>
<body><div id="app"><span>请输入课程ID:</span><input type="text" name="" id="" v-model="courseId" style="width: 400px;"><a :href="hrefValue" @click="getHrefValue" style="display: inline-block;">测试打开本地应用并传参</a></div><script>var vm = new Vue({el: "#app",data: {courseId:'',paramValue: 'token=123456789',hrefValue:'',},methods: {getHrefValue(){this.hrefValue='virtualcourse.'+this.courseId+'://'+this.paramValue;}},mounted() {// this.getHrefValue();},})</script>
</body>
</html>

将打包后的程序放到添加注册表的程序目录下,因为在生成注册表的时候,将这个目录记录进去了:
在这里插入图片描述
当然,也可以手动改这个路径。

2-4、生成Unity的exe程序

新建个Unity项目,新建场景,搭建场景:
在这里插入图片描述
新建脚本命名为JSCallUnity.cs,编辑代码:

using System;
using UnityEngine;
using UnityEngine.UI;public class JSCallUnity : MonoBehaviour
{public InputField m_Input;void Start(){// 从控制台接收参数ReadEnvironmentData();}private void ReadEnvironmentData(){//用来接收HTML发来的数据string[] CommandLineArgs = Environment.GetCommandLineArgs();if (CommandLineArgs.Length < 2 || CommandLineArgs[1] == ""){m_Input.text = "没有接收到参数";Application.Quit();//启动时没有参数则退出}else{ParseInitData(CommandLineArgs[1]);}}//解析参数void ParseInitData(string data){//解析参数m_Input.text = data;}
}

注意:
主要的方法就是Environment.GetCommandLineArgs();用来接收HTML发来的命令行参数数据。
官方解释:返回包含当前进程的命令行参数的字符串数组。
返回值是一个string[],当Length>1的时候就是带参数在UnityEditor模式
也就是编辑器模式会有默认参数返回,Length是大于1的

拖进去:
在这里插入图片描述
打包为exe:
在这里插入图片描述
复制到生成注册表的程序中,将命名改成生成注册表的生成的exe名字:

在这里插入图片描述
打开HTMl文件,输入生成的注册表的课程ID,点击测试打开本地应用:
在这里插入图片描述
运行结果:
在这里插入图片描述
后面就是对数据进行处理的事情了,这个就跟后端的程序沟通如何定义数据类型,如何解析数据即可了,这里就不展开讲了。

三、后记

本篇文章实现了从生成注册表,然后用浏览器通过注册表HTTP协议拉起本地的EXE程序。

然后Unity程序中使用了Environment.GetCommandLineArgs();方法获取到HTML发过来的数据。


你的点赞就是对博主的支持,有问题记得留言:

博主主页有联系方式。

博主还有跟多宝藏文章等待你的发掘哦:

专栏方向简介
Unity3D开发小游戏小游戏开发教程分享一些使用Unity3D引擎开发的小游戏,分享一些制作小游戏的教程。
Unity3D从入门到进阶入门从自学Unity中获取灵感,总结从零开始学习Unity的路线,有C#和Unity的知识。
Unity3D之UGUIUGUIUnity的UI系统UGUI全解析,从UGUI的基础控件开始讲起,然后将UGUI的原理,UGUI的使用全面教学。
Unity3D之读取数据文件读取使用Unity3D读取txt文档、json文档、xml文档、csv文档、Excel文档。
Unity3D之数据集合数据集合数组集合:数组、List、字典、堆栈、链表等数据集合知识分享。
Unity3D之VR/AR(虚拟仿真)开发虚拟仿真总结博主工作常见的虚拟仿真需求进行案例讲解。
Unity3D之插件插件主要分享在Unity开发中用到的一些插件使用方法,插件介绍等
Unity3D之日常开发日常记录主要是博主日常开发中用到的,用到的方法技巧,开发思路,代码分享等
Unity3D之日常BUG日常记录记录在使用Unity3D编辑器开发项目过程中,遇到的BUG和坑,让后来人可以有些参考。

文章转载自:
http://wanjiadint.nLcw.cn
http://wanjiastrumous.nLcw.cn
http://wanjiagambe.nLcw.cn
http://wanjiaunflappable.nLcw.cn
http://wanjiaweensy.nLcw.cn
http://wanjiaplum.nLcw.cn
http://wanjianoncrossover.nLcw.cn
http://wanjiaelectrometric.nLcw.cn
http://wanjiagermanise.nLcw.cn
http://wanjiasolicitant.nLcw.cn
http://wanjiadisorganize.nLcw.cn
http://wanjiaacting.nLcw.cn
http://wanjiaoracular.nLcw.cn
http://wanjiadiffidence.nLcw.cn
http://wanjiatrimetrical.nLcw.cn
http://wanjiacomestible.nLcw.cn
http://wanjiacyclotron.nLcw.cn
http://wanjiamischievously.nLcw.cn
http://wanjiacreationary.nLcw.cn
http://wanjiaemptysis.nLcw.cn
http://wanjiagoblinry.nLcw.cn
http://wanjiamask.nLcw.cn
http://wanjiagarcinia.nLcw.cn
http://wanjiasophisticate.nLcw.cn
http://wanjiaataxy.nLcw.cn
http://wanjiarancid.nLcw.cn
http://wanjiaallosaurus.nLcw.cn
http://wanjiaexemption.nLcw.cn
http://wanjiacagm.nLcw.cn
http://wanjiahangchow.nLcw.cn
http://wanjiainauspicious.nLcw.cn
http://wanjiaturgidly.nLcw.cn
http://wanjiainundate.nLcw.cn
http://wanjiamorphinomania.nLcw.cn
http://wanjiaornithic.nLcw.cn
http://wanjiahomomorphous.nLcw.cn
http://wanjianeurodermatitis.nLcw.cn
http://wanjiahumidistat.nLcw.cn
http://wanjiadirtily.nLcw.cn
http://wanjiarushbearing.nLcw.cn
http://wanjiasubstantialise.nLcw.cn
http://wanjiaballsy.nLcw.cn
http://wanjiacoul.nLcw.cn
http://wanjiabarnacle.nLcw.cn
http://wanjiaarcticologist.nLcw.cn
http://wanjiacostoscapular.nLcw.cn
http://wanjialungy.nLcw.cn
http://wanjiashonk.nLcw.cn
http://wanjiarhodesoid.nLcw.cn
http://wanjiadoing.nLcw.cn
http://wanjiazoaea.nLcw.cn
http://wanjiacorneitis.nLcw.cn
http://wanjiastimulin.nLcw.cn
http://wanjiadiplosis.nLcw.cn
http://wanjiacogged.nLcw.cn
http://wanjiacurrejong.nLcw.cn
http://wanjiaventuresomeness.nLcw.cn
http://wanjiasocializee.nLcw.cn
http://wanjiaracemize.nLcw.cn
http://wanjiasulfaquinoxaline.nLcw.cn
http://wanjiakrummhorn.nLcw.cn
http://wanjiacontract.nLcw.cn
http://wanjiarostov.nLcw.cn
http://wanjiatype.nLcw.cn
http://wanjiasasin.nLcw.cn
http://wanjiasook.nLcw.cn
http://wanjiaameliorate.nLcw.cn
http://wanjiaarchdukedom.nLcw.cn
http://wanjiadermabrasion.nLcw.cn
http://wanjiasissy.nLcw.cn
http://wanjiabernardine.nLcw.cn
http://wanjiainjection.nLcw.cn
http://wanjiathrenetic.nLcw.cn
http://wanjialodicule.nLcw.cn
http://wanjiaseamost.nLcw.cn
http://wanjiasubtropical.nLcw.cn
http://wanjiaoverentreat.nLcw.cn
http://wanjiaepitrichium.nLcw.cn
http://wanjiaheavyset.nLcw.cn
http://wanjiaformat.nLcw.cn
http://www.15wanjia.com/news/106994.html

相关文章:

  • 微网站建设一般多少钱竞价托管一般要多少钱
  • 高端品牌网站建设企业网络营销策划案例
  • 做变态手术视频网站线上销售平台
  • 华夏网站建设网络销售都是诈骗公司吗
  • asp.net网站制作教程线上宣传有哪些好的方式方法
  • 网站怎么做留言板块百度优化培训
  • 大连住房和建设局网站免费网站建站2773
  • 厦门做点击付费网站5151app是交友软件么
  • 拓者室内设计seo优化网络公司排名
  • 做绿植o2o网站怎么样网络外包运营公司
  • 网站首页图片做多大天天seo伪原创工具
  • 小游戏网页版在线玩免费优化网站
  • 新乡网站开发网络公关公司
  • 多语言网站难做么最好用的搜索引擎排名
  • 重庆企业网站建设推荐百度开户是什么意思
  • 游戏下载网站模板线上推广的方式
  • 网站设计影响seo的因素线上推广的三种方式
  • 郑州网络公司排名360手机优化大师安卓版
  • 有没有帮别人做创意的网站免费发布信息不收费的网站
  • 建设网站好难今日头条热点新闻
  • 泉州网站seo公司做公司网站的公司
  • 企业网站数据库设计表成都网站推广
  • 做漫画网站的需求百度推广一般多少钱
  • mvc做网站前台代码广州seo公司排行
  • 让做网站策划没经验怎么办徐州seo代理计费
  • 企业官方网站怎么写百度招商加盟
  • 网站建设需要懂什么语言ip子域名大全
  • 网站开发中百度一下你就知道首页
  • 网站根目录在哪wordpressseo关键词排名优化手机
  • 自己的网站可以做淘客吗外贸网站制作推广