2021-08-23 09:28:14 +08:00
|
|
|
|
using Assets.Scripts;
|
2021-09-13 17:33:58 +08:00
|
|
|
|
using Assets.Scripts.Mobile.Interface;
|
2021-08-24 17:50:14 +08:00
|
|
|
|
using DG.Tweening;
|
2021-10-12 20:07:13 +08:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2021-08-24 17:50:14 +08:00
|
|
|
|
using System;
|
2021-08-23 09:28:14 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
2021-08-24 17:50:14 +08:00
|
|
|
|
using UnityEngine.UI;
|
2021-08-23 09:28:14 +08:00
|
|
|
|
|
2021-09-13 17:33:58 +08:00
|
|
|
|
public class LoginControllerMobile : MonoBehaviour, INativeOnMobileWxLoginResp
|
2021-08-23 09:28:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
// Start is called before the first frame update
|
2021-08-24 17:50:14 +08:00
|
|
|
|
ScrollRect loginScrollView;
|
|
|
|
|
|
Transform thirdLoginPage;
|
2021-08-26 15:08:02 +08:00
|
|
|
|
|
|
|
|
|
|
public WeChatController weChat { get; private set; }
|
|
|
|
|
|
|
2021-08-24 17:50:14 +08:00
|
|
|
|
void Awake()
|
2021-08-23 09:28:14 +08:00
|
|
|
|
{
|
2021-08-24 17:50:14 +08:00
|
|
|
|
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());
|
2021-12-01 10:38:43 +08:00
|
|
|
|
|
2021-08-23 09:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-24 17:50:14 +08:00
|
|
|
|
|
2021-08-26 15:08:02 +08:00
|
|
|
|
private void Start()
|
|
|
|
|
|
{
|
2021-10-25 16:13:04 +08:00
|
|
|
|
//Utils.showToast(null,"123",duration:10,showSeconds: true);
|
2021-08-26 15:08:02 +08:00
|
|
|
|
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());
|
2021-10-12 20:07:13 +08:00
|
|
|
|
CheckUpdate();
|
2021-08-26 15:08:02 +08:00
|
|
|
|
}
|
2021-10-12 20:07:13 +08:00
|
|
|
|
|
|
|
|
|
|
private async void CheckUpdate()
|
|
|
|
|
|
{
|
2021-10-21 18:04:01 +08:00
|
|
|
|
#if UNITY_ANDROID
|
|
|
|
|
|
transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/BtnThirdLogin")
|
|
|
|
|
|
.gameObject.SetActive(true);
|
|
|
|
|
|
#endif
|
2021-10-12 20:07:13 +08:00
|
|
|
|
var r = await ConfigHelper.userApi.GetVersions();
|
|
|
|
|
|
if (r.result)
|
|
|
|
|
|
{
|
2021-11-01 11:04:22 +08:00
|
|
|
|
#if UNITY_ANDROID || UNITY_IOS
|
|
|
|
|
|
#if UNITY_ANDROID
|
2021-10-12 20:07:13 +08:00
|
|
|
|
var info = r.data.Value<JObject>("UnityApk");
|
|
|
|
|
|
Debug.Log(info.Value<string>("Version"));
|
2021-10-13 19:03:14 +08:00
|
|
|
|
if (Utils.isUpdate(App.AppVersion, info.Value<string>("Version")))
|
2021-10-12 20:07:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
transform.Find("Panel").gameObject.SetActive(false);
|
|
|
|
|
|
transform.Find("Version").gameObject.SetActive(false);
|
|
|
|
|
|
UIManager.ShowAndroidUpdate(info);
|
|
|
|
|
|
}
|
2021-11-17 18:10:20 +08:00
|
|
|
|
App.WorkoutsUrl = r.data.Value<JObject>("Apk").Value<string>("Url");
|
2021-10-12 20:07:13 +08:00
|
|
|
|
#elif UNITY_IOS
|
2021-10-20 14:13:44 +08:00
|
|
|
|
var sw = r.data.Value<string>("ThirdPartSwitch");
|
|
|
|
|
|
transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/BtnThirdLogin")
|
|
|
|
|
|
.gameObject.SetActive(sw.Equals("on") && App.weChatController.IsWeChatAppInstalled());
|
2021-10-12 20:07:13 +08:00
|
|
|
|
var info = r.data.Value<JObject>("UnityIos");
|
2021-10-13 19:03:14 +08:00
|
|
|
|
if (Utils.isUpdate(App.AppVersion, info.Value<string>("Version")))
|
2021-10-12 20:07:13 +08:00
|
|
|
|
{
|
2021-10-13 11:29:09 +08:00
|
|
|
|
Application.OpenURL(info.Value<string>("Url"));
|
|
|
|
|
|
Application.Quit();
|
2021-10-12 20:07:13 +08:00
|
|
|
|
}
|
2021-11-17 18:10:20 +08:00
|
|
|
|
App.WorkoutsUrl = r.data.Value<JObject>("Ios").Value<string>("Url");
|
2021-10-12 20:07:13 +08:00
|
|
|
|
#endif
|
2021-11-17 18:10:20 +08:00
|
|
|
|
|
2021-11-01 11:04:22 +08:00
|
|
|
|
#endif
|
2021-10-12 20:07:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
//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"));
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-23 09:28:14 +08:00
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void ShowThirdLoginPage()
|
|
|
|
|
|
{
|
2021-08-24 17:50:14 +08:00
|
|
|
|
thirdLoginPage.DOLocalMoveY(0, 0.3f);
|
2021-08-23 09:28:14 +08:00
|
|
|
|
}
|
2021-08-24 17:50:14 +08:00
|
|
|
|
public void HideThirdLoginPage()
|
2021-08-23 09:28:14 +08:00
|
|
|
|
{
|
2021-08-24 17:50:14 +08:00
|
|
|
|
thirdLoginPage.DOLocalMoveY(-301, 0.3f);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void goWxLogin()
|
|
|
|
|
|
{
|
|
|
|
|
|
#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
|
|
|
|
|
|
if (weChat.IsWeChatAppInstalled())
|
|
|
|
|
|
{
|
|
|
|
|
|
weChat.WxLogin("snsapi_userinfo", "");
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
2021-08-23 09:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 从ios或者安卓接收code,在c#里不建议调用
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="res"></param>
|
|
|
|
|
|
public void OnMobileWxLoginResp(string res)
|
|
|
|
|
|
{
|
2021-09-13 17:33:58 +08:00
|
|
|
|
if (res.Contains("true;"))
|
|
|
|
|
|
{
|
|
|
|
|
|
GetComponent<LoginController>().goWxLoginWithCode(res.Replace("true;", ""), "mobile");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Utils.showToast(null, res.Replace("false;", ""));
|
|
|
|
|
|
}
|
2021-08-23 09:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|