UI调整
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SLSUtilities.General
|
||||
@@ -9,47 +10,63 @@ namespace SLSUtilities.General
|
||||
public float duration;
|
||||
public float currentTime;
|
||||
public bool isInfinite;
|
||||
public bool keepActions;
|
||||
public float Percentage => duration > 0 ? Mathf.Clamp01(currentTime / duration) : 1f;
|
||||
public virtual bool IsCompleted => currentTime >= duration;
|
||||
public bool isCompleted;
|
||||
|
||||
public List<PrioritizedAction> onComplete;
|
||||
private IDisposable _autoObserver;
|
||||
|
||||
public Timer(float duration, bool isInfinite = false)
|
||||
public Timer(float duration, bool keepActions = true, bool isInfinite = false)
|
||||
{
|
||||
this.duration = duration;
|
||||
this.isInfinite = isInfinite;
|
||||
this.keepActions = keepActions;
|
||||
currentTime = 0f;
|
||||
onComplete = new List<PrioritizedAction>();
|
||||
}
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
{
|
||||
if (!IsCompleted)
|
||||
currentTime += deltaTime;
|
||||
|
||||
if (!isInfinite && !isCompleted && currentTime >= duration)
|
||||
{
|
||||
currentTime += deltaTime;
|
||||
isCompleted = true;
|
||||
onComplete.Invoke();
|
||||
if (!keepActions)
|
||||
{
|
||||
onComplete.Clear();
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (isInfinite)
|
||||
{
|
||||
if (!isInfinite)
|
||||
{
|
||||
onComplete.Invoke();
|
||||
onComplete.Clear(); // 确保只调用一次
|
||||
}
|
||||
else
|
||||
{
|
||||
onComplete.Invoke();
|
||||
Reset();
|
||||
}
|
||||
onComplete.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Reset(float newDuration = -1f)
|
||||
{
|
||||
isCompleted = false;
|
||||
currentTime = 0f;
|
||||
if(newDuration >= 0f)
|
||||
{
|
||||
duration = newDuration;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Complete(bool invokeAction = true)
|
||||
{
|
||||
currentTime = duration;
|
||||
isCompleted = true;
|
||||
if (invokeAction)
|
||||
{
|
||||
onComplete.Invoke();
|
||||
if (!keepActions)
|
||||
{
|
||||
onComplete.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user