Unity WebGL ios 跳转URL

需求:

WebGL跳转网址

现象:

Application.OpenURL("https://www.baidu.com");

这个函数在安卓上可以用,IOS 不管用

解决方案:

编写js插件,unity调用js函数,由js跳转网址 

注意事项 :

将以下JS代码复制并且放到Unity工程Plugins文件夹下,插件后缀为.jslib ,如名字为IOS.jslib

C#代码加上[DllImport]

    public void OpenURL()
    {
        JSOpenURL();
    }

    [DllImport("__Internal")]
    public static extern void JSOpenURL();
mergeInto(LibraryManager.library, {

  JSOpenURL: function () {
    //window.open("https://www.baidu.com");
    location.href = "https://www.baidu.com";
  },

  HelloString: function (str) {
    window.alert(Pointer_stringify(str));
  },

  PrintFloatArray: function (array, size) {
    for(var i = 0; i < size; i++)
    console.log(HEAPF32[(array >> 2) + i]);
  },

  AddNumbers: function (x, y) {
    return x + y;
  },

  StringReturnValueFunction: function () {
    var returnStr = "bla";
    var bufferSize = lengthBytesUTF8(returnStr) + 1;
    var buffer = _malloc(bufferSize);
    stringToUTF8(returnStr, buffer, bufferSize);
    return buffer;
  },

  BindWebGLTexture: function (texture) {
    GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[texture]);
  },

});

高级跳转功能:

如跳转各大应用商店,唤醒APP等,暂时不写,催我就写,哈哈

IOSAppStore:

itms-apps://itunes.apple.com/us/developer/<short name>/id<your developer id> 

帮助链接:

官方文档icon-default.png?t=N7T8https://docs.unity3d.com/2021.1/Documentation/Manual/webgl-interactingwithbrowserscripting.html

JS页面跳转常用函数icon-default.png?t=N7T8https://blog.csdn.net/rr20060119/article/details/133919531

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值