zorsite 发表于 2022-11-29 15:17:44

如何获取Activity的统计信息?

本帖最后由 zorsite 于 2022-11-29 15:42 编辑

如何获取Activity的统计信息?
3D实体的属性面板中可以查看统计信息。

同时可以通过Object.stats属性来获取相关信息。

Activity也有属性面板

但是Activity却没有stats属性,无法通过属性获取统计信息。

原因在于当我们使用current关键字的时候,current被声明为Object对象,而activity被声明为treenode对象。
treenode作为Object的父类,其属性和方法不如其子类Object那样丰富。

作为treenode的子类,Object对象除了有treenode的属性外,还具有以下属性:

其中就有stats属性,可以获取统计信息。

那如何使用代码获取Activity的统计信息呢?
第1种方法,使用getstat命令。
getstat (node object, str name, int flag [, var p1, var p2, var p3])
Returns the statistic value for the given objectDescription
It is preferred to use Object.stats instead. Gets the specified statistic from the given object.
Example:
getstat(activity, "Content", STAT_CURRENT)getstat(activity, "Input", STAT_CURRENT)getstat(activity, "Staytime", STAT_AVERAGE)
double avgContent = getstat(
// getstat requires between 4 and 6 parameters:
activity, // 1. the object (shared asset or activity) that has the statistic
"Content", // 2. the name of the statistic
STAT_AVERAGE, // 3. the desired value from the statistic (could also be STAT_CURRENT, STAT_MIN, or STAT_MAX)
// 4. an optional parameter the instance object (usually current)
// 5. an additional parameter to help resolve which data to get
// 6. an additional parameter to help resolve which data to get
);
第2种方法,转换activity的类型。
既然Object对象有stats属性,那把activity从treenode类型转换为Object类型不就可以了?
转换的方式有2种:
方法1,使用as关键字:
activity.as(Object).stats.input.value;

方法2,将activity声明为Object类型的变量:
Object Obj_activity=activity;
return Obj_activity.stats.input.value;







页: [1]
查看完整版本: 如何获取Activity的统计信息?