[Unity菜鸟] Unity发布web后,从HTML调用本地文件

1. 遇到的问题

从xml读数据,xml的编码用中文就会乱码,改编码格式就调用不了。目前采用默认的ANSI编码。

.exe        .txt .xlsx .xml .test

Run √ (路径不能带空格) √ √ √ √ (.test要有关联的默认打开方式如记事本)

Exec √ × × × ×

Run 不能直接打开带有空格的路径,如果带有空格,我给路径加一对双引号就又能运行

Exec 可以打开带有空格的.exe文件

一篇比较好的例子:必须要用支持ActiveX的浏览器,比如IE。并且在IE-Internet选项-安全-自定义级别-对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本 选择启用。

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <title></title>
 5     <script type="text/javascript">
 6         function Run(strPath) {
 7             //debugger;
 8             exe.value = strPath;
 9             try
10             {  
11                  //核心语句
12                  var objShell = new ActiveXObject("wscript.shell");
13                  objShell.Run(strPath);
14                  objShell = null;
15              }
16              catch (e)
17              {
18                  alert('找不到文件"' + strPath + '"(或它的组件之一)。请确定路径和文件名是否正确,而且所需的库文件均可用。')
19             }
20         }   
21  
22     </script>
23 </head>
24 <body>
25     请输入要运行的程序:<br>
26     <input name="exe" type="text" size="20" value="regedit">
27     <button type="button" onclick="Run(exe.value)">
28         确定</button>
29     <button type="button" onclick="exe.value=''">
30         重新输入</button><br>
31     <button type="button" onclick="Run('C:\\WINDOWS\\system32\\notepad.exe')">
32         记事本</button><br>
33     <button type="button" onclick="Run('C:\\WINDOWS\\system32\\mspaint.exe')">
34         画图板</button><br>
35     <button type="button" onclick="Run('C:\\WINDOWS\\system32\\calc.exe')">
36         计算器</button><br>
37     <button type="button" onclick="Run('C:\\WINDOWS\\system32\\cmd.exe')">
38         cmd</button><br>
39     <button type="button" onclick="Run('C:\\WINDOWS\\regedit.exe')">
40         注册表</button><br>
41     <button type="button" onclick="Run('C:\\WINDOWS\\system32\\msconfig.exe')">
42         Msconfig</button><br>
43 </body>
44 </html>