Skip to content

Commit 7fdb69b

Browse files
Init
1 parent a1b75b5 commit 7fdb69b

37 files changed

+2460
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Assets/AssetStoreTools*
77

88
# Visual Studio cache directory
99
.vs/
10+
.vscode/
1011

1112
# Autogenerated VS/MD/Consulo solution and project files
1213
ExportedObj/

Assets/BartInTheField.Timer.unitypackage.meta

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

Assets/BartInTheField.meta

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

Assets/BartInTheField/BartInTheField.Timer.meta

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

Assets/BartInTheField/BartInTheField.Timer/Editor.meta

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

Assets/BartInTheField/BartInTheField.Timer/Editor/Icons.meta

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

Assets/BartInTheField/BartInTheField.Timer/Editor/Icons/Timer.png.meta

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
namespace BartInTheField.Timer
7+
{
8+
public class Timer : MonoBehaviour
9+
{
10+
public event Action OnTimeout = delegate { };
11+
public event Action<float> OnTimeChanged = delegate { };
12+
13+
[SerializeField] private float startTime = 1f;
14+
[SerializeField] private bool loop = false;
15+
[SerializeField] private bool autoStart = true;
16+
17+
private bool timeout = true;
18+
private float timer = 0.0f;
19+
20+
private void Start()
21+
{
22+
if (autoStart)
23+
{
24+
StartTimer();
25+
}
26+
}
27+
28+
private void Update()
29+
{
30+
if (timer > 0 && !timeout)
31+
{
32+
timer -= Time.deltaTime;
33+
OnTimeChanged.Invoke(timer);
34+
}
35+
else if (timer < 0 && !timeout)
36+
{
37+
timeout = true;
38+
OnTimeout.Invoke();
39+
40+
if (loop)
41+
{
42+
StartTimer();
43+
}
44+
}
45+
}
46+
47+
public void StartTimer()
48+
{
49+
timer = startTime;
50+
timeout = false;
51+
}
52+
}
53+
}

Assets/BartInTheField/BartInTheField.Timer/Timer.cs.meta

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

0 commit comments

Comments
 (0)