Skip to content

Commit 8abf721

Browse files
committed
Added support for ServiceKit
1 parent 45316a8 commit 8abf721

10 files changed

Lines changed: 175 additions & 7 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
## [0.4.1] - Aug 20, 2025
4+
- Added ServiceKit support
5+
36
## [0.4.0] - Aug 20, 2025
47
- No longer in beta
58

Runtime/Extensions/ServiceKit.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System;
2+
using Nonatomic.ServiceKit;
3+
4+
#if TIMERS_SERVICE_KIT
5+
6+
namespace Nonatomic.Timers.Extensions.ServiceKit
7+
{
8+
public interface IBaseTimerService : ITimer
9+
{
10+
11+
}
12+
13+
public abstract class BaseTimerService<T> : ServiceKitBehaviour<T> where T : class, IBaseTimerService
14+
{
15+
public float Duration
16+
{
17+
get => Timer.Duration;
18+
set => Timer.Duration = value;
19+
}
20+
21+
public bool IsRunning => Timer.IsRunning;
22+
public float TimeRemaining => Timer.TimeRemaining;
23+
public float TimeElapsed => Timer.TimeElapsed;
24+
public float ProgressElapsed => Timer.ProgressElapsed;
25+
public float ProgressRemaining => Timer.ProgressRemaining;
26+
27+
protected ITimer Timer;
28+
29+
private Action _onCompleteHandler;
30+
private Action _onResumeHandler;
31+
32+
private Action _onStartHandler;
33+
private Action _onStopHandler;
34+
private Action<IReadOnlyTimer> _onTickHandler;
35+
36+
protected override void OnDestroy()
37+
{
38+
if (Registered && Timer != null)
39+
{
40+
Timer.OnStart -= _onStartHandler;
41+
Timer.OnResume -= _onResumeHandler;
42+
Timer.OnComplete -= _onCompleteHandler;
43+
Timer.OnStop -= _onStopHandler;
44+
Timer.OnTick -= _onTickHandler;
45+
}
46+
47+
base.OnDestroy();
48+
}
49+
50+
public event Action OnStart;
51+
public event Action OnComplete;
52+
public event Action OnResume;
53+
public event Action OnStop;
54+
public event Action<IReadOnlyTimer> OnTick;
55+
56+
public float TimeByType(TimeType type)
57+
{
58+
return Timer.TimeByType(type);
59+
}
60+
61+
public void StartTimer()
62+
{
63+
Timer.StartTimer();
64+
}
65+
66+
public void ResumeTimer()
67+
{
68+
Timer.ResumeTimer();
69+
}
70+
71+
public void StopTimer()
72+
{
73+
Timer.StopTimer();
74+
}
75+
76+
public void ResetTimer()
77+
{
78+
Timer.ResetTimer();
79+
}
80+
81+
public void FastForward(float seconds)
82+
{
83+
Timer.FastForward(seconds);
84+
}
85+
86+
public void Rewind(float seconds)
87+
{
88+
Timer.Rewind(seconds);
89+
}
90+
91+
public void AddMilestone(TimerMilestone milestone)
92+
{
93+
Timer.AddMilestone(milestone);
94+
}
95+
96+
public void RemoveMilestone(TimerMilestone milestone)
97+
{
98+
Timer.RemoveMilestone(milestone);
99+
}
100+
101+
public void RemoveAllMilestones()
102+
{
103+
Timer.RemoveAllMilestones();
104+
}
105+
106+
public void RemoveMilestonesByCondition(Predicate<TimerMilestone> condition)
107+
{
108+
Timer.RemoveMilestonesByCondition(condition);
109+
}
110+
111+
public TimerRangeMilestone AddRangeMilestone(TimeType timeType, float min, float max, float interval, Action action)
112+
{
113+
return Timer.AddRangeMilestone(timeType, min, max, interval, action);
114+
}
115+
116+
protected override void InitializeService()
117+
{
118+
Timer ??= gameObject.AddComponent<Timer>();
119+
120+
_onStartHandler = () => OnStart?.Invoke();
121+
_onResumeHandler = () => OnResume?.Invoke();
122+
_onCompleteHandler = () => OnComplete?.Invoke();
123+
_onStopHandler = () => OnStop?.Invoke();
124+
_onTickHandler = timer => OnTick?.Invoke(timer);
125+
126+
Timer.OnStart += _onStartHandler;
127+
Timer.OnResume += _onResumeHandler;
128+
Timer.OnComplete += _onCompleteHandler;
129+
Timer.OnStop += _onStopHandler;
130+
Timer.OnTick += _onTickHandler;
131+
}
132+
}
133+
}
134+
#endif

Runtime/Extensions/ServiceKit/BaseTimerService.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#if TIMERS_SERVICE_KIT
2+
3+
namespace Nonatomic.Timers.Extensions.ServiceKit
4+
{
5+
public interface ITimerService : IBaseTimerService
6+
{
7+
8+
}
9+
10+
public class TimerService : BaseTimerService<ITimerService>, ITimerService
11+
{
12+
13+
}
14+
}
15+
16+
#endif

Runtime/Extensions/ServiceKit/TimerService.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Extensions/ServiceLocator/BaseTimerService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#if SERVICE_LOCATOR
1+
#if TIMERS_SERVICE_LOCATOR
22

33
using System;
44
using Nonatomic.ServiceLocator;
55
using UnityEngine;
66

77
namespace Nonatomic.Timers.Extensions.ServiceLocator
88
{
9-
public interface IBaseTimerService
9+
public interface IBaseTimerService : ITimer
1010
{
1111

1212
}

Runtime/Extensions/ServiceLocator/TimerService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#if SERVICE_LOCATOR
1+
#if TIMERS_SERVICE_LOCATOR
22

33
namespace Nonatomic.Timers.Extensions.ServiceLocator
44
{
5-
public interface ITimerService : IBaseTimerService, ITimer
5+
public interface ITimerService : IBaseTimerService
66
{
77

88
}

Runtime/com.nonatomic.timers.runtime.asmdef

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "com.nonatomic.timers.runtime",
33
"rootNamespace": "Nonatomic.Timers",
44
"references": [
5-
"GUID:d8c8bb452aae45acbab36298ba796881"
5+
"GUID:d8c8bb452aae45acbab36298ba796881",
6+
"GUID:1b0144b25b4099e45a5beb8f8f7bee63"
67
],
78
"includePlatforms": [],
89
"excludePlatforms": [],
@@ -15,7 +16,12 @@
1516
{
1617
"name": "com.nonatomic.servicelocator",
1718
"expression": "0.5.0",
18-
"define": "SERVICE_LOCATOR"
19+
"define": "TIMERS_SERVICE_LOCATOR"
20+
},
21+
{
22+
"name": "com.nonatomic.servicekit",
23+
"expression": "1.3.3",
24+
"define": "TIMERS_SERVICE_KIT"
1925
}
2026
],
2127
"noEngineReferences": false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.nonatomic.timers",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"displayName": "Timers",
55
"description": "Timers",
66
"unity": "2022.3",

0 commit comments

Comments
 (0)