# Contex

&#x20; The Context is where all the delegate and event store. it provides member functions for initializing the scene. You should bind app and command in contex.

### void InitApp()

#### Remarks

Override InitApp to bind app instance to contex.

```
public override void InitApp() {
        // Bind App class to contex.You can ignore this if app class is useless.
        // 绑定App类到contex,如果app类无用,或者不需要做全局初始化,可忽略此步.
        BindApp(TestApp.Instance<TestApp>());
    }
```

### void InitScene()

#### Remarks

Override InitScene to initialize each scene, e.g. create gameobject, make gameobject initialize etc.

### void ExitScene()

#### Remarks

Override ExitScene to clean up each scene.

### void InitCommand()

#### Remarks

Override InitCommand to bind command to contex. You should bind all commands that will be used in the scene.

```
public override void InitCommand() {
        // Initialize command function, All command class should be create here.
        // Command类初始化函数,所有的Command类应当在此进行创建.
        BindCommand(new Test1Command(this));
        BindCommand(new CubeCommand(this));
    }
```

### void OnAwake()

#### Remarks

Instead of unity function "Awake".&#x20;

### void OnStart()

#### Remarks

Instead of unity function "Start".

### void OnUpdate()

#### Remarks

Instead of unity function "Update".

## Example

```
public class Test1Contex : Contex {

    public override void InitApp() {
        // Bind App class to contex.You can ignore this if app class is useless.
        // 绑定App类到contex,如果app类无用,或者不需要做全局初始化,可忽略此步.
        BindApp(TestApp.Instance<TestApp>());
    }

    public override void ExitScene() {
        // Uninitialize scene function
        // 场景反初始化函数,可以在此做一些场景资源的销毁.
    }

    public override void InitCommand() {
        // Initialize command function, All command class should be create here.
        // Command类初始化函数,所有的Command类应当在此进行创建.
        BindCommand(new Test1Command(this));
        BindCommand(new CubeCommand(this));
    }

    public override void InitScene() {
        // Initialize scene function.
        // 场景初始化函数,可以做一些场景初始化工作.
    }

    public override void OnStart() {
        
    }

    public override void OnUpdate() {
        
    }

    public override void OnAwake() {

    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://2011fuzhou.gitbook.io/hnmvc/api/contex.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
