132 lines
4.5 KiB
C#
132 lines
4.5 KiB
C#
using Assets.Scripts;
|
||
using Assets.Scripts.Mobile.Interface;
|
||
using DG.Tweening;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class LoginControllerMobile : MonoBehaviour, INativeOnMobileWxLoginResp
|
||
{
|
||
// Start is called before the first frame update
|
||
ScrollRect loginScrollView;
|
||
Transform thirdLoginPage;
|
||
|
||
public WeChatController weChat { get; private set; }
|
||
|
||
void Awake()
|
||
{
|
||
loginScrollView = transform.Find("Panel/LoginContainer/LoginScrollView").GetComponent<ScrollRect>();
|
||
thirdLoginPage = loginScrollView.content.Find("FormContainer-Login/Mask/FormContainer-third");
|
||
UIManager.AddEvent(loginScrollView.content.Find("FormContainer-Login/Mask/FormContainer/BtnThirdLogin").gameObject,
|
||
UnityEngine.EventSystems.EventTriggerType.PointerClick,
|
||
(b)=> ShowThirdLoginPage());
|
||
UIManager.AddEvent(loginScrollView.content.Find("FormContainer-Login/Mask/FormContainer-third/BtnReturn").gameObject,
|
||
UnityEngine.EventSystems.EventTriggerType.PointerClick,
|
||
(b) => HideThirdLoginPage());
|
||
UIManager.AddEvent(loginScrollView.content.Find("FormContainer-Login/Mask/FormContainer-third/otherContainer/Wechat").gameObject,
|
||
UnityEngine.EventSystems.EventTriggerType.PointerClick,
|
||
(b) => goWxLogin());
|
||
}
|
||
|
||
|
||
private void Start()
|
||
{
|
||
transform.Find("MobileInfo/BatteryText").GetComponent<Text>().text =
|
||
$"{Math.Round(SystemInfo.batteryLevel * 100, 0)}%";
|
||
transform.Find("MobileInfo/TimeText").GetComponent<Text>().text =
|
||
DateTime.Now.ToString("HH:mm");
|
||
weChat = App.weChatController;
|
||
weChat.Init(App.WxAppId);
|
||
//App.weChatController.Init(App.WxAppId);
|
||
//var s = App.weChatController.isApplicationAvilible("com.gugoumainapp","powerfun").ToString();
|
||
//Utils.showToast(null, SystemInfo.batteryLevel.ToString());
|
||
CheckUpdate();
|
||
}
|
||
|
||
private async void CheckUpdate()
|
||
{
|
||
var r = await ConfigHelper.userApi.GetVersions();
|
||
if (r.result)
|
||
{
|
||
|
||
#if UNITY_ANDROID
|
||
var info = r.data.Value<JObject>("UnityApk");
|
||
Debug.Log(info.Value<string>("Version"));
|
||
if (info.Value<string>("Version") != App.AppVersion)
|
||
{
|
||
transform.Find("Panel").gameObject.SetActive(false);
|
||
transform.Find("Version").gameObject.SetActive(false);
|
||
UIManager.ShowAndroidUpdate(info);
|
||
}
|
||
#elif UNITY_IOS
|
||
var info = r.data.Value<JObject>("UnityIos");
|
||
if (info.Value<string>("Version") != App.AppVersion)
|
||
{
|
||
Application.OpenURL(info.Value<string>("Url"));
|
||
Application.Quit();
|
||
}
|
||
#endif
|
||
}
|
||
//if (r.result)
|
||
//{
|
||
// //#if !UNITY_EDITOR
|
||
// var ver = r.data.Value<JObject>("Version").ToObject<UpdateModel>();
|
||
// if (ver != null && ver.HasUpdate)
|
||
// {
|
||
// App.UpdateObject = ver;
|
||
// Debug.Log(Application.persistentDataPath + "/PowerFun.exe");
|
||
// UIManager.ShowDownloadModal();
|
||
// }
|
||
// //#endif
|
||
// App.notifyContent = r.data.Value<string>("Content");
|
||
|
||
// if (r.data.Value<int>("Id") != notifyId)//r.data.Value<int>("Id") != notifyId
|
||
// {
|
||
// UIManager.ShowNewsModal();
|
||
// PlayerPrefs.SetInt("notifyId", r.data.Value<int>("Id"));
|
||
// }
|
||
//}
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
private void ShowThirdLoginPage()
|
||
{
|
||
thirdLoginPage.DOLocalMoveY(0, 0.3f);
|
||
}
|
||
public void HideThirdLoginPage()
|
||
{
|
||
thirdLoginPage.DOLocalMoveY(-301, 0.3f);
|
||
}
|
||
private void goWxLogin()
|
||
{
|
||
#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
|
||
if (weChat.IsWeChatAppInstalled())
|
||
{
|
||
weChat.WxLogin("snsapi_userinfo", "");
|
||
}
|
||
#endif
|
||
}
|
||
/// <summary>
|
||
/// 从ios或者安卓接收code,在c#里不建议调用
|
||
/// </summary>
|
||
/// <param name="res"></param>
|
||
public void OnMobileWxLoginResp(string res)
|
||
{
|
||
if (res.Contains("true;"))
|
||
{
|
||
GetComponent<LoginController>().goWxLoginWithCode(res.Replace("true;", ""), "mobile");
|
||
}
|
||
else
|
||
{
|
||
Utils.showToast(null, res.Replace("false;", ""));
|
||
}
|
||
}
|
||
}
|