-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Timer manager, function to easily get icon from sprite
- Loading branch information
Showing
11 changed files
with
192 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using RicUtils.Managers; | ||
using RicUtils.Utilities; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
|
||
namespace RicUtils | ||
{ | ||
public class TimerManager : SingletonGenericManager<TimerManager> | ||
{ | ||
private List<GameTimer> timers = new List<GameTimer>(); | ||
|
||
public GameTimer CreateTimer(float timer, bool repeat = true) | ||
{ | ||
GameTimer gameTimer = new GameTimer(timer, repeat); | ||
|
||
timers.Add(gameTimer); | ||
|
||
return gameTimer; | ||
} | ||
|
||
private void Update() | ||
{ | ||
timers.RemoveAll(g => g == null); | ||
|
||
foreach(var timer in timers) | ||
{ | ||
timer.Update(); | ||
} | ||
|
||
timers.RemoveAll(g => g.ended); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/RicUtils/Runtime/Scripts/Managers/TimerManager.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace RicUtils.Utilities | ||
{ | ||
public sealed class GameTimer | ||
{ | ||
public bool Repeat { get; set; } | ||
|
||
public float Timer { get; set; } | ||
|
||
internal bool ended; | ||
|
||
private bool started; | ||
|
||
private float time; | ||
|
||
public bool Paused => !started; | ||
|
||
public event System.Action onTick; | ||
|
||
internal GameTimer(float timer, bool repeat) | ||
{ | ||
Timer = timer; | ||
Repeat = repeat; | ||
} | ||
|
||
internal void Update() | ||
{ | ||
if(ended || !started) return; | ||
|
||
time += Time.deltaTime; | ||
if(time >= Timer) | ||
{ | ||
onTick?.Invoke(); | ||
if(!Repeat) ended = true; | ||
time -= Timer; | ||
} | ||
} | ||
|
||
public void Start() | ||
{ | ||
started = true; | ||
time = 0; | ||
} | ||
|
||
public void Pause() | ||
{ | ||
started = false; | ||
} | ||
|
||
public void Unpause() | ||
{ | ||
started = true; | ||
} | ||
|
||
public void Remove() | ||
{ | ||
ended = true; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/RicUtils/Runtime/Scripts/Utilities/GameTimer.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