Bootstrap Chameleon Logo

OnClose回调

有始有终

OnMapChangedCmd

Add "OnMapChangedCmd" to the Chameleon tool for executing Python commands when changing maps.

Usage: 用途:

  • Clean references in Chameleon tool when unload map to avoid memory leaks
  • 清除Chameleon工具中的引用,避免内存泄漏
  • Sync the UI when changing map
  • 同步UI,例如:切换地图时,刷新地图列表等

举个例子,在对可能会持有场景中对象引用的工具加入"OnMapChangedCmd"字段,并在其中添加清除引用的代码,例如:

    "OnMapChangedCmd": "chemeleon_objectDetailViewer.on_map_changed(%map_change_type)",
    def on_map_changed(self, map_change_type_str):
        # remove the reference, avoid memory leaking when load another map.
        if map_change_type_str == "TearDownWorld":
            self.reset(bResetParameter=False)
        else:
            pass # skip: LoadMap, SaveMap, NewMap
### 参数说明

- %world: Get the world of map operation
- %world获取地图操作的世界关卡

- %map_change_type: Get the operation type of changing map, "LoadMap", "SaveMap", "NewMap" or "TearDownWorld"
- %map_change_type获取地图操作的类型可能的值有
- "LoadMap"
- "SaveMap"
- "NewMap"
- "TearDownWorld"

## OnClosePyCmd

Chameleon Tool 中的`"OnClosePyCmd"`的字段用于设置用户主动关闭Chameleon工具时执行的Python命令

```JSON
{
    "TabLabel": "KeypadCommunicator",
    "InitTabSize": [200, 80],
    "InitTabPosition": [1100, 20],
    "InitPyCmd": "import MidiCommander; import importlib; importlib.reload(MidiCommander); chameleon_midi = MidiCommander.MidiListener.MidiListener(%JsonPath); chameleon_midi.open()",
    "OnClosePyCmd": "chameleon_midi.on_ui_close()",
    "Root":
    {...}
}

参考

Previous Next Topic