Skip to content

Instantly share code, notes, and snippets.

@herman-rogers
Created February 24, 2017 16:36
Show Gist options
  • Save herman-rogers/ee819557973c8dd111481844be534f83 to your computer and use it in GitHub Desktop.
Save herman-rogers/ee819557973c8dd111481844be534f83 to your computer and use it in GitHub Desktop.
Flux implementation in Unity
Props stateTree = {name: "InitialState", value: 0};
Props stateOneProps = {
name: "SceneOne"
value: 1
}
Props stateTwoProps = {
name: "SceneTwo"
}
TreeUpdator(newProps) {
Props newTree = stateTree
// if state props are null keep old state; aka magiks
newTree.name = newProps.name;
newTree.value = newProps.value;
// essentially just assign a new tree each time, not modify it
stateTree = newTree
}
TreeUpdator(stateOneProps)
//stateTree.name should be "SceneOne", value should be 1
TreeUpdator(stateTwoProps)
//stateTree.name should be "SceneTwo", value should be 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment