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

70 lines
2.0 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;
2024-04-26 03:55:43 +08:00
[Inject]
private IUXWaiting _waiting;
private IUXWaitingHandle _waitingHandle;
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;
2024-04-26 03:55:43 +08:00
sceneService.OnUnloadScene += OnUnloadScene;
sceneService.OnSceneUnloaded += OnSceneUnloaded;
}
protected override void Start()
{
base.Start();
DI.Inject(this);
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
}
2024-04-26 03:55:43 +08:00
private void OnSceneUnloaded(string obj)
{
if (_waitingHandle is not null)
{
_waiting.Release(_waitingHandle);
}
}
private void OnUnloadScene(string obj)
{
if(_waiting is null)return;
_waitingHandle = _waiting.Get();
_waitingHandle.SetMessage("正在返回主场景");
}
2023-06-08 14:09:50 +08:00
}
}