|
|
本帖最后由 zorsite 于 2022-11-29 15:42 编辑
" j: _ f3 }: `) s8 b( t+ ]% _- s0 u+ D! _" _2 ?. j9 f
如何获取Activity的统计信息?# f1 x. B, i- c+ R" }- O
3D实体的属性面板中可以查看统计信息。- r' ~/ x/ I* f7 }# } {( i
: ?) R/ P1 u2 \ D# |4 a同时可以通过Object.stats属性来获取相关信息。* r P3 c# g, s0 O
- ^ [* H3 c8 S3 w9 \7 [3 Y- F% @/ FActivity也有属性面板
) P) G, e5 U7 M2 ?8 s$ d1 [: t& L
. @4 ^5 u! @$ }6 B但是Activity却没有stats属性,无法通过属性获取统计信息。
5 e7 P& b; j* f1 n
$ B1 `* y3 t; c. V `原因在于当我们使用current关键字的时候,current被声明为Object对象,而activity被声明为treenode对象。
, ]: E. i/ t0 ~- r+ [/ dtreenode作为Object的父类,其属性和方法不如其子类Object那样丰富。+ s" o$ s; o3 l- m0 ?7 g
$ ~3 D2 f: p- V5 q
作为treenode的子类,Object对象除了有treenode的属性外,还具有以下属性:/ R! z( W% [% Y: v( N
) H3 i+ C4 }: T1 M- L5 p其中就有stats属性,可以获取统计信息。
2 u4 s* t7 D$ z3 W
: g0 \, O4 a/ a# u那如何使用代码获取Activity的统计信息呢?& ?. h% j" W) U' ]- [
第1种方法,使用getstat命令。$ k: z( S6 Z, v1 d" ~" ^
getstat (node object, str name, int flag [, var p1, var p2, var p3])
/ w" U% d4 R4 b" P- oReturns the statistic value for the given objectDescription9 Z- k, i# h+ Q; V% R
It is preferred to use Object.stats instead. Gets the specified statistic from the given object.
% m- B/ T7 {0 g/ tExample:+ B3 p! s5 _: D' W7 d4 n/ {! U3 x9 M
- getstat(activity, "Content", STAT_CURRENT)
复制代码- getstat(activity, "Input", STAT_CURRENT)
复制代码- getstat(activity, "Staytime", STAT_AVERAGE)
复制代码- double avgContent = getstat(
, _ p( l7 L2 A - // getstat requires between 4 and 6 parameters:8 m6 V; w- b1 E
- activity, // 1. the object (shared asset or activity) that has the statistic) }- Q! h; l; h& _* K
- "Content", // 2. the name of the statistic
1 L) ]3 U, \: h - STAT_AVERAGE, // 3. the desired value from the statistic (could also be STAT_CURRENT, STAT_MIN, or STAT_MAX)8 [6 |7 S& h1 s5 L9 `, ~
- // 4. an optional parameter the instance object (usually current)& x9 ]- W1 z5 X5 r; h! b
- // 5. an additional parameter to help resolve which data to get
, z3 I; i9 s) m' m! J2 J: @ - // 6. an additional parameter to help resolve which data to get* { D$ ?" w% x* `: S
- );
复制代码 - r, E( b2 o( V/ d; Y& N: G+ F2 q
第2种方法,转换activity的类型。2 D- r5 @5 s+ |0 \
既然Object对象有stats属性,那把activity从treenode类型转换为Object类型不就可以了?. b3 @! }* n! s) L! E; j7 |
转换的方式有2种:
4 Q# ?" r" a/ {方法1,使用as关键字:
9 E$ V2 X1 k6 E3 s- Q- activity.as(Object).stats.input.value;
- d) X2 Y2 h% v+ {
复制代码
* T1 B/ B; _% u8 a方法2,将activity声明为Object类型的变量:
$ o9 ?/ f. b; a; C' U2 @- Object Obj_activity=activity;
7 B' c: U6 Z+ o0 x1 u - return Obj_activity.stats.input.value;
复制代码 8 P% P+ S; O3 ?/ B7 k, T0 n3 \
/ M# o0 |% {" r* D- P) G: ?0 P$ K# _+ }& S# c4 p
+ D* h1 I$ T9 }4 ]) T4 j4 m# |8 X" y0 T- P
" e, N/ a7 f3 s: J$ u
; W% }* `: R! Q9 z- w
" ^$ X: e# d9 F8 j8 |
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|