Skip to content

Tools I wouldn't function without 💻

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

PlayCreatively/FreyrEssentials

Repository files navigation

⏳ Timer class

Create a countdown and start the timer

//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

//Interpolate between pointA and pointB by myTimer's progression to 5 seconds.
Vector2.Lerp(pointA, pointB, myTimer)

or as a bool

//While myTimer hasn't reached 5 seconds.
while(!myTimer)

Pool<T> 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 drawing

🔨 Constructing a pool

Pool<Slime> slimePool = new Pool<Slime>(
            CreateNew: () => new GameObject().AddComponent<Slime>(),
            OnChange: (isSpawning, slime) => slime.gameObject.SetActive(isSpawning));

The first parameter called CreateNew is a Func<T> which will be used by the Pool class to create new instances of T.

//Method which instantiates a gameObject, adds a slime component and returns a reference to it.
CreateNew: () => new GameObject().AddComponent<Slime>() 

The second parameter is optional, called OnChange which is an Action<bool, T> and runs when a T instance is being either borrowed or returned.

//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.

About

Tools I wouldn't function without 💻

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages