Skip to content

Repository files navigation

license

nuget

Mission of this Library

  • To provide a simple and easy-to-use state management library for Unity.(Like Redux or Svelte.store)

Features 🌟

  • State Set/Read/Observe
  • StateCollection
  • DependencyState/HalfDependencyState

State List

classsummaryimplements interface
ObservableState
SubjectState
A state variable that can be observedIStateReader, IStateObserver, IStateSetter, IDisposable
StateA state variable that cannot be observed but is more memory-efficient than ObservableStateIStateReader, IStateSetter
DependencyStateA state variable that derives results from other variables and triggers themIStateReader, IStateObserver
HalfDependencyStateA state variable that derive results from other variables and their own variable and trigger themIStateReader, IStateSetter, IStateObserver
ObservableListStateA collection of StateVariables (internally implemented as a List)IStateReader, IStateSetter, IStateCollectionObserver, IStateCollectionElementObserver, IStateCollectionElementSetter, IStateCollectionModifier
ObservableDictionaryStateA collection of StateVariables (internally implemented as a Dictionary)IStateReader, IStateSetter, IStateCollectionObserver, IStateCollectionElementObserver, IStateCollectionElementSetter, IStateCollectionModifier

Usage Example(This Example used a Zenject)

Each State is bound to the appropriate context of the DI container, and each object obtains the necessary dependencies.

// ----- InstallervartestState=newObservableState<Test>(newTest());testState.AddTo(this);Container.BindInstance<IStateReader<Test>>(testState);Container.BindInstance<IStateObserver<Test>>(testState);Container.BindInstance<IStateSetter<Test>>(testState);
[Inject]IStateObserver<Test> _testObserver;[Inject]IStateReader<Test> _testReader;[Inject]IStateSetter<Test>_testSetter;void Start(){// How to use variable_testObserver.Observe().Subscribe(test =>{}).AddTo(this);Testtest=_testReader.Read();_testSetter.Set(newTest());// Observer can also readtest=_testObserver.Read();// Setter can also readtest=_testSetter.Read();}

Installation ☘️

Unity

Install via git URL

  1. Open the Package Manager
  2. Press [+▼] button and click Add package from git URL...
  3. Enter the following: https://github.com/tanitaka-tech/StateVariable.git

Install via NugetForUnity

  1. Install NugetForUnity.
  2. Search for StateVariable in the NugetForUnity window.
  3. Click the Install button.

Install via nuget

  1. Run the following:
dotnet add package StateVariable --version 1.4.0

Required

About

A library for managing state variables

Resources

Stars

15 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages