https://github.com/PlayCreatively/FreyrEssentials
Tools I wouldn't function without 💻
https://github.com/PlayCreatively/FreyrEssentials
csharp essentials timer unity utility
Last synced: 10 months ago
JSON representation
Tools I wouldn't function without 💻
- Host: GitHub
- URL: https://github.com/PlayCreatively/FreyrEssentials
- Owner: PlayCreatively
- License: mit
- Created: 2020-10-02T01:34:05.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-12-23T12:27:22.000Z (about 4 years ago)
- Last Synced: 2024-11-10T16:46:25.437Z (over 1 year ago)
- Topics: csharp, essentials, timer, unity, utility
- Language: C#
- Homepage:
- Size: 55.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⏳ Timer class
Create a countdown and start the timer
``` c#
//Create and start a count down of 5 seconds.
Timer myTimer = Timer.Create(5f);
```
read the value as a normal progression of the countdown ranging from 0 to 1
``` c#
//Interpolate between pointA and pointB by myTimer's progression to 5 seconds.
Vector2.Lerp(pointA, pointB, myTimer)
```
or as a bool
``` c#
//While myTimer hasn't reached 5 seconds.
while(!myTimer)
```
# Pool\ class
_Lightweight generic pooling class._
### 🤔 Why use Pool?
Pool is just a simple lightweight pooling system which takes care of the pooling boilerplate.
### How to use 
![]()
### 🔨 Constructing a pool
``` c#
Pool slimePool = new Pool(
CreateNew: () => new GameObject().AddComponent(),
OnChange: (isSpawning, slime) => slime.gameObject.SetActive(isSpawning));
```
___
The first parameter called `CreateNew` is a `Func` which will be used
by the Pool class to create new instances of `T`.
``` c#
//Method which instantiates a gameObject, adds a slime component and returns a reference to it.
CreateNew: () => new GameObject().AddComponent()
```
___
The second parameter is optional, called `OnChange` which is an `Action` and runs when a T instance is being either __borrowed__ or __returned__.
``` c#
//Enable or disable the slime component based on if it's being borrowed or returned.
OnChange: (isSpawning, slime) => slime.gameObject.SetActive(isSpawning)
```
### 🔁 Borrow/Return
Now that you've made a pool you can start borrowing and returning slime instances using `slimePool.Borrow()` and `slimePool.Return(Slime)` respectively.