|
本帖最后由 zorsite 于 2022-11-29 15:42 编辑 X" M [- A8 E" ?) D; s
[" s$ X* D. r8 Z3 e
如何获取Activity的统计信息?
; h1 W* A# [' A7 z( J1 e* e3 S3D实体的属性面板中可以查看统计信息。
, u! u7 v% s6 z$ L1 g& N) I" I. W' G0 f) b- Y% J8 Z
同时可以通过Object.stats属性来获取相关信息。) Y+ I2 w$ @- A6 e3 U6 X+ T4 I
# E' ^$ T. o2 z2 i' H: s
Activity也有属性面板
1 s$ A# s. S) L( U9 x
- E2 z2 I7 [" L9 J" y但是Activity却没有stats属性,无法通过属性获取统计信息。/ c/ U0 P8 P9 {5 d* k Z: x! j
6 q2 S8 C1 I/ M
原因在于当我们使用current关键字的时候,current被声明为Object对象,而activity被声明为treenode对象。
) ]7 U+ H1 ?. l* a( F7 r5 m* Jtreenode作为Object的父类,其属性和方法不如其子类Object那样丰富。; |, ?! B8 M" h. g
- B* S; {* V7 R+ c" m1 N
作为treenode的子类,Object对象除了有treenode的属性外,还具有以下属性: \" ~) y: X3 W( b0 z+ I4 I
# o+ B6 D% Y8 C% o9 C7 x$ Y# }
其中就有stats属性,可以获取统计信息。# T: x6 |3 y$ S1 Y
, o2 k: m8 P$ R& O$ w* X2 L那如何使用代码获取Activity的统计信息呢?
0 ~' n/ z9 Q T7 |# ~# J第1种方法,使用getstat命令。* |2 F9 r0 a2 P G2 m6 {
getstat (node object, str name, int flag [, var p1, var p2, var p3])
. S( |1 h' @5 yReturns the statistic value for the given objectDescription
. z: n9 w$ p2 YIt is preferred to use Object.stats instead. Gets the specified statistic from the given object.8 v I" n8 B' h
Example:
5 e" f& p! Y) j7 B+ P9 f4 `. D, C, ]- getstat(activity, "Content", STAT_CURRENT)
复制代码- getstat(activity, "Input", STAT_CURRENT)
复制代码- getstat(activity, "Staytime", STAT_AVERAGE)
复制代码- double avgContent = getstat(
; J6 X6 d, h1 ?# U6 ^) | - // getstat requires between 4 and 6 parameters:
1 P" [$ D3 ~9 z - activity, // 1. the object (shared asset or activity) that has the statistic
/ e" A- ~9 r% A Y+ X - "Content", // 2. the name of the statistic
8 V @1 g. o. s0 _* T1 R - STAT_AVERAGE, // 3. the desired value from the statistic (could also be STAT_CURRENT, STAT_MIN, or STAT_MAX)2 w9 Z0 w$ h: d4 l S
- // 4. an optional parameter the instance object (usually current)
& r. h# t+ [9 g8 l: |% W% g - // 5. an additional parameter to help resolve which data to get
0 G# r' h' n- A9 ]; e - // 6. an additional parameter to help resolve which data to get6 ^' c$ P3 W) F9 {& I
- );
复制代码 : r) x3 t' ~( O: e* j Z' z
第2种方法,转换activity的类型。7 }# h2 J5 @8 Y
既然Object对象有stats属性,那把activity从treenode类型转换为Object类型不就可以了?/ `) M# ] S. V, h' c
转换的方式有2种:
, a# _& m0 ]6 Z9 c: a方法1,使用as关键字:" k9 D% P# k# h5 J/ [- m5 A; a- x. p
- activity.as(Object).stats.input.value;
8 X p( X0 ~( G4 Q1 D5 @; b
复制代码
0 @" _. t8 t4 k# I, _$ @方法2,将activity声明为Object类型的变量:2 y5 A, ^4 W1 X8 W
- Object Obj_activity=activity;, K, G3 [" f A0 j
- return Obj_activity.stats.input.value;
复制代码 R4 K/ o5 d( k, [! X% S
) Q- R' F5 l* }% L" {8 g
( A8 E7 D$ W* y5 Q) _, E
/ u( B- U( Q8 m/ K
- L+ F9 V) g! y7 u# e5 D7 D6 z' O. q9 \$ x7 D1 _5 C
1 q) W8 G4 f) `& n& D7 c7 \
! i* H2 k. J0 g4 o% x7 f G |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|