This commit is contained in:
CortexCore
2024-07-15 17:26:08 +08:00
parent de0bae347d
commit e686eb89ab
4 changed files with 74 additions and 45 deletions

View File

@@ -53,6 +53,7 @@ namespace BITKit.Entities
/// </summary> /// </summary>
public interface IEntitiesService public interface IEntitiesService
{ {
/// <summary> /// <summary>
/// 当添加Entity时 /// 当添加Entity时
/// </summary> /// </summary>

View File

@@ -53,10 +53,14 @@ namespace BITKit
[SerializeField] private bool isOffline; [SerializeField] private bool isOffline;
[SerializeField] private bool IsEditorSimulateMode; [SerializeField] private bool IsEditorSimulateMode;
[UXBindPath("progress-bar")] [UXBindPath("progress-bar",true)]
private ProgressBar _progressBar; private ProgressBar _progressBar;
[UXBindPath("progress-fill",true)]
private VisualElement _progressFill;
[UXBindPath("progress-label")] [UXBindPath("progress-label")]
private Label _progressLabel; private Label _progressLabel;
private Action<float> _setProgressValue;
private async void Start() private async void Start()
{ {
try try
@@ -67,7 +71,16 @@ namespace BITKit
#endif #endif
UXUtils.Inject(this); UXUtils.Inject(this);
_progressBar.value=0f; if (_progressBar is not null)
{
_setProgressValue = value => _progressBar.value = value;
}else if (_progressFill is not null)
{
_setProgressValue = value =>
_progressFill.style.width = new Length() { value = value*100, unit = LengthUnit.Percent };
}
_setProgressValue?.Invoke(0f);
var stopwatch = new Stopwatch(); var stopwatch = new Stopwatch();
stopwatch.Start(); stopwatch.Start();
@@ -127,7 +140,8 @@ namespace BITKit
while (initOperation.IsDone is false) while (initOperation.IsDone is false)
{ {
await UniTask.NextFrame(destroyCancellationToken); await UniTask.NextFrame(destroyCancellationToken);
_progressBar.value =initOperation.Progress; //_progressBar.value =initOperation.Progress;
_setProgressValue?.Invoke(initOperation.Progress);
} }
try try
@@ -137,7 +151,8 @@ namespace BITKit
while (operation.IsDone is false) while (operation.IsDone is false)
{ {
await UniTask.NextFrame(destroyCancellationToken); await UniTask.NextFrame(destroyCancellationToken);
_progressBar.value = operation.Progress; //_progressBar.value = operation.Progress;
_setProgressValue?.Invoke(operation.Progress);
} }
@@ -167,7 +182,8 @@ namespace BITKit
while (frameworkHandle.IsDone is false) while (frameworkHandle.IsDone is false)
{ {
await UniTask.NextFrame(destroyCancellationToken); await UniTask.NextFrame(destroyCancellationToken);
_progressBar.value=frameworkHandle.Progress; //_progressBar.value=frameworkHandle.Progress;
_setProgressValue?.Invoke(frameworkHandle.Progress);
} }
var framework = Instantiate(frameworkHandle.AssetObject); var framework = Instantiate(frameworkHandle.AssetObject);

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using Cysharp.Threading.Tasks; using Cysharp.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements; using UnityEngine.UIElements;
// ReSharper disable MemberCanBeProtected.Global // ReSharper disable MemberCanBeProtected.Global
// ReSharper disable ClassWithVirtualMembersNeverInherited.Global // ReSharper disable ClassWithVirtualMembersNeverInherited.Global
@@ -31,6 +32,9 @@ namespace BITKit.UX
[Header(Constant.Header.Components)] [Header(Constant.Header.Components)]
[SerializeField] protected UIDocument document; [SerializeField] protected UIDocument document;
[Header(Constant.Header.Settings)]
[SerializeField, ReadOnly] private bool isActive;
[SerializeField,ReadOnly] private float currentOpacity;
[Header(Constant.Header.Settings)] [Header(Constant.Header.Settings)]
[SerializeField] private bool isWindow; [SerializeField] private bool isWindow;
[SerializeField] private bool isAnimate; [SerializeField] private bool isAnimate;
@@ -57,14 +61,14 @@ namespace BITKit.UX
protected virtual VisualElement background => document.rootVisualElement; protected virtual VisualElement background => document.rootVisualElement;
protected float CurrentOpacity protected float CurrentOpacity
{ {
get => background?.GetOpacity() ?? _currentOpacity; get => background?.GetOpacity() ?? currentOpacity;
set set
{ {
_currentOpacity = value; currentOpacity = value;
background?.SetOpacity(value); background?.SetOpacity(value);
} }
} }
private float _currentOpacity;
protected virtual void Awake() protected virtual void Awake()
{ {
cancellationToken = gameObject.GetCancellationTokenOnDestroy(); cancellationToken = gameObject.GetCancellationTokenOnDestroy();
@@ -121,6 +125,7 @@ namespace BITKit.UX
Debug.Log(gameObject.name); Debug.Log(gameObject.name);
throw; throw;
} }
isActive = true;
} }
async UniTask IEntryElement.EntryAsync() async UniTask IEntryElement.EntryAsync()
{ {
@@ -156,6 +161,7 @@ namespace BITKit.UX
void IEntryElement.Exited() void IEntryElement.Exited()
{ {
document.rootVisualElement.SetActive(false); document.rootVisualElement.SetActive(false);
isActive = false;
} }
public event Action OnEntry; public event Action OnEntry;

View File

@@ -120,6 +120,8 @@ namespace BITKit.UX
CurrentPanel = obj; CurrentPanel = obj;
} }
private void Update() private void Update()
{
try
{ {
while (RegistryQueue.TryDequeue(out var result)) while (RegistryQueue.TryDequeue(out var result))
{ {
@@ -155,7 +157,6 @@ namespace BITKit.UX
BITAppForUnity.AllowCursor.SetElements(this, nextPanel.AllowCursor); BITAppForUnity.AllowCursor.SetElements(this, nextPanel.AllowCursor);
BITInputSystem.AllowInput.SetElements(this, nextPanel.AllowInput); BITInputSystem.AllowInput.SetElements(this, nextPanel.AllowInput);
} }
if (EntryGroup.TryGetEntried(out var currentPanel)) if (EntryGroup.TryGetEntried(out var currentPanel))
{ {
currentPanel.OnUpdate(Time.deltaTime); currentPanel.OnUpdate(Time.deltaTime);
@@ -165,6 +166,11 @@ namespace BITKit.UX
windowPanel.OnUpdate(Time.deltaTime); windowPanel.OnUpdate(Time.deltaTime);
} }
} }
catch (Exception e)
{
BIT4Log.LogException(e);
}
}
void IUXService.Register(IUXPanel panel) => Register(panel); void IUXService.Register(IUXPanel panel) => Register(panel);