Unity One Time Variable by TheJemy191 - 1

Extensions

Little unity package that handle one timed variable

Unknown VersionThe UnlicenseUpdated 18 days agoCreated on May 9th, 2020
Go to source

UnityOneTimeVariable

Little unity package that handle one timed variable

Why?

Ever done something like this?

bool oneTime = true;

void Update()
{
  if(oneTime)
  {
    oneTime = false;
    //Do something
  }
}

Yes so this little package is for you.
This package will handle oneTimed variable by scope like:
Session, Scene, PlayerPref, Database even, WorldWide? YES YOU CAN!

Installation

Copy the clone link. And add the package to unity packageManager.
UnityAddGitPackage

How to use

using OneTimeVariable;
using OneTimeVariable.BasicScope;

void Awake()
{
  OneTime.Register<ScopePlayerPrefs>();
  OneTime.Register<ScopeLocal>();//One per session
  OneTime.Register<ScopeScene<ScopeLocal>>();//One per scene
}

void Update()
{
  if(OneTime.Get<ScopePlayerPrefs>()["OneTimeVariable"])
    Debug.Log("This will be executed only one time or until the PlayerPref are deleted");
    
  if(OneTime.Get<ScopeLocal>()["OneTimeVariable"])
    Debug.Log("This will be executed only one time in this play session");    
    
  if(OneTime.Get<ScopeScene<ScopeLocal>>()["OneTimeVariable"])
    Debug.Log("This will be executed only one time in a scene. When the scene is reloaded. It will execute again");
}

Advance use

By classes type

OneTime.Get<ScopeLocal>()[typeof(MyClass)]; // One time for the class MyClass
OneTime.Get<ScopeLocal>()[typeof(MyClass), "oneTime"]; // One Time for "oneTime" for the classMyClass

PS: If you work at EdokyAcademy and want to change this do a pull request

Show all projects by TheJemy191