Command

Commands are the Controllers in the classic Model-View-Controller structure.

Command listens to every dispatch from the command dispatcher. Whenever an event or Signal fires, contex would find the event listener of command, and call the action function.

Command(Contex contex)

Remarks

Constructor function require contex param.

void InitModel()

Remarks

Override InitModel to initialize models.You should call BindModel to bind models to command.

public override void InitModel() {
        BindModel(ModelType.ScoreModel, ScoreModel.GetSingleton<ScoreModel>());
    }

void BindModel(enum, Model model)

Params

enum: model type

model: model class drived from Model

Remarks

Call BindModel to bind models to command in InitModel function.

Model.GetSingleton<T> that will instantiate an model which works in the application life time.

Model.GetInstance<T> that will instantiate an model which destroys with the scene.

void AddListener(enum, Action.Do doFunc)

Params

enum: event type

doFunc: action function.

delegate void Action.Do(object[] param)

Remarks

Call this function to listen to a event, when got a event which is fired by "DispatchCommand(enum)" in other commands or mediator or view, it'll call the action function.

void OnMessage(enum, Action.Do doFunc)

Params

enum: event type

doFunc: action function.

Remarks

Call this function to listen to a event when you are using thread, when got a event fired, it'll call the action function.

void OnStart()

Remarks

Instead of unity function "Start", and you should add listener here.

Example

Last updated