• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

WebGL手机端弹出输入框

武飞扬头像
weixin_43754633
帮助1

实现原理是使用JS调用浏览器的默认提示框,默认提示框可以呼出软键盘,(注意此时呼出的提示框会阻塞,unity会不工作,就算你勾选了Run in BackGround),关掉提示框,unity会再次工作

网上给的解决方法是自定义呼出模板,而不是用默认提示框(博主没试过)

1,创建JS代码(放在Plugin中,这方面Unity官网有介绍如何制作unity可调用的JS的操作方法),Unity调用JS

JS代码

 mergeInto(LibraryManager.library, {

    StringReturnValueFunction: function ()
    {
        var returnStr = window.location.search;
        var buffer = _malloc(lengthBytesUTF8(returnStr)   1);
        writeStringToMemory(returnStr,buffer);
        return buffer;
    },

    ShowKeyboard: function (str)   //这个就是呼出浏览器默认提示框的方法
    {
        var returnStr = prompt("", Pointer_stringify(str)); //呼出提示框方法,具体百度
        if(returnStr == undefined)
        {
           return "";
        }
        var buffer = _malloc(lengthBytesUTF8(returnStr)   1);
         writeStringToMemory(returnStr,buffer);
        return buffer;
    },

});
学新通

Unity调用

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Runtime.InteropServices;
using System;

[RequireComponent(typeof(InputField))]
public class KeyboardClassInput : MonoBehaviour, ISelectHandler
{

    [DllImport("__Internal")]
    private static extern string ShowKeyboard(string str);

    string str;

    private InputField inputField;

    private void Awake()
    {
		inputField = GetComponent<InputField>();
	}

    public void Update()
    {
        if (str != null&&str!=""&&!string.IsNullOrEmpty(str))
        {
            inputField.text= str;
        }
    }

    public void OnSelect(BaseEventData data) 
    {
      
#if UNITY_EDITOR
        return;
    #endif
        str = ShowKeyboard("Enter Name");
    }
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbgbck
系列文章
更多 icon
同类精品
更多 icon
继续加载