Cute_demon_attacks/meng_yao/Assets/script/ConnactServer/Logo_in.cs
2024-11-11 12:04:41 +08:00

212 lines
7.7 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 System.Collections;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Logo_in : mount
{
public Slider sceneslider;
public Button logo_inbtn;
public float loadSpeed = 0.5f; // 填充速度
public float timerDuration = 2f; // 剩余30%进度的时间
public float smoothingSpeed = 0.1f;
public override void Awake()
{
}
// Start is called before the first frame update
void Start()
{
//sceneslider.gameObject.SetActive(false);
//logo_inbtn.onClick.AddListener(ShowLogoin);
if (sceneslider != null)
{
sceneslider.value = 0f; // 初始值设为0
}
Privacy_Policy_screen();
}
public void Privacy_Policy_screen()
{
List<BoxType> boxTypes = new List<BoxType>();
boxTypes.Add(new BoxType { Name = "", prompt = "", Type = 9, widthnum = 700, WidthHeight = 650, content = "在您使用我们(萌妖)服务前,请您务必审慎阅读、充分理解腾讯游戏用户协议隐私保护指引和儿童隐私保护指引的各条款,了解我们对您个人信息的处理规则。同时,您应特别注意前述协议中免除或者限制我们责任的条款、对您权利进行限制的条款、约定争议解决方式和司法管辖的条款。如您已详细阅读并同意 萌妖出击游戏用户协议、隐私保护指引和儿童隐私保护指引,请点击“同意”开始使用我们的服务。" });
boxTypes.Add(new BoxType {Name = "submit", textName = " 取消确定 ", Type = 12 });
GameObject gameObject = add_pop_up(true);//生成弹窗母体
List<GameObject> gameObjects = gameObject.GetComponent<input_box_pop_up_window>().updateUI(boxTypes, "用户协议和隐私保护指引");//测试输入框回调处理
gameObjects[1].GetComponent<input_box_pop_up_window_item>().register_click(async (BoxType boxType, int type) =>//登录确定或取消
{
if (type == 0)
{
}
else if (type == 1)
{
login_in_screen();
gameObject.GetComponent<input_box_pop_up_window>().destroy();
}
});
}
public void Real_name_screen()
{
List<BoxType> boxTypes = new List<BoxType>();
boxTypes.Add(new BoxType { Name = "", prompt = "", Type = 9, widthnum = 700, WidthHeight = 650, content = "在您使用我们(萌妖)服务前,请您务必审慎阅读、充分理解腾讯游戏用户协议隐私保护指引和儿童隐私保护指引的各条款,了解我们对您个人信息的处理规则。同时,您应特别注意前述协议中免除或者限制我们责任的条款、对您权利进行限制的条款、约定争议解决方式和司法管辖的条款。如您已详细阅读并同意 萌妖出击游戏用户协议、隐私保护指引和儿童隐私保护指引,请点击“同意”开始使用我们的服务。" });
boxTypes.Add(new BoxType { Name = "submit", textName = " 取消确定 ", Type = 12 });
GameObject gameObject = add_pop_up(true);//生成弹窗母体
List<GameObject> gameObjects = gameObject.GetComponent<input_box_pop_up_window>().updateUI(boxTypes, "实名认证");//测试输入框回调处理
}
public void login_in_screen()//登录界面
{
List<BoxType> boxTypes = new List<BoxType>();
boxTypes.Add(new BoxType { Name = "account_number", textName = " 手机号", prompt = "请输入手机号", Type = 1, is_required = true });
boxTypes.Add(new BoxType { Name = "verification_code", textName = " 验证码", prompt = "请输入验证码", Type = 0, is_required = true });
boxTypes.Add(new BoxType { Name = "submit", textName = " 取消确定 ", Type = 5 });
GameObject gameObject = add_pop_up(true);//生成弹窗母体
List<GameObject> gameObjects = gameObject.GetComponent<input_box_pop_up_window>().updateUI(boxTypes, "登录");//测试输入框回调处理
//gameObjects[0].GetComponent<input_box_pop_up_window_item>().register_click((BoxType boxType, int type) =>//手机号获取验证码点击
//{
// if (boxType.is_required && string.IsNullOrWhiteSpace(boxType.content))
// {
// Promptmgr.Instance.PromptBubble("请不要" + boxType.textName + "为空");
// return;
// }
// Debug.Log("获取验证码");
//});
gameObjects[2].GetComponent<input_box_pop_up_window_item>().register_click(async (BoxType boxType, int type) =>//登录确定或取消
{
if (type == 0)//注册
{
//Login login = new Login();
//login.Phone = boxTypes[0].content;
////register.Code = boxTypes[0].content;
//string jsonString = JsonUtility.ToJson(login);
//string response = await web.SendRequest(web.URL+"/Player/Register", "POST", jsonString);
//Debug.Log(response);
}
else if (type == 1)//登录
{
//Login login = new Login();
//login.Phone = boxTypes[0].content;
//Debug.Log(boxTypes[0].content);
////register.Code = boxTypes[0].content;
//string jsonString = JsonUtility.ToJson(login);
//string response = await web.SendRequest(web.URL+"/Player/Login", "POST", jsonString);
//Debug.Log(response);
//Rootobject root = JsonUtility.FromJson<Rootobject>(response);
//if (root.ErrorMessage=="" && boxTypes[0].content!= "")
//{
// gameObject.SetActive(false);
// Promptmgr.Instance.PromptBubble("登录成功");
// isLoading = true;
//}
//else
//{
// Promptmgr.Instance.PromptBubble("登录失败,请先注册");
//}
gameObject.SetActive(false);
Promptmgr.Instance.PromptBubble("登录成功");
StartCoroutine(LoadSceneWithProgress());
}
});
}
IEnumerator LoadSceneWithProgress()
{
// 异步加载场景
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(JumpScene.main_scene);
// 确保加载完毕前场景不会自动切换
asyncLoad.allowSceneActivation = false;
float displayProgress = 0f;
// 当场景未加载完成时,持续更新进度条
while (!asyncLoad.isDone)
{
// 获取加载进度将异步加载进度映射到0-0.7范围内
float targetProgress = Mathf.Clamp01(asyncLoad.progress / 0.9f) * 0.7f;
// 平滑推进进度条显示
displayProgress = Mathf.MoveTowards(displayProgress, targetProgress, smoothingSpeed * Time.deltaTime);
sceneslider.value = displayProgress;
// 强制刷新UI
yield return new WaitForSeconds(0.02f); // 等待更短的时间确保UI更新
// 当异步加载到90%,开启计时器
if (asyncLoad.progress >= 0.9f)
{
StartCoroutine(CompleteProgressWithTimer(asyncLoad));
yield break;
}
}
}
IEnumerator CompleteProgressWithTimer(AsyncOperation asyncLoad)
{
float elapsedTime = 0f;
float startProgress = 0.7f;
float targetProgress = 1f;
while (elapsedTime < timerDuration)
{
elapsedTime += Time.deltaTime;
float newProgress = Mathf.Lerp(startProgress, targetProgress, elapsedTime / timerDuration);
sceneslider.value = newProgress;
yield return new WaitForSeconds(0.02f); // 控制刷新频率
}
// 确保进度条达到100%
sceneslider.value = 1f;
yield return new WaitForSeconds(0.5f); // 短暂延迟后允许场景切换
asyncLoad.allowSceneActivation = true;
}
}
public class Rootobject
{
public int ErrorCode;
public string ErrorMessage;
}
public class JsonParser
{
public static Rootobject ParseJson(string json)
{
return JsonUtility.FromJson<Rootobject>(json);
}
}