From c4e6d5838229decfda40a33d7355522f1a47921c Mon Sep 17 00:00:00 2001
From: wangguan <wangguan@kt007.com>
Date: Thu, 10 Dec 2020 10:25:07 +0800
Subject: [PATCH] login注释

---
 Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs |  258 +++++++++++++++++---------------------------------
 1 files changed, 89 insertions(+), 169 deletions(-)

diff --git a/Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs b/Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs
index 539a428..622dd1b 100644
--- a/Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs
+++ b/Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs
@@ -8,22 +8,52 @@
 using UnityEngine.Networking;
 using Protobuf;
 using Google.Protobuf;
+using DG.Tweening;
 
 public class LoginUI : MonoBehaviour
 {
-    private AsyncOperation async = null;
     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;//切换场景等待时间
+
 
     // Start is called before the first frame update
     void Start()
     {
-        TDAA_SDKManager.Ins.SDKInit(ChannelID.Gm.ToString());
-        TDAA_SDKManager.Ins.Statistics(1);//成功加载登陆界面的人数
+        AudioSourceManager.Ins.Play(AudioEnum.BGM1);
+        EventCenter.Ins.RemoveAllListener();
+
         isLogining = false;
 
-        transform.Find("Panel/Button").GetComponent<Button>().onClick.AddListener(OnClickLoginBtn);
-        transform.Find("Panel/Button (1)").GetComponent<Button>().onClick.AddListener(OnClickResetBtn);
+        repairBtn = transform.Find("Panel/RepairBtn").GetComponent<Button>();
+        noticeBtn = transform.Find("Panel/NoticeBtn").GetComponent<Button>();
+        startBtn = transform.Find("Panel/StartBtn").GetComponent<Button>();
+
+        versionTxt = transform.Find("Panel/Version").GetComponent<Text>();
+        resVersion = transform.Find("Panel/ResVersion").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 (Application.platform == RuntimePlatform.Android)
         {
@@ -35,27 +65,56 @@
             imei0 = "MyTestGemBattle123";
         }
 
+        GameConfig.PlayerName = imei0;
+
+        versionTxt.text = "版本号:" + Application.version;
+        //resVersion.text 暂时没有使用
+        transform.Find("Panel/PlayerID").GetComponent<Text>().text = "玩家ID:" + imei0;
 
 
+        if (!GameConfig.isFirstStart)//后续直接加载
+        {
+            waitTime = 2f;
+
+            loginNext();
+        }
+        else
+        {
+            waitTime = 0f;
+            //第一次启动,初始化并且埋点
+            if (!GameConfig.useSDK)
+            {
+                TDAA_SDKManager.Ins.SDKInit(ChannelID.Gm.ToString());
+                TDAA_SDKManager.Ins.Statistics(1);//成功加载登陆界面的人数
+            }
+        }
     }
 
-    private void OnEnable()
+    /// <summary>
+    /// 开始游戏
+    /// </summary>
+    void loginNext()
     {
-        SocketEvent.Ins.Add<IMessage>((int)Opcode.LoginS2C, LoginS2C);
+        progressSlider.gameObject.SetActive(true);
+        startBtn.gameObject.SetActive(false);
 
+        AudioSourceManager.Ins.Play(AudioEnum.UI);
+        TDAA_SDKManager.Ins.Statistics(2);//埋点
+
+        GameConfig.isFirstStart = false;
+        StartCoroutine(loginMy());
     }
 
-    private void OnDestroy()
-    {
-        SocketEvent.Ins.Remove<IMessage>((int)Opcode.LoginS2C, LoginS2C);
 
-    }
 
     #region 获得安卓手机上的IMEI号
     public string imei0 = "";
     public string imei1 = "";
     public string meid = "";
 
+    /// <summary>
+    /// 已弃用
+    /// </summary>
     void GetetDeviceIMEI()
     {
         var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
@@ -82,184 +141,44 @@
     {
         if (!isLogining)
         {
-            AudioSourceManager.Ins.Play(AudioEnum.UI);
-            TDAA_SDKManager.Ins.Statistics(2);//埋点
-
-            //StartCoroutine(loginMy());
-            StartCoroutine(LoadScene());
-        }else{
-
-        }
-
-        //TDAA_SDKManager.Ins.Statistics(2);//埋点
-        //LoginRequest();
-    }
-
-    /// <summary>
-    /// 登录请求处理
-    /// </summary>
-    /// <param name="req"></param>
-    private void LoginRequest()
-    {
-        if (!isLogining)
-        {
-            Debug.Log("登录");
-            if (Application.platform == RuntimePlatform.WindowsEditor)
+            // CoderM: 在这里要使用SDK来进行登录了
+            if (GameConfig.useSDK)
             {
-                Debug.Log("编辑器直接登录");
-
-                //TDAA_SDKManager.Ins.Login();
-                //TDAA_SDKManager.Ins.Statistics(3);//埋点
-
-                //StartCoroutine(loginMy());
-                StartCoroutine(LoadScene());
-                return;
-            }
-
-            isLogining = true;
-            string url = GameConfig.IsDebug ? GameConfig.TestLoginUrl : GameConfig.LoginUrl;
-            JsonData data = new JsonData();
-            data["account"] = imei0;
-            data["password"] = "123456";
-            data["channelid"] = (int)ChannelID.Gm;
-            byte[] postBytes = System.Text.Encoding.Default.GetBytes(data.ToJson());
-            StartCoroutine(Post(url, postBytes));
-        }
-    }
-
-    IEnumerator Post(string url, byte[] postBytes)
-    {
-        UnityWebRequest request = UnityWebRequest.Post(url, "POST");
-        request.uploadHandler = new UploadHandlerRaw(postBytes);
-        request.downloadHandler = new DownloadHandlerBuffer();
-        request.SetRequestHeader("Content-Type", "application/json");
-        yield return request.SendWebRequest();
-
-        if (request.isDone)
-        {
-            string text = request.downloadHandler.text;
-            loginData = JsonMapper.ToObject(text);
-            if (loginData.Keys.Contains("errorcode"))
-            {
-                JsonData errorData = loginData["errorcode"];
-                isLogining = false;
-                CommonDebugHelper.DebugSocket(int.Parse(errorData.ToString()));
-
-                yield break;
-            }
-
-            if (!string.IsNullOrEmpty(text))
-            {
-                EventCenter.Ins.Add<bool>((int)KTGMGemClient.EventType.MasterSocketConnectResult, MasterSocketConnectSuccess);
-                MasterSocket.Ins.MasterIp = loginData["masterip"].ToString();
-                MasterSocket.Ins.MasterPort = int.Parse(loginData["masterport"].ToString());
-                MasterSocket.Ins.StartConnect();
-
-                // System.DateTime dt = GameUtils.GetTime(loginData["timestamp"].ToString());
-                // GameConfig.dateTime = dt;
-                // GameConfig.timeSpan = dt - System.DateTime.Now;
+                //设置login的回调
+                SDKCallBack.ins.setNextAction("login", loginNext);
+                SDKManager.ins.sdk.login();
             }
             else
             {
-                isLogining = false;
-                //UIManager.Instance.ShowWarningWind("没有登录数据返回,text:" + text);
-                //CommonDebugHelper.DebugError("--------------------- 没有登录数据返回 ---------------------text:" + text);
+                //没有使用SDK
+                loginNext();
             }
         }
         else
         {
-            isLogining = false;
-            //UIManager.Instance.ShowWarningWind(request.error);
 
-            //CommonDebugHelper.DebugError("登录失败 request.error" + request.error);
         }
     }
-
-    private void MasterSocketConnectSuccess(bool res)
-    {
-        if (res)
-        {
-            Login_C2S login = new Login_C2S();
-            login.Username = loginData["username"].ToString();
-            login.Channel = (int)ChannelID.Gm;
-            login.SessionKey = loginData["sessionKey"].ToString();
-            MasterSocket.Ins.SendMsg(Opcode.LoginC2S, login);
-        }
-        else
-        {
-            CommonDebugHelper.DebugError("Socket 链接失败了");
-        }
-    }
-
-    private void LoginS2C(IMessage msg)
-    {
-        Login_S2C login = (Login_S2C)msg;
-        if (login.Errorcode == 0)
-        {
-            Debug.Log("--------------------- 登录成功 ---------------------");
-            //UserDataMsg userData = login.Userdata;
-
-            //TDAA_SDKManager.Ins.Login();
-            //TDAA_SDKManager.Ins.Statistics(3);//埋点
-
-            //StartCoroutine(loginMy());
-            StartCoroutine(LoadScene());
-
-        }
-        else
-        {
-            CommonDebugHelper.DebugSocket(login.Errorcode);
-            isLogining = false;
-        }
-    }
-
-
-    IEnumerator LoadScene()
-    {
-        async = SceneManager.LoadSceneAsync(GameConfig.NextSceneName);
-        async.allowSceneActivation = true;
-        /*while (!async.isDone)
-        {
-            
-            if (async.progress < 0.9f)
-                progressValue = async.progress;
-            else
-                progressValue = 1.0f;
-            slider.value = progressValue;
-            progress.text = (int)(slider.value * 100) + " %";
-            
-            if (async.progress >= 0.89)
-            {
-                Debug.Log("进展时间分别是:" + async.progress + "," + totalTime);
-                if( totalTime >= 3.0f )
-                    async.allowSceneActivation = true;
-                
-                progress.text = "按任意键继续";
-                if (Input.anyKeyDown)
-                {
-                    async.allowSceneActivation = true;
-                }
-
-            }
-
-            //yield return null;
-        }*/
-        yield return null;
-    }
-
 
     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(GameConfig.NextSceneName);
+        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;
+            toProgress = (int)(op.progress * 100);
             while (displayProgress < toProgress)
             {
                 ++displayProgress;
+                progressSlider.value = displayProgress * 0.01f;
                 SetLoadingPercentage(displayProgress);
                 yield return new WaitForEndOfFrame();//ui渲染完成之后
             }
@@ -268,6 +187,8 @@
         while (displayProgress < toProgress)
         {
             ++displayProgress;
+            progressSlider.value = displayProgress * 0.01f;
+
             SetLoadingPercentage(displayProgress);
             yield return new WaitForEndOfFrame();
         }
@@ -278,8 +199,7 @@
 
     private void SetLoadingPercentage(int displayProgress)
     {
-        CommonDebugHelper.Debug($"当前进度{displayProgress}%");
-
+        //CommonDebugHelper.Debug($"当前进度{displayProgress}%");
     }
 
 }

--
Gitblit v1.9.1