|
本帖最后由 zorsite 于 2022-11-29 15:42 编辑 8 c( A, F; Q% W* g1 a/ @
4 }5 a, a9 V) \
如何获取Activity的统计信息?
+ q6 @: o' D5 N( `/ C2 H V3 _3D实体的属性面板中可以查看统计信息。
( h& ^( a; ?2 C$ o" B U( @2 @& @3 m+ \
同时可以通过Object.stats属性来获取相关信息。
2 B: Q4 Q' S7 G2 B% C
% a- Z% |8 L" w5 N4 ]7 HActivity也有属性面板
7 H. B. m! f0 F7 J, x
: J. l! J* C! q: Y9 D" i& Z4 }但是Activity却没有stats属性,无法通过属性获取统计信息。
5 Y' i3 w( E0 ]; ~$ H+ `
9 u- m5 _! l3 v原因在于当我们使用current关键字的时候,current被声明为Object对象,而activity被声明为treenode对象。4 ?- d* c8 p) W4 g( D! b# X1 L
treenode作为Object的父类,其属性和方法不如其子类Object那样丰富。$ N. p. X- {& x: _/ |8 g
% r/ _& \# L {$ _+ s) M% D5 V
作为treenode的子类,Object对象除了有treenode的属性外,还具有以下属性:
) s0 c( h0 Y4 Q4 C. H4 Y% @
, R+ ^3 _' Q+ N其中就有stats属性,可以获取统计信息。, {# t6 Z% T% _' Z4 j9 L
" K# F* [: D$ H, D9 U& `那如何使用代码获取Activity的统计信息呢?" ~3 Z9 ?( y; q! ~; n: B' R: r
第1种方法,使用getstat命令。
, J$ d$ D. w, I5 Cgetstat (node object, str name, int flag [, var p1, var p2, var p3])
6 S9 x! g$ i8 R4 _Returns the statistic value for the given objectDescription+ G% T P3 e: p) e
It is preferred to use Object.stats instead. Gets the specified statistic from the given object.! S+ j& p% ?* G! v# {0 S
Example:
5 `( g: D% r9 a- getstat(activity, "Content", STAT_CURRENT)
复制代码- getstat(activity, "Input", STAT_CURRENT)
复制代码- getstat(activity, "Staytime", STAT_AVERAGE)
复制代码- double avgContent = getstat(4 j- f F) D9 _0 `; J5 K$ a" q
- // getstat requires between 4 and 6 parameters:2 B, F/ t6 d- s) c
- activity, // 1. the object (shared asset or activity) that has the statistic z6 ?: _ M9 \
- "Content", // 2. the name of the statistic
5 Z: B! A3 j. F4 x- o - STAT_AVERAGE, // 3. the desired value from the statistic (could also be STAT_CURRENT, STAT_MIN, or STAT_MAX)9 q# Z! j! y- o5 q
- // 4. an optional parameter the instance object (usually current)
/ `4 L# i& K4 S - // 5. an additional parameter to help resolve which data to get8 @8 ], q4 \* z
- // 6. an additional parameter to help resolve which data to get: t0 j" B7 w% F
- );
复制代码
) F5 N; A* \8 ]" `4 V第2种方法,转换activity的类型。
( g) u2 Q4 c' y/ N# `6 w既然Object对象有stats属性,那把activity从treenode类型转换为Object类型不就可以了?
# s4 h, r1 \' o# E. o转换的方式有2种:
+ M4 o; u1 d' N- |6 ]方法1,使用as关键字:
' b' K k/ `5 M5 f4 F6 a; I( i- activity.as(Object).stats.input.value;
M+ ?2 g8 t" N) s2 Y4 i ~
复制代码
% b) j6 V; Z- W- H8 [5 t/ ?% e方法2,将activity声明为Object类型的变量:3 K( X4 { P" |7 O/ h, z
- Object Obj_activity=activity;5 a8 N/ g2 b7 o1 j
- return Obj_activity.stats.input.value;
复制代码 ' n2 O, n$ w* q: C" Z7 M5 V# x
( |+ b: g7 r9 o( P! o5 X( N9 o' W
5 r# P; L9 e0 R
* c7 A9 P7 M* S' W, m
( ?/ K0 \# h- r! P3 V# a/ w) O3 p& F6 X
0 J/ z7 ?& o ]: r- {
R0 a) ?% x4 w |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|