BITFALL/Assets/Artists/Scripts/UX/UXLoading.cs

52 lines
1.5 KiB
C#
Raw Normal View History

2023-08-23 01:59:40 +08:00
using System;
2023-06-08 14:09:50 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.InputSystem;
using BITKit;
using BITKit.UX;
using BITKit.Entities;
2023-10-20 19:31:12 +08:00
using BITKit.SceneManagement;
2023-06-08 14:09:50 +08:00
namespace BITFALL.UX
{
2023-10-20 19:31:12 +08:00
public class UXLoading : UIToolKitPanel
2023-06-08 14:09:50 +08:00
{
2023-06-17 16:30:53 +08:00
[Header(Constant.Header.Providers)]
2023-11-15 23:54:54 +08:00
[SerializeReference, SubclassSelector] private ISceneService sceneService;
[SerializeReference, SubclassSelector] private INetProvider netProvider;
2023-06-17 16:30:53 +08:00
[Header(Constant.Header.Components)]
2023-11-15 23:54:54 +08:00
[SerializeField] private UXBar loadBar;
[SerializeField] private UXLabel loadText;
[SerializeField] private UXLabel mapLabel;
[SerializeField] private UXElement blackScreen;
protected override VisualElement background => null;
2023-08-23 01:59:40 +08:00
protected override void Awake()
2023-06-08 14:09:50 +08:00
{
2023-08-23 01:59:40 +08:00
base.Awake();
2023-10-20 19:31:12 +08:00
sceneService.OnLoadScene += Load;
sceneService.OnSceneLoadProgress += OnLoadProgress;
2023-08-23 01:59:40 +08:00
}
2023-08-12 01:43:24 +08:00
2023-10-20 19:31:12 +08:00
private void Load(string obj)
2023-06-08 14:09:50 +08:00
{
2023-11-15 23:54:54 +08:00
mapLabel.Set(obj);
2023-10-20 19:31:12 +08:00
loadBar.SetDirect(0,$"正在开始加载:{obj}");
2023-08-23 01:59:40 +08:00
Entry();
2023-06-08 14:09:50 +08:00
}
2023-10-20 19:31:12 +08:00
private void OnLoadProgress(string s, float f)
2023-06-08 14:09:50 +08:00
{
2023-10-20 19:31:12 +08:00
loadBar.Set(f);
loadText.Set(s);
2023-06-08 14:09:50 +08:00
}
2023-11-15 23:54:54 +08:00
public override void OnUpdate(float deltaTime)
{
base.OnUpdate(deltaTime);
blackScreen.GetVisualElement().SetOpacity(
TargetOpacity is 0 ? 1-CurrentOpacity : 0);
}
2023-06-08 14:09:50 +08:00
}
}