prime31 / Nez

Nez is a free 2D focused framework that works with MonoGame and FNA
MIT License
1.76k stars 357 forks source link

ChangeState non-generic method - TypeStateMachine.cs #815

Closed optimo closed 2 weeks ago

optimo commented 2 weeks ago

I wanted to be able to use a runtime-resolved type for the generic part of of ChangeState. The messy way is with some reflection and binding. Instead here I created a new method with the same name, but non-generic. You simply pass in the Type.

I've redressed the existing method to call thru to the new method.

And I also thought maybe the new method be given its own name instead?

Also added a ChangeToPreviousState() method that does what it says by calling the new method with the PreviousType as its argument. As long as it's non-null type it will work, in any case returning the _currentState as State.