yohash / UnityReact

A react-like backend built in C# for Unity
MIT License
0 stars 0 forks source link

Initialize state containers in core `Props` #4

Closed yohash closed 3 months ago

yohash commented 11 months ago

Create props so we don't have to force the = new State(). If this line doesn't exist, Component throws errors on initialization in buildProps()

public class ModelProps : Props
{
  public PlayerState PlayerState = new PlayerState();

  public override List<StateContainer> state =>
    new List<StateContainer>() {
      PlayerState
    };

  public override void SetState(List<StateContainer> containers)
  {
    foreach (var container in containers) {
      if (container is PlayerState) {
        PlayerState = container.Copy as PlayerState;
      }
    }
  }
}