|
本帖最后由 zorsite 于 2022-11-29 15:42 编辑 7 z% l1 k& f- o
7 ]7 C2 F" b! y1 s Q5 [! |如何获取Activity的统计信息?6 r" s/ g2 v# Q
3D实体的属性面板中可以查看统计信息。7 V$ d6 o L, \ Q
* f( W' q5 A- q1 G2 l; z z同时可以通过Object.stats属性来获取相关信息。
. H& b2 E9 {* Z! N( z
2 z# x- y' z7 w9 e" y5 ]5 VActivity也有属性面板: O' ^3 f/ n% V- L. ]
6 M6 s! \ G' E$ T( W% ~! M6 V但是Activity却没有stats属性,无法通过属性获取统计信息。
k9 |/ X# X' O& x3 E% ~
+ Z! i( h' N+ Z# h, V5 z原因在于当我们使用current关键字的时候,current被声明为Object对象,而activity被声明为treenode对象。
$ e `" p m1 R( j. [" M$ |treenode作为Object的父类,其属性和方法不如其子类Object那样丰富。5 t3 Z$ b) S' `( r+ U8 f8 N
5 H) I. c0 M J7 J作为treenode的子类,Object对象除了有treenode的属性外,还具有以下属性:
2 t3 J1 _! t, M; b1 {
* T8 j5 j: J$ o2 P* B/ S' x其中就有stats属性,可以获取统计信息。
3 H, m2 S$ R! P U3 ~/ W
H* A7 q7 B3 b. F, i那如何使用代码获取Activity的统计信息呢?
" _$ M4 ?: ]7 p第1种方法,使用getstat命令。0 j3 w2 I5 m2 }+ u5 B! V
getstat (node object, str name, int flag [, var p1, var p2, var p3]) C* N- L7 [: n
Returns the statistic value for the given objectDescription# g+ _* ^ _5 _( e$ E/ i+ M
It is preferred to use Object.stats instead. Gets the specified statistic from the given object.* a9 s& S4 }6 v- }% r4 b2 A
Example:2 N4 Y- m9 N. ^! p. D- r3 s
- getstat(activity, "Content", STAT_CURRENT)
复制代码- getstat(activity, "Input", STAT_CURRENT)
复制代码- getstat(activity, "Staytime", STAT_AVERAGE)
复制代码- double avgContent = getstat(
9 U3 A6 S6 W, x# G7 S, _% N$ t - // getstat requires between 4 and 6 parameters:
% w# |( S+ H& t) n; b - activity, // 1. the object (shared asset or activity) that has the statistic0 `* |" _0 x% @& m5 z T3 @
- "Content", // 2. the name of the statistic, W) E$ y' w2 ~* ]* A( o+ O
- STAT_AVERAGE, // 3. the desired value from the statistic (could also be STAT_CURRENT, STAT_MIN, or STAT_MAX)+ x D3 s; G" Y5 x; A+ [
- // 4. an optional parameter the instance object (usually current): j; S3 }& K' t9 {/ @, H2 L
- // 5. an additional parameter to help resolve which data to get
8 y9 A I1 ?( ^1 _( c3 [ - // 6. an additional parameter to help resolve which data to get$ \. ?4 s0 R0 g- E6 R$ u/ `3 C5 P( ]; {
- );
复制代码 , s2 _* {5 {4 f& Z! i
第2种方法,转换activity的类型。
% b/ r, |3 g3 ~; Q" B既然Object对象有stats属性,那把activity从treenode类型转换为Object类型不就可以了?
6 I, |8 y" d/ `, @转换的方式有2种:
1 Y% m. c( }; a, I, g9 `( p方法1,使用as关键字:
0 r7 \, H- q5 z/ I" J" j- activity.as(Object).stats.input.value;$ x' i& L1 K$ ~; W$ A9 P2 K
复制代码
3 V7 i- @8 v% K( ]! \方法2,将activity声明为Object类型的变量:
2 L* ~1 b, W5 F1 i( O1 P7 S6 e- Object Obj_activity=activity;
' {0 n6 g- s% U3 e5 h4 K - return Obj_activity.stats.input.value;
复制代码
' q+ b, ^- X- P& |# n, ~& i; K2 R, k' G7 e# c' O/ w: H1 E% I$ q
, Y8 d# _+ [) F
3 R* x. ?/ e" c/ E) P2 v- q3 q4 R
7 {' \3 _9 n& Z$ T# O- |
3 U! _/ Q5 z/ C! X: {6 ^8 K8 S
0 S( t/ t) m4 u2 E, a, g# V: F% l6 W
2 x/ P7 S2 P0 k3 w' d5 q4 e z# n& e |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|