Skip to content

Commit

Permalink
feat: 💥 update to attach timer method and add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
SushiWaUmai committed Feb 2, 2022
1 parent 638b1bf commit ff30707
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 9 deletions.
Binary file added .github/images/Slide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ChronityTest/Assets/Scripts/Runtime/ChronityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ChronityTest : MonoBehaviour

public void StartTimer()
{
timer = this.RegisterTimer(5, () => Debug.Log("Hello World"), x => Debug.Log($"Timer Updated: {x}"));
timer = this.AttachTimer(5, () => Debug.Log("Hello World"), x => Debug.Log($"Timer Updated: {x}"));
}

public void PauseTimer()
Expand Down
2 changes: 1 addition & 1 deletion ChronityTest/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "10dc5e1220227bc4e3640d732612bab751b98190"
"hash": "b4a335d2d374e9d2daae6b6ae7b901148f3f24a9"
},
"com.unity.2d.animation": {
"version": "5.0.10",
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Chronity
[![# Chronity](./.github/images/Slide.png)](https://sushiwaumai.github.io/Chronity)

[![Release](https://img.shields.io/github/v/release/SushiWaUmai/Chronity?include_prereleases&style=flat-square)](https://github.com/SushiWaUmai/Chronity/releases)
[![OpenUPM](https://img.shields.io/npm/v/com.sushiwaumai.chronity?label=openupm&registry_uri=https://package.openupm.com&style=flat-square)](https://openupm.com/packages/com.sushiwaumai.chronity/)
Expand All @@ -10,6 +10,8 @@

This package is a fork of the [UnityTimer](https://github.com/akbiggs/UnityTimer) made by [akbiggs](https://github.com/akbiggs).

To get started, read the [docs](https://sushiwaumai.github.io/Chronity) or follow this [README](README.md) file.

## Table of Contents
- [Getting Started](https://github.com/SushiWaUmai/Chronity#getting-started-rocket)
- [Installation](https://github.com/SushiWaUmai/Chronity#installation)
Expand Down Expand Up @@ -75,7 +77,7 @@ public class CoolMonoBehaviour : MonoBehaviour
{
// Use the AttachTimer extension method to create a timer that is destroyed when this
// object is destroyed.
this.RegisterTimer(5f, () => {
this.AttachTimer(5f, () => {

// If this code runs after the object is destroyed, a null reference will be thrown,
// which could corrupt game state.
Expand Down Expand Up @@ -106,6 +108,16 @@ Timer.Register(transitionDuration,
onComplete: () => Debug.Log("Color is now red"));
```

**Make a timer presist through scene changes using the `cancelOnSceneChange` parameter.**
```c#
// Make a timer that will persist through scene changes.
Timer.Register(5f, () => Debug.Log("Hello World"), cancelOnSceneChange: false);

// Change scene from another script
// Logs "Hello World" after 5 seconds.
```

**Make a timer run in the editor by using the `EditorTimer` class.**
```c#
// Logs "Hello World" after 5 seconds in the editor
Expand Down
2 changes: 1 addition & 1 deletion com.sushiwaumai.chronity/Runtime/TimerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class TimerExtension
/// <param name="isLooped">Whether the timer should restart after executing.</param>
/// <param name="cancelOnSceneChange">Whether the timer should cancel when the scene changes</param>
/// <returns>A timer object that allows you to examine stats and stop/resume progress.</returns>
public static Timer RegisterTimer(this MonoBehaviour behaviour, float duration, Action onComplete, Action<float> onUpdate = null, bool useRealTime = false, bool isLooped = false, bool cancelOnSceneChange = true)
public static Timer AttachTimer(this MonoBehaviour behaviour, float duration, Action onComplete, Action<float> onUpdate = null, bool useRealTime = false, bool isLooped = false, bool cancelOnSceneChange = true)
{
Timer result = Timer.Register(duration, onComplete, onUpdate, useRealTime, isLooped, cancelOnSceneChange, behaviour);
return result;
Expand Down
5 changes: 2 additions & 3 deletions com.sushiwaumai.chronity/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "com.sushiwaumai.chronity",
"version": "0.1.0",
"version": "1.0.0",
"displayName": "Chronity",
"description": "Library for running functions after a delay by creating timers in Unity3D.",
"unity": "2020.3",
"type": "library",
"dependencies": {}
"type": "library"
}
12 changes: 11 additions & 1 deletion docfx_project/manual/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class CoolMonoBehaviour : MonoBehaviour
{
// Use the AttachTimer extension method to create a timer that is destroyed when this
// object is destroyed.
this.RegisterTimer(5f, () => {
this.AttachTimer(5f, () => {

// If this code runs after the object is destroyed, a null reference will be thrown,
// which could corrupt game state.
Expand Down Expand Up @@ -72,6 +72,16 @@ Timer.Register(transitionDuration,
onComplete: () => Debug.Log("Color is now red"));
```

**Make a timer presist through scene changes using the `cancelOnSceneChange` parameter.**
```c#
// Make a timer that will persist through scene changes.
Timer.Register(5f, () => Debug.Log("Hello World"), cancelOnSceneChange: false);

// Change scene from another script
// Logs "Hello World" after 5 seconds.
```

**Make a timer run in the editor by using the `EditorTimer` class.**
```c#
// Logs "Hello World" after 5 seconds in the editor
Expand Down

0 comments on commit ff30707

Please sign in to comment.