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(); 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 = $"{Math.Round(SystemInfo.batteryLevel * 100, 0)}%"; transform.Find("MobileInfo/TimeText").GetComponent().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("UnityApk"); Debug.Log(info.Value("Version")); if (Utils.isUpdate(App.AppVersion, info.Value("Version"))) { transform.Find("Panel").gameObject.SetActive(false); transform.Find("Version").gameObject.SetActive(false); UIManager.ShowAndroidUpdate(info); } #elif UNITY_IOS var sw = r.data.Value("ThirdPartSwitch"); transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/BtnThirdLogin") .gameObject.SetActive(sw.Equals("on") && App.weChatController.IsWeChatAppInstalled()); var info = r.data.Value("UnityIos"); if (Utils.isUpdate(App.AppVersion, info.Value("Version"))) { Application.OpenURL(info.Value("Url")); Application.Quit(); } #endif } //if (r.result) //{ // //#if !UNITY_EDITOR // var ver = r.data.Value("Version").ToObject(); // if (ver != null && ver.HasUpdate) // { // App.UpdateObject = ver; // Debug.Log(Application.persistentDataPath + "/PowerFun.exe"); // UIManager.ShowDownloadModal(); // } // //#endif // App.notifyContent = r.data.Value("Content"); // if (r.data.Value("Id") != notifyId)//r.data.Value("Id") != notifyId // { // UIManager.ShowNewsModal(); // PlayerPrefs.SetInt("notifyId", r.data.Value("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 } /// /// 从ios或者安卓接收code,在c#里不建议调用 /// /// public void OnMobileWxLoginResp(string res) { if (res.Contains("true;")) { GetComponent().goWxLoginWithCode(res.Replace("true;", ""), "mobile"); } else { Utils.showToast(null, res.Replace("false;", "")); } } }