- To provide a simple and easy-to-use state management library for Unity.(Like Redux or Svelte.store)
- State Set/Read/Observe
- StateCollection
- DependencyState/HalfDependencyState
| class | summary | implements interface |
|---|---|---|
| ObservableState SubjectState | A state variable that can be observed | IStateReader, IStateObserver, IStateSetter, IDisposable |
| State | A state variable that cannot be observed but is more memory-efficient than ObservableState | IStateReader, IStateSetter |
| DependencyState | A state variable that derives results from other variables and triggers them | IStateReader, IStateObserver |
| HalfDependencyState | A state variable that derive results from other variables and their own variable and trigger them | IStateReader, IStateSetter, IStateObserver |
| ObservableListState | A collection of StateVariables (internally implemented as a List) | IStateReader, IStateSetter, IStateCollectionObserver, IStateCollectionElementObserver, IStateCollectionElementSetter, IStateCollectionModifier |
| ObservableDictionaryState | A collection of StateVariables (internally implemented as a Dictionary) | IStateReader, IStateSetter, IStateCollectionObserver, IStateCollectionElementObserver, IStateCollectionElementSetter, IStateCollectionModifier |
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();}- Open the Package Manager
- Press [+▼] button and click Add package from git URL...
- Enter the following:
https://github.com/tanitaka-tech/StateVariable.git
- Install NugetForUnity.
- Search for
StateVariablein the NugetForUnity window. - Click the
Installbutton.
- Run the following:
dotnet add package StateVariable --version 1.4.0