Ali*_*000 1 c# unity-game-engine unity-webgl
目前通过我的游戏打开链接会在相同的界面中打开链接。我希望它在新选项卡上打开。我尝试研究插件等,以便 .jslib 文件与 Unity 项目交互,但我也遇到了问题。我是这种交互的新手,所以我在查找插件检查器本身时也遇到了问题。
目前,我的代码是这样做的:
private void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
Application.OpenURL("www.google.com");
}
}
Run Code Online (Sandbox Code Playgroud)
所以这会在同一浏览器上打开链接。我试图做到这一点,当用户点击返回键时,他们会在新浏览器上打开该链接。
任何帮助表示赞赏!
一种正确的方法是使用 .jslib 文件
资产/插件/plugin.jslib
var plugin = {
OpenNewTab : function(url)
{
url = Pointer_stringify(url);
window.open(url,'_blank');
},
};
mergeInto(LibraryManager.library, plugin);
Run Code Online (Sandbox Code Playgroud)
你的 C# 脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
public class OpenURL : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void OpenNewTab(string url);
public void openIt(string url)
{
#if !UNITY_EDITOR && UNITY_WEBGL
OpenNewTab(url);
#endif
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
openIt("www.wateverurluwant.com");
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3391 次 |
| 最近记录: |