|
本帖最后由 zorsite 于 2022-11-29 15:42 编辑
, P3 H5 E2 I& O# B- ^( r4 P, O' U
" c* u) X) P4 U6 S" D如何获取Activity的统计信息?
0 |. x& R3 O" Q% R3 T8 \: E, y1 J3D实体的属性面板中可以查看统计信息。 S4 j: x% {1 W i: u; L
. V. `) y- E# v8 Q/ o [/ }& o: d
同时可以通过Object.stats属性来获取相关信息。 T, A9 w! L% r+ z7 S6 S' t1 v
; d$ i4 i3 i. g' D9 T
Activity也有属性面板
& s, O/ ?5 r$ e0 j) V$ d
/ `5 s6 f5 |$ m* ], y& u; f+ H2 z但是Activity却没有stats属性,无法通过属性获取统计信息。
6 T% T) }' v6 @# I
" R' C- \9 X: o/ G, n* d: a原因在于当我们使用current关键字的时候,current被声明为Object对象,而activity被声明为treenode对象。/ {- K1 o# D9 H# U3 D. Z8 s! Y, {
treenode作为Object的父类,其属性和方法不如其子类Object那样丰富。
! r, T8 ^$ D H' V5 B; k4 _
3 f9 t+ `8 [2 @3 J作为treenode的子类,Object对象除了有treenode的属性外,还具有以下属性:
) d! X9 @6 x) g, q
$ Q6 c* f9 y" L9 J4 N. N. f其中就有stats属性,可以获取统计信息。
0 z2 V8 ^* b- L, n
9 ?" z$ [8 L& G6 E那如何使用代码获取Activity的统计信息呢?4 A; h1 x$ {. Z5 o$ U& k
第1种方法,使用getstat命令。7 z; R7 a8 v0 p) U
getstat (node object, str name, int flag [, var p1, var p2, var p3])6 }' n; Q( O3 V3 W1 Q) b& E/ b
Returns the statistic value for the given objectDescription
1 T d6 w. K3 `: n) \% e2 K; dIt is preferred to use Object.stats instead. Gets the specified statistic from the given object.6 L5 N6 E; {$ V |. s" d
Example:; z: d) ]5 A5 t% ~* G; M
- getstat(activity, "Content", STAT_CURRENT)
复制代码- getstat(activity, "Input", STAT_CURRENT)
复制代码- getstat(activity, "Staytime", STAT_AVERAGE)
复制代码- double avgContent = getstat(
# f2 P! g" y$ Z9 z, G0 W, j& I3 ]0 S - // getstat requires between 4 and 6 parameters:
4 k' @( G; T. t( G6 X. e - activity, // 1. the object (shared asset or activity) that has the statistic4 c1 J, d. @9 W. v/ C
- "Content", // 2. the name of the statistic
. [1 V; N4 u' I4 J - STAT_AVERAGE, // 3. the desired value from the statistic (could also be STAT_CURRENT, STAT_MIN, or STAT_MAX)
1 ~% @0 K0 \$ m1 y - // 4. an optional parameter the instance object (usually current)
& V. G: s& E7 ^: `0 f - // 5. an additional parameter to help resolve which data to get
$ H7 `/ A m- a5 w - // 6. an additional parameter to help resolve which data to get
$ O' Y. l2 H% F! Y$ q# f( P - );
复制代码
( S1 |( o* O+ x& o第2种方法,转换activity的类型。1 H* ?4 Y# k; D$ c- e# N
既然Object对象有stats属性,那把activity从treenode类型转换为Object类型不就可以了?! E6 T: Y8 @. O/ ?
转换的方式有2种:& E7 N* ? M& H/ b0 h; z
方法1,使用as关键字:- `( L ?) e/ I9 B; v8 `
- activity.as(Object).stats.input.value;
9 q4 Y/ P5 D: J1 e/ ?. g
复制代码
& y3 v1 J1 P% e方法2,将activity声明为Object类型的变量:
- Y' o' \0 S% t. l" D2 `- Object Obj_activity=activity;
; t5 R0 o0 A1 j7 P3 R6 |% j/ l - return Obj_activity.stats.input.value;
复制代码
4 P4 i( w' m9 N, ?! k, V7 W& }, U; j( [( `
! f7 U. q2 U5 w, ~' g# S2 s
( H7 D) A6 H$ [8 M
7 `# s1 p9 @& E F& w! T7 B+ _: [9 }8 R: d% i
" |+ j( R4 j: I- L
" }* ?! p# Q1 T |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|