Closed kinosang closed 4 years ago
You can call those methods, but I'm not sure why you'd put an observer inside your derived state machine. I'd highly suggest keeping observers separate of the state machine definition.
If you insist on doing it, just cast this
to the interface and call it.
@phatboyg finally, I solve the problem by creating a static factory method.
TLDR;
The reason why I want to put observers inside the state machine is to log all changes on various state machines.
So I just created a base class derived from AutomatonymousStateMachine
and want to connect the observer in the constructor.
But I got Cannot access explicit implementation of 'StateMachine<TInstance>.ConnectStateObserver'
.
UPDATE
Use this.ConnectStateObserver(observer);
instead of ConnectStateObserver(observer);
in the constructor.
Your case is fairly unique, glad you figured it out.
Make
_eventObservers
and_stateObservers
accessible to derived state mchines.Or make
ConnectEventObserver
,ConnectStateObserver
accessible to derived state mchines (in constructor).So that we can connect observers when create a new instance of state mchines.