|
本帖最后由 zorsite 于 2022-11-29 15:42 编辑 2 k' k+ A9 G: }. E5 G. i0 k o
+ z3 Y) c0 H$ }; U# d如何获取Activity的统计信息?
1 U. ~# Y5 N: e+ y$ c3D实体的属性面板中可以查看统计信息。
L2 B# C1 Y' h8 Z
. J4 A- n- d5 r$ Y/ [+ R2 y0 D同时可以通过Object.stats属性来获取相关信息。. }% j* v1 s4 w8 q: S% N
: l6 ]5 V( I2 I! {5 K, t
Activity也有属性面板5 x' j6 @. P7 {4 Z, M `
; e3 ]/ Y4 m9 y1 J
但是Activity却没有stats属性,无法通过属性获取统计信息。
& y( Q- Q6 r4 S! a2 P% n) k8 H1 \; L' J+ W4 i( L; S: h; c
原因在于当我们使用current关键字的时候,current被声明为Object对象,而activity被声明为treenode对象。$ ?/ y; {- l4 g" u
treenode作为Object的父类,其属性和方法不如其子类Object那样丰富。# l5 V; }# T# }5 `: g: o3 ^* E
5 g. S. x; N6 [/ m( B作为treenode的子类,Object对象除了有treenode的属性外,还具有以下属性:( N1 x$ [/ X% E7 Y& N
7 w: B/ q2 O0 t8 ~' O, m: a' R$ [其中就有stats属性,可以获取统计信息。. w0 E3 {2 a+ H1 d' R
, Z7 [4 m. j7 |8 H2 G, E* E/ U
那如何使用代码获取Activity的统计信息呢?
, o+ a5 @$ @! U& A0 b0 {$ V) I第1种方法,使用getstat命令。' l3 P* O0 A0 g' b$ ?6 ?; d( C
getstat (node object, str name, int flag [, var p1, var p2, var p3])- H. a. M( m/ m, X w8 D! k+ A
Returns the statistic value for the given objectDescription" x, U7 b) g" @, W0 [1 i
It is preferred to use Object.stats instead. Gets the specified statistic from the given object.
1 H! b1 @7 C5 m( _+ o- vExample:
/ |, Z% `$ i, C4 S( _4 E) w- o& I- getstat(activity, "Content", STAT_CURRENT)
复制代码- getstat(activity, "Input", STAT_CURRENT)
复制代码- getstat(activity, "Staytime", STAT_AVERAGE)
复制代码- double avgContent = getstat(1 c0 o }+ o2 G% L: A
- // getstat requires between 4 and 6 parameters:( O Q. {8 {8 j" k/ j9 {
- activity, // 1. the object (shared asset or activity) that has the statistic; j8 P' R8 ^/ }( g0 ]$ Z2 p: c3 J
- "Content", // 2. the name of the statistic
7 C/ j+ O. x C' y0 E7 W4 L - STAT_AVERAGE, // 3. the desired value from the statistic (could also be STAT_CURRENT, STAT_MIN, or STAT_MAX)
( K0 I G- l" J4 u& Y - // 4. an optional parameter the instance object (usually current)4 B3 X' j3 f4 a3 F
- // 5. an additional parameter to help resolve which data to get2 C% b" c+ }) A; q! Y
- // 6. an additional parameter to help resolve which data to get) H3 S8 \% b0 ?8 o. A: v" ?
- );
复制代码 " z# \0 Y! t$ D' B
第2种方法,转换activity的类型。$ Y4 N* I% [2 x! t: O. A, P
既然Object对象有stats属性,那把activity从treenode类型转换为Object类型不就可以了?' [3 k3 {: ?, h( o+ I/ A
转换的方式有2种:
) I9 r% M a, @' K7 d- H方法1,使用as关键字:( L" i. _; D* l! Q) \! k
- activity.as(Object).stats.input.value;
/ p. Q8 J6 G2 H. U! R
复制代码 ; r {& i5 t0 H# H* p5 o" J
方法2,将activity声明为Object类型的变量:3 r4 i& O4 o8 Z* o0 l' K
- Object Obj_activity=activity;
9 s2 B. f. J) L/ ? - return Obj_activity.stats.input.value;
复制代码
5 @! T) G1 l( Z5 O4 O9 R1 Y' y" K; ~" [/ a: I ~ [
" }6 z9 {8 [" S0 L w8 F' Z! M
9 I) \9 F8 o( x
. m A8 {& E A# m2 ^4 p: M
3 h; n' y/ P" U [4 `; _2 i% k6 ^* N3 M+ i
- ]* F* G5 D/ t7 b: H' @
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|