generated from kurone-kito/vpm-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added the abstracted interval logic
- Loading branch information
1 parent
f4351c9
commit cca1088
Showing
4 changed files
with
97 additions
and
75 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
Packages/black.kit.toybox/Runtime/Scripts/UI/IntervalBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using UdonSharp; | ||
using UnityEngine; | ||
|
||
namespace black.kit.toybox | ||
{ | ||
/// <summary>The base class of the interval logic.</summary> | ||
[UdonBehaviourSyncMode(BehaviourSyncMode.None)] | ||
public abstract class IntervalBase : UdonSharpBehaviour | ||
{ | ||
/// <summary>The safe minimum interval.</summary> | ||
private const float SAFE_MIN_INTERVAL = 0.01f; | ||
|
||
/// <summary>The warning of the null.</summary> | ||
private const string WARN_NULL = "Some inspector values is null."; | ||
|
||
/// <summary>The interval of the progress.</summary> | ||
/// <remarks>It ignores less than 0.01f.</remarks> | ||
[SerializeField, Range(SAFE_MIN_INTERVAL, 60f)] | ||
[Tooltip("Specifies the interval of the progress")] | ||
private float interval = 1f; | ||
|
||
/// <summary>The interval of the progress.</summary> | ||
public float Interval => interval; | ||
|
||
/// <summary>Update the view of the UI.</summary> | ||
public void InternalUpdateView() | ||
{ | ||
UpdateView(); | ||
var safeInterval = Mathf.Max(Interval, SAFE_MIN_INTERVAL); | ||
SendCustomEventDelayedSeconds(nameof(InternalUpdateView), safeInterval); | ||
} | ||
|
||
/// <summary>Update the view of the UI.</summary> | ||
[ContextMenu("Update view")] | ||
public abstract void UpdateView(); | ||
|
||
/// <summary>Validate the inspector.</summary> | ||
/// <returns>Whether the inspectors are valid.</returns> | ||
protected abstract bool ValidateInspector(); | ||
|
||
/// <summary>The callback when the object is initialized.</summary> | ||
protected virtual void Start() | ||
{ | ||
if (!ValidateInspector()) | ||
{ | ||
Debug.LogWarning(WARN_NULL); | ||
return; | ||
} | ||
SendCustomEventDelayedFrames(nameof(InternalUpdateView), 1); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/black.kit.toybox/Runtime/Scripts/UI/IntervalBase.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters