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

52 lines
1.5 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.InputSystem;
using BITKit;
using BITKit.UX;
using BITKit.Entities;
using BITKit.SceneManagement;
namespace BITFALL.UX
{
public class UXLoading : UIToolKitPanel
{
[Header(Constant.Header.Providers)]
[SerializeReference, SubclassSelector] private ISceneService sceneService;
[SerializeReference, SubclassSelector] private INetProvider netProvider;
[Header(Constant.Header.Components)]
[SerializeField] private UXBar loadBar;
[SerializeField] private UXLabel loadText;
[SerializeField] private UXLabel mapLabel;
[SerializeField] private UXElement blackScreen;
protected override VisualElement background => null;
protected override void Awake()
{
base.Awake();
sceneService.OnLoadScene += Load;
sceneService.OnSceneLoadProgress += OnLoadProgress;
}
private void Load(string obj)
{
mapLabel.Set(obj);
loadBar.SetDirect(0,$"正在开始加载:{obj}");
Entry();
}
private void OnLoadProgress(string s, float f)
{
loadBar.Set(f);
loadText.Set(s);
}
public override void OnUpdate(float deltaTime)
{
base.OnUpdate(deltaTime);
blackScreen.GetVisualElement().SetOpacity(
TargetOpacity is 0 ? 1-CurrentOpacity : 0);
}
}
}