ict.shenzhi/Assets/Scripts/UIManager/Panel/LoadingPanel.cs

185 lines
8.6 KiB
C#
Raw Permalink 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 UnityEngine;
using UnityEngine.UI;
using TMPro;
using static LoginSceneUIManager;
using UnityEngine.SceneManagement;
/// <summary>
/// 加载中面板
/// </summary>
public class LoadingPanel : PanelBasic
{
public RectTransform loading_slider;
public Image loading_fill_image;
public Image loading_handle_image;
public Image loading_ring_image;
public TextMeshProUGUI loading_text;
float timer;
// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
if (timer < 0.5f)
{
loading_text.text = "场景加载中.";
}
else if (timer > 0.5f && timer < 1)
{
loading_text.text = "场景加载中..";
}
else if (timer > 0.5f && timer < 1)
{
loading_text.text = "场景加载中...";
}
loading_ring_image.rectTransform.Rotate(new Vector3(0, 0, -360) * Time.deltaTime);
loading_handle_image.rectTransform.Rotate(new Vector3(0, 0, -360) * Time.deltaTime);
loading_fill_image.fillAmount = async_load.load_progress / 100;
loading_handle_image.rectTransform.anchoredPosition = new Vector2(async_load.load_progress / 100 * loading_slider.rect.width, 0);
}
protected override void OnEnable()
{
base.OnEnable();
async_load ??= new AsyncLoad();
//StartCoroutine(async_load.AsyncLoadScene("UIScene",true));
SceneManager.LoadSceneAsync("UIScene", LoadSceneMode.Additive).completed += (_async) =>
{
//暂时将自由编程和课程任务区分
if (GameManager.current_main_menu_type.Equals(MainMenuType.))
{
var _handle_scene_name = GameManager.current_scene = current_preselect_scene;
//加载UI及相机场景加载完毕后根据对应场景数据更新相机位置及角度
var scene_detail_data = GameManager.scene_detail_datas.Find(x => x.scene_name.Equals(GameManager.current_scene));
if (scene_detail_data != null)
{
Debug.Log("场景加载完成");
var _position = scene_detail_data.init_position.Split(',');
var _rotation = scene_detail_data.init_rotation.Split(',');
//UIScene.instance.camera_move.SetTransform(new Vector3(float.Parse(_position[0]), float.Parse(_position[1]), float.Parse(_position[2])),
// new Vector3(float.Parse(_rotation[0]), float.Parse(_rotation[1]), float.Parse(_rotation[2])));
UIScene.Instance.camera_init_position = new Vector3(float.Parse(_position[0]), float.Parse(_position[1]), float.Parse(_position[2]));
UIScene.Instance.camera_init_rotation = new Vector3(float.Parse(_rotation[0]), float.Parse(_rotation[1]), float.Parse(_rotation[2])).ToQuaternion();
}
GameManager.current_scene_time = "昼";
switch (current_preselect_scene)
{
case "深圳市民中心":
_handle_scene_name += "_昼";
UIScene.Instance.camera_move.XLimit = new Vector2(-200, 500);
UIScene.Instance.camera_move.YLimit = new Vector2(3, 120);
UIScene.Instance.camera_move.ZLimit = new Vector2(-300, 300);
break;
case "西丽湖校区":
_handle_scene_name += "_昼";
UIScene.Instance.camera_move.XLimit = new Vector2(-100, 100);
UIScene.Instance.camera_move.YLimit = new Vector2(1, 100);
UIScene.Instance.camera_move.ZLimit = new Vector2(-100, 100);
break;
case "机器人舞台":
UIScene.Instance.camera_move.XLimit = new Vector2(-23, 19);
UIScene.Instance.camera_move.YLimit = new Vector2(0.5f, 5);
UIScene.Instance.camera_move.ZLimit = new Vector2(-20, -5);
break;
case "数字人舞台":
UIScene.Instance.camera_move.XLimit = new Vector2(-200, 500);
UIScene.Instance.camera_move.YLimit = new Vector2(3, 120);
UIScene.Instance.camera_move.ZLimit = new Vector2(-300, 300);
break;
default:
break;
}
SceneOverlayManager.Instance.LoadSceneAsync(_handle_scene_name, true, (_async) =>
{
var _component = "";
switch (GameManager.current_component_type)
{
case ComponentType.:
_component = "无人机";
break;
case ComponentType.:
_component = "机器人";
break;
case ComponentType.:
_component = "数字人";
break;
default:
break;
}
_component = string.Format("{0}组件控制器", _component);
SceneOverlayManager.Instance.LoadSceneAsync(_component, false);
SceneManager.UnloadSceneAsync("LoginScene");
});
}
else
{
//任务和案例一样加载
var _position = CallForTest.instance.currentTaskData.scene_formdtoslist.cameraPosition.Split(',');
var _rotation = CallForTest.instance.currentTaskData.scene_formdtoslist.cameraAngle.Split(',');
UIScene.Instance.camera_init_position = new Vector3(float.Parse(_position[0]), float.Parse(_position[1]), float.Parse(_position[2]));
UIScene.Instance.camera_init_rotation = new Vector3(float.Parse(_rotation[0]), float.Parse(_rotation[1]), float.Parse(_rotation[2])).ToQuaternion();
var _ax = CallForTest.instance.currentTaskData.scene_formdtoslist.cameraScopeX.Split(",");
var _ay = CallForTest.instance.currentTaskData.scene_formdtoslist.cameraScopeY.Split(",");
var _az = CallForTest.instance.currentTaskData.scene_formdtoslist.cameraScopeZ.Split(",");
UIScene.Instance.camera_move.XLimit = new Vector2(float.Parse(_ax[0]), float.Parse(_ax[1]));
UIScene.Instance.camera_move.YLimit = new Vector2(float.Parse(_ay[0]), float.Parse(_ay[1]));
UIScene.Instance.camera_move.ZLimit = new Vector2(float.Parse(_az[0]), float.Parse(_az[1]));
GameManager.current_scene_time = "昼";
SceneOverlayManager.Instance.LoadSceneAsync(current_preselect_scene, true, (_async) =>
{
var _component = "";
switch (GameManager.current_component_type)
{
case ComponentType.:
_component = "无人机";
break;
case ComponentType.:
_component = "机器人";
break;
case ComponentType.:
_component = "数字人";
break;
default:
break;
}
_component = string.Format("{0}组件控制器", _component);
SceneOverlayManager.Instance.LoadSceneAsync(_component, false);
//根据LoginScene是否加载判断是否为启动器启动
//if (SceneManager.GetSceneByName("LoginScene").isLoaded)
// SceneManager.UnloadSceneAsync("LoginScene");
//else
//{
// SceneManager.UnloadSceneAsync("InitScene");
// SceneManager.UnloadSceneAsync("LoadingScene");
//}
if (SceneManager.GetSceneByName("LoginScene").isLoaded)
SceneManager.UnloadSceneAsync("LoginScene");
if(SceneManager.GetSceneByName("InitScene").isLoaded)
SceneManager.UnloadSceneAsync("InitScene");
if (SceneManager.GetSceneByName("LoadingScene").isLoaded)
SceneManager.UnloadSceneAsync("LoadingScene");
});
}
};
return;
StartCoroutine(async_load.AsyncLoadScene(current_preselect_scene, true));
}
}