unity 微信小游戏登录(通过code获取openid),充值

1.初始化:
 WX.InitSDK((jsCode) =>
 {
   
     Debug.Log("***  InitSDK  success ");
     FunGetSysten();
     Init1();
 });
 
 2.获取系统信息
  private void FunGetSysten()
 {
   
     Debug.Log("***  GetSystemInfo   ");
     GetSystemInfoOption getSystemInfoOption = new GetSystemInfoOption();
     getSystemInfoOption.success = ((e) =>
     {
   
         systemInfo = e;
         switch (e.platform)
         {
   
             case "android":
                 weChatSystemType = WeChatSystemType.android;
                 break;
             case "ios":
                 weChatSystemType = WeChatSystemType.ios;
                 break;
             case "windows":
                 weChatSystemType = WeChatSystemType.windows;
                 break;
             case "mac":
                 weChatSystemType = WeChatSystemType.mac;
                 break;
             case "devtools":
                 weChatSystemType = WeChatSystemType.devtools;
                 break;
             default:
                 weChatSystemType = WeChatSystemType.other;
                 break;
         }
         if (e.platform == "android")
         {
   
             
         }
         else
         if (e.platform == "ios")
         {
   
             weChatSystemType = WeChatSystemType.ios;
         }
         Debug.Log("***  GetSystemInfo  success " + e.platform);
     });
     getSystemInfoOption.fail = ((e) =>
     {
   
         Debug.Log("****** FunGetSysten  fail  :" + e.errMsg);
     });
     WX.GetSystemInfo(getSystemInfoOption);


var info = WX.GetSystemInfoSync();
if (info != null)
{
   
    Systen2_top = (float)info.safeArea.top;
    Systen2_windowHeight = (float)info.windowHeight;
    Systen2_pixelRatio = (float)info.pixelRatio;
}
 }
 
3.获取code
    public void Init1(Action action = null)
    {
   
Unity开发微信小游戏时,获取设备分辨率通常通过Unity的InputManager或GraphicsSettings API来完成。以下是一个简单的步骤: 1. 首先,在Unity编辑器中,打开`C#`脚本并添加以下代码: ```csharp using UnityEngine; using System.Runtime.InteropServices; public class DeviceResolution : MonoBehaviour { [DllImport("Unity-iPhone-iOS9")] private static extern void UIApplicationMain(int argc, string[] argv, string principalClassString, string delegateClassName); public void GetScreenResolution() { int width = Screen.width; int height = Screen.height; Debug.Log($"屏幕宽度: {width}, 屏幕高度: {height}"); } // 如果是在微信小程序环境中,这里需要判断 void Start() { if (Application.platform == RuntimePlatform.IPhonePlayer) { GetScreenResolution(); } else if (IsWechatXiaoGame()) // 判断是否是微信小游戏环境 { float deviceScale = ApplicationInfo.currentDeviceAspectRatio; // 微信小游戏有自己的deviceScale float scaledWidth = deviceScale * Screen.width; float scaledHeight = deviceScale * Screen.height; Debug.Log($"实际分辨率为 ({scaledWidth}, {scaledHeight})"); } } // 简单的微信小游戏环境检测函数,可能需要根据实际情况调整 private bool IsWechatXiaoGame() { return Application.tenantId != ""; } } ``` 注意,对于微信小游戏,`currentDeviceAspectRatio` 可能会返回一个大于1的值,这是因为微信小游戏会应用自适应缩放(例如2倍屏)。你需要根据实际需求调整分辨率获取
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序粉末状在校生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值