powerfun-unity/Assets/Scripts/Mobile/LoginControllerMobile.cs
2021-10-13 19:03:22 +08:00

132 lines
4.5 KiB
C#
Raw 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.

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 (Utils.isUpdate(App.AppVersion, info.Value<string>("Version")))
{
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 (Utils.isUpdate(App.AppVersion, info.Value<string>("Version")))
{
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;", ""));
}
}
}