2025-05-18 01:04:31 +08:00

100 lines
2.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-12-21
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "WXInput" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
#if SDK_WECHAT_WASM
using WeChatWASM;
#endif
namespace G
{
/// <summary>
/// 微信适配
/// </summary>
public class WXInput : MonoBehaviour, IPointerClickHandler, IPointerExitHandler
{
public TMPro.TMP_InputField input;
public void OnPointerClick(PointerEventData eventData)
{
#if SDK_WECHAT_WASM
// 监听点击事件唤起微信输入法
WX.ShowKeyboard(new ShowKeyboardOption()
{
// 这里的参数根据需要自行设置参见https://developers.weixin.qq.com/minigame/dev/api/ui/keyboard/wx.showKeyboard.html
defaultValue = input.text,
maxLength = 20,
confirmType = "go"
});
//绑定回调
WX.OnKeyboardConfirm(OnConfirm);
WX.OnKeyboardComplete(OnComplete);
#endif
}
public void OnPointerExit(PointerEventData eventData)
{
#if SDK_WECHAT_WASM
// 隐藏输入法
if (!input.isFocused)
{
WX.HideKeyboard(null);
//删除掉相关事件监听
WX.OffKeyboardInput(OnInput);
WX.OffKeyboardConfirm(OnConfirm);
WX.OffKeyboardComplete(OnComplete);
}
#endif
}
#if SDK_WECHAT_WASM
public void OnInput(OnKeyboardInputCallbackResult v)
{
if (input.isFocused)
{
//input.text = v.value;
}
}
public void OnConfirm(OnKeyboardInputCallbackResult v)
{
// 输入法confirm回调
if (input.isFocused)
{
input.text = v.value;
}
}
public void OnComplete(OnKeyboardInputCallbackResult v)
{
// 输入法complete回调
if (input.isFocused)
{
}
}
#endif
void Start()
{
}
}
}