|
本帖最后由 zorsite 于 2022-11-29 15:42 编辑
- k6 @( p) S3 X% e" M, D
; l9 o; J7 F e0 G0 |: W# K如何获取Activity的统计信息?9 V: q/ H9 [6 O3 g) D5 r" ?
3D实体的属性面板中可以查看统计信息。; ~9 j2 _. ~4 v9 U
3 _* [- T4 o$ K" D0 X
同时可以通过Object.stats属性来获取相关信息。5 w. ~/ ~- `- J& p2 M
! X4 r) d2 P2 m2 z0 m1 [0 _4 y
Activity也有属性面板
$ t3 M" _$ V; ^( M! d3 W- ^4 L& j# z: e# F
但是Activity却没有stats属性,无法通过属性获取统计信息。
1 `' w2 Q- f+ L0 Q
" I' _& M" F. R) r" |+ V原因在于当我们使用current关键字的时候,current被声明为Object对象,而activity被声明为treenode对象。: ~, t- j/ `) K8 A" v
treenode作为Object的父类,其属性和方法不如其子类Object那样丰富。
9 a. C3 o' W; t
0 z3 M# c, D) b8 b( }* k7 G6 r: o/ H) E8 ~作为treenode的子类,Object对象除了有treenode的属性外,还具有以下属性:
8 e7 N3 q/ S: Q2 i
8 G# l% X( K, U, ~! \+ |其中就有stats属性,可以获取统计信息。
: r+ L* w, }5 _7 s A; S! N& n, C8 Z. G9 U- C
那如何使用代码获取Activity的统计信息呢?: s+ e+ E U; }
第1种方法,使用getstat命令。' ~& a: }- q0 d+ S7 R
getstat (node object, str name, int flag [, var p1, var p2, var p3])# M6 P- V3 I Z8 ]+ }; i
Returns the statistic value for the given objectDescription3 I, d# U9 i# H4 V3 I
It is preferred to use Object.stats instead. Gets the specified statistic from the given object.. T$ u$ f) J( C% h v3 n
Example:9 `' u& `: M5 j9 I9 [
- getstat(activity, "Content", STAT_CURRENT)
复制代码- getstat(activity, "Input", STAT_CURRENT)
复制代码- getstat(activity, "Staytime", STAT_AVERAGE)
复制代码- double avgContent = getstat(- V' {/ V4 R! _+ H- Q: R
- // getstat requires between 4 and 6 parameters:' b/ H9 i X$ K, d1 w/ [
- activity, // 1. the object (shared asset or activity) that has the statistic
5 R5 k8 K/ e3 N5 a6 R - "Content", // 2. the name of the statistic9 |2 G! d* T( i. A; T" ^
- STAT_AVERAGE, // 3. the desired value from the statistic (could also be STAT_CURRENT, STAT_MIN, or STAT_MAX)* H1 R1 T& h. z& o& g3 ^, X
- // 4. an optional parameter the instance object (usually current)
1 b9 ~, s* F* f4 J; B - // 5. an additional parameter to help resolve which data to get
7 k! a2 P. B7 N- f - // 6. an additional parameter to help resolve which data to get* v* S/ a3 ^! F& a
- );
复制代码 + `2 l3 W9 J' C, N3 I
第2种方法,转换activity的类型。
! R. H% m7 x" h% a2 C9 ?! W. I既然Object对象有stats属性,那把activity从treenode类型转换为Object类型不就可以了?
' D$ a% J. q# P, C5 F& z9 N转换的方式有2种:
" r7 X5 l, X3 e9 Q- T m方法1,使用as关键字:+ J7 s- d: I m, {# ~5 W
- activity.as(Object).stats.input.value;, Z. P# y2 w" ^0 X
复制代码
, m. e3 l5 Q8 H; _9 W方法2,将activity声明为Object类型的变量:: C; V3 |; s9 J0 u
- Object Obj_activity=activity;
9 i, \$ n2 H ?' O" C - return Obj_activity.stats.input.value;
复制代码
N/ Y7 W6 J" [
s" u- G' d6 @0 H# r9 S1 ]3 ]6 {- `
3 b3 k& |9 q6 p4 ?) ^, X. y: s9 l0 K0 f: @" d1 O) ]
# a. c0 J- k+ n$ g
$ ^2 S+ b- r+ L/ D* b
7 K+ b1 o5 t8 T
. E9 P1 S; x( R6 U+ p9 S( O |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|