# 属性系统
# 一、介绍
属性系统
用于获取属性信息,例如金币、钻石、体力等都属于属性,当然你也可以自定义其他属性,具体的属性需要在物品配置中配置。
注意:在物品配置表
中物品类型
为属性
的物品,会出现在属性系统列表中,并且可通过属性系统的接口进行操作。
# 二、使用
1. 获取属性信息列表
在头部引入账号模块后,异步调用attributeSystem.attributes
数据访问接口,返回值为Attribute类型数组,请查看 Attribute类
// 导入账号模块
import { attributeSystem } from '@timi/mogs-sdk';
// ...
// 获取属性相关信息
const attributes = await attributeSystem.attributes;
attributes.forEach((attr) => {
console.log(attr.id, attr.name, attr.value);
});
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
2. 属性更新事件监听
attributeSystem
同时提供了单个属性的更新事件监听:attributeSystem.onAttributeUpdate
和 attributeSystem.offAttributeUpdate
,以及属性列表的更新时间监听attributeSystem.onAttributesUpdate
和 attributeSystem.offAttributesUpdate
以下为监听属性更新例子:
// 导入属性模块
import { attributeSystem } from '@timi/mogs-sdk';
// ...
// 定义一个事件
const handler: AttributeUpdateEventHandler = (event) => {
console.log(event.previousValue, event.currentValue);
};
//开始监听 Attributes 改变事件
attributeSystem.onAttributeUpdate(handler);
// ...
// 移除刚刚添加的事件处理函数
attributeSystem.offAttributeUpdate(handler);
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
TIP
更多匹配模块的api请参考属性模块