using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.SceneManagement;
|
using KTGMGemClient;
|
using UnityEngine.UI;
|
using LitJson;
|
using UnityEngine.Networking;
|
using Protobuf;
|
using Google.Protobuf;
|
using DG.Tweening;
|
|
public class LoginUI : MonoBehaviour
|
{
|
bool isLogining;
|
private JsonData loginData;
|
|
//private Button repairBtn;//修复
|
//private Button noticeBtn;//公告
|
private Button startBtn;//开始游戏
|
private Slider progressSlider;//进度条
|
|
private Text versionTxt;//版本号
|
private Text resVersion;//资源版本号
|
float waitTime;//切换场景等待时间
|
|
[SerializeField]
|
private Sprite nextSprite;
|
|
[SerializeField]
|
private Image bg;
|
|
[SerializeField]
|
private List<GameObject> other;
|
|
private GameObject MainUI;
|
|
// Start is called before the first frame update
|
void Start()
|
{
|
AudioSourceManager.Ins.Play(AudioEnum.BGM1);
|
|
EventCenter.Ins.RemoveAllListener();
|
TDAA_SDKManager.Ins.AddListener();
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.ChangeScene, ChangeScene);
|
|
isLogining = false;
|
|
MainUI = transform.Find("Panel/MainPanel").gameObject;
|
MainUI.SetActive(false);
|
|
//repairBtn = transform.Find("Panel/RepairBtn").GetComponent<Button>();
|
startBtn = transform.Find("Panel/StartBtn").GetComponent<Button>();
|
|
versionTxt = transform.Find("Panel/Version").GetComponent<Text>();
|
|
progressSlider = transform.Find("Panel/Progress").GetComponent<Slider>();
|
progressSlider.value = 0;
|
progressSlider.gameObject.SetActive(false);
|
|
startBtn.onClick.AddListener(OnClickLoginBtn);
|
startBtn.gameObject.SetActive(true);
|
|
// repairBtn.onClick.AddListener(() =>
|
// {
|
// OnClickResetBtn();
|
// });
|
|
//transform.Find("Panel/Button (1)").GetComponent<Button>().onClick.AddListener(OnClickResetBtn);
|
|
if (!GameConfig.useSDK)
|
{
|
if (Application.platform == RuntimePlatform.Android)
|
{
|
//GetetDeviceIMEI();//获取安卓手机IMEI
|
imei0 = TDAA_SDKManager.Ins.GetDeviceId();//使用设备ID
|
}
|
else if (Application.platform == RuntimePlatform.WindowsEditor)
|
{
|
imei0 = "MyTestGemBattle123";
|
}
|
|
GameConfig.Imei = imei0;
|
}
|
|
versionTxt.text = "版本号:" + Application.version;
|
//resVersion.text 暂时没有使用
|
transform.Find("Panel/PlayerID").GetComponent<Text>().text = "玩家ID:" + imei0;
|
|
if (GameConfig.isFirstStart)
|
{
|
waitTime = 0f;
|
Debug.Log("初始化TDAA_SDKManager");
|
TDAA_SDKManager.Ins.SDKInit(ChannelID.Gm.ToString());
|
TDAA_SDKManager.Ins.Statistics(1);//成功加载登陆界面的人数
|
}
|
|
//SetStart();
|
}
|
|
/// <summary>
|
/// 设置开始状态
|
/// </summary>
|
private void SetStart()
|
{
|
startBtn.gameObject.SetActive(true);
|
int resId = Mathf.FloorToInt(Mathf.Clamp01(GameConfig.GameCompletedCount));
|
Image img = startBtn.transform.GetChild(0).GetComponent<Image>();
|
img.sprite = Resources.Load<Sprite>($"UI/Loading/{resId}");
|
img.SetNativeSize();
|
|
if (GameConfig.GameCompletedCount > 0)
|
{
|
for (int i = 0; i < other.Count; ++i)
|
{
|
other[i].SetActive(false);
|
}
|
bg.sprite = nextSprite;
|
bg.SetNativeSize();
|
}
|
}
|
|
/// <summary>
|
/// 开始游戏
|
/// </summary>
|
void loginNext()
|
{
|
startBtn.gameObject.SetActive(false);
|
|
AudioSourceManager.Ins.Play(AudioEnum.UI);
|
TDAA_SDKManager.Ins.Statistics(2);//埋点
|
|
//GameConfig.isFirstStart = false;
|
MainUI.SetActive(true);
|
}
|
|
/// <summary>
|
/// 使用SDK登录
|
/// </summary>
|
void SDKloginNext()
|
{
|
GameConfig.Imei = SDKManager.ins.sdk.uid;
|
Debug.Log("SDK登录,修改Imei:" + GameConfig.Imei);
|
transform.Find("Panel/PlayerID").GetComponent<Text>().text = "玩家ID:" + GameConfig.Imei;
|
|
loginNext();
|
}
|
|
private void ChangeScene()
|
{
|
progressSlider.gameObject.SetActive(true);
|
|
StartCoroutine(loginMy());
|
}
|
|
|
#region 获得安卓手机上的IMEI号
|
public string imei0 = "";
|
public string imei1 = "";
|
public string meid = "";
|
|
/// <summary>
|
/// 已弃用
|
/// </summary>
|
void GetetDeviceIMEI()
|
{
|
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
var context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
|
var telephoneyManager = context.Call<AndroidJavaObject>("getSystemService", "phone");
|
imei0 = telephoneyManager.Call<string>("getImei", 0);//如果手机双卡 双待 就会有两个MIEI号
|
imei1 = telephoneyManager.Call<string>("getImei", 1);
|
meid = telephoneyManager.Call<string>("getMeid");//电信的手机 是MEID
|
|
CommonDebugHelper.Debug($"获取到了安卓手机的IMEI!!! imei0:{imei0} imei1:{imei1} meid:{meid}");
|
}
|
|
#endregion
|
|
private void OnClickResetBtn()
|
{
|
if (!GameConfig.useSDK)
|
{
|
Debug.LogError("清空了所有数据");
|
PlayerPrefs.DeleteAll();
|
TDAA_SDKManager.Ins.Reset();
|
}
|
}
|
|
|
private void OnClickLoginBtn()
|
{
|
if (!isLogining)
|
{
|
isLogining = true;
|
if (GameConfig.isFirstStart)
|
{
|
// CoderM: 在这里要使用SDK来进行登录了
|
if (GameConfig.useSDK)
|
{
|
Debug.Log("使用SDK来进行登录了");
|
//设置login的回调
|
SDKCallBack.ins.setNextAction("login", SDKloginNext);
|
SDKManager.ins.sdk.login();
|
}
|
else
|
{
|
Debug.Log("没有使用SDK");
|
|
//没有使用SDK
|
loginNext();
|
}
|
}
|
else
|
{
|
Debug.Log("重玩");
|
progressSlider.gameObject.SetActive(true);
|
startBtn.gameObject.SetActive(false);
|
|
AudioSourceManager.Ins.Play(AudioEnum.UI);
|
TDAA_SDKManager.Ins.OnClickRestartBtn();//重玩
|
StartCoroutine(loginMy());
|
}
|
|
}
|
|
}
|
|
IEnumerator loginMy()
|
{
|
progressSlider.value = 0.0f;
|
System.GC.Collect();
|
DOTween.Clear();
|
Debug.Log("开始清理GC,清理DOTween");
|
yield return new WaitForSeconds(waitTime);
|
int displayProgress = 0;
|
int toProgress = 0;
|
AsyncOperation op = SceneManager.LoadSceneAsync("Endless2D");
|
// AsyncOperation op = SceneManager.LoadSceneAsync(GameConfig.NextSceneName);
|
op.allowSceneActivation = false;
|
while (op.progress < 0.9f) //此处如果是 <= 0.9f 则会出现死循环所以必须小0.9
|
{
|
toProgress = (int)(op.progress * 100);
|
while (displayProgress < toProgress)
|
{
|
++displayProgress;
|
progressSlider.value = displayProgress * 0.01f;
|
SetLoadingPercentage(displayProgress);
|
yield return new WaitForEndOfFrame();//ui渲染完成之后
|
}
|
}
|
toProgress = 100;
|
while (displayProgress < toProgress)
|
{
|
++displayProgress;
|
progressSlider.value = displayProgress * 0.01f;
|
|
SetLoadingPercentage(displayProgress);
|
yield return new WaitForEndOfFrame();
|
}
|
op.allowSceneActivation = true;
|
yield break;
|
|
}
|
|
private void SetLoadingPercentage(int displayProgress)
|
{
|
//CommonDebugHelper.Debug($"当前进度{displayProgress}%");
|
}
|
|
}
|