初始化工程
| 备注: Python Waapi-Client 专门用于与 Python 3.7+ 一起使用。 |
从任意目录运行以下命令来安装依赖:
# Windows
py -3 -m pip install waapi-client
# macOS, Linux
python3 -m pip install waapi-client
工程代码
该文件包含以下代码,让您能连接到 Wwise Authoring API。
from waapi import WaapiClient, CannotConnectToWaapiException
from pprint import pprint
try:
client = WaapiClient()
except CannotConnectToWaapiException:
print("Could not connect to Waapi: Is Wwise running and Wwise Authoring API enabled?")
else:
def on_name_changed(*args, **kwargs):
obj_type = kwargs.get("object", {}).get("type")
old_name = kwargs.get("oldName")
new_name = kwargs.get("newName")
print("Object '{}' (of type '{}') was renamed to '{}'\n".format(old_name, obj_type, new_name))
client.disconnect()
handler = client.subscribe("ak.wwise.core.object.nameChanged", on_name_changed, {"return": ["type"]})
print("Subscribed 'ak.wwise.core.object.nameChanged', rename an object in Wwise")
运行工程
在 Wwise 中打开工程后,使用以下命令在终端上运行脚本:
# Windows
py subscribe.py
# macOS, Linux
python3 subscribe.py
此时,应会显示如下输出:
Getting Wwise instance information:
Subscribed 'ak.wwise.core.object.nameChanged', rename an object in Wwise
接着,在 Wwise 中重命名对象。此时,应会显示如下输出:
Object 'MySound' (of type 'Sound') was renamed to 'MyOtherSound'