Skip to content

Commit 01da886

Browse files
committed
feat: TimeUtility RemoveTimer & HasTimer
1 parent a392aed commit 01da886

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Editor/EditorUtilities/UIToolkitEditorUtility.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#if UNITY_2019_4_OR_NEWER
2-
using System;
32
using UnityEditor;
43
using UnityEngine;
54
using UnityEngine.UIElements;
@@ -30,7 +29,7 @@ public static void CloneTreeAndApplyStyle(VisualElement target, string path)
3029
Debug.LogError($"Failed to load VisualTreeAsset at path: {uxmlPath}");
3130
return;
3231
}
33-
32+
3433
visualTree.CloneTree(target);
3534
ApplyStyle(target, path);
3635
}
@@ -63,7 +62,7 @@ internal static void ApplyStyleForInternalControl<T>(T target) where T : VisualE
6362
var name = typeof(T).Name;
6463
ApplyStyleForInternalControl(target, name);
6564
}
66-
65+
6766
internal static void ApplyStyleForInternalControl(VisualElement target, string name)
6867
{
6968
ApplyStyle(target, $"{FoundationPackage.UIToolkitControlsPath}/{name}/{name}");

Runtime/Utilities/TimeUtility.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,34 @@ public static class TimeUtility
1414
/// Start new timer, with given name.
1515
/// You can check timer second value via <see cref="GetTime"/> method.
1616
/// </summary>
17-
/// <param name="name">Timer name.</param>
17+
/// <param name="name">The name of the timer.</param>
1818
public static void StartTimer(string name)
1919
{
2020
s_Timers[name] = DateTime.Now.Ticks;
2121
}
2222

23+
/// <summary>
24+
/// Removes timer from timers list.
25+
/// </summary>
26+
/// <param name="name">The name of the timer.</param>
27+
public static void RemoveTimer(string name) {
28+
s_Timers.Remove(name);
29+
}
30+
31+
/// <summary>
32+
/// Method allows if time with specified name exists.
33+
/// </summary>
34+
/// <param name="name">The name of the timer.</param>
35+
/// <returns>`true` if timer exists and `false` otherwise.</returns>
36+
public static bool HasTimer(string name) {
37+
return s_Timers.ContainsKey(name);
38+
}
39+
2340
/// <summary>
2441
/// Get timer value in seconds by timer name. You may star any number of timers using the <see cref="StartTimer"/> method.
2542
/// If timer with specified name doesn't exist `0` value will be returned.
2643
/// </summary>
27-
/// <param name="name">Timer name.</param>
44+
/// <param name="name">The name of the timer.</param>
2845
/// <returns>Timer value in seconds</returns>
2946
public static float GetTime(string name)
3047
{
@@ -37,7 +54,6 @@ public static float GetTime(string name)
3754
return 0f;
3855
}
3956

40-
4157
/// <summary>
4258
/// Converts a UNIX time stamp into <see cref="DateTime"/> object.
4359
/// </summary>

0 commit comments

Comments
 (0)