|
|
@@ -0,0 +1,50 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+public class UserGameAnalyse : MonoBehaviour
|
|
|
+{
|
|
|
+ int gameType;
|
|
|
+ long startTime; //毫秒
|
|
|
+ float duration; //秒
|
|
|
+ float sceneTimeOnStart;
|
|
|
+ float uploadCountOnUpdate = 0;
|
|
|
+ bool gameIsEnd = false;
|
|
|
+
|
|
|
+ public static void CreateWhenGameStart(int gameType) {
|
|
|
+ new GameObject("UserGameAnaly").AddComponent<UserGameAnalyse>().gameType = gameType;
|
|
|
+ }
|
|
|
+
|
|
|
+ void Start()
|
|
|
+ {
|
|
|
+ startTime = JC.CS.Utility.GetTimestamp();
|
|
|
+ sceneTimeOnStart = Time.realtimeSinceStartup;
|
|
|
+ }
|
|
|
+
|
|
|
+ void OnDestroy() {
|
|
|
+ UploadData(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ void Update()
|
|
|
+ {
|
|
|
+ if (!gameIsEnd) {
|
|
|
+ duration = Time.realtimeSinceStartup - sceneTimeOnStart;
|
|
|
+ if (duration / 60 >= uploadCountOnUpdate) { //每60秒上传一次
|
|
|
+ uploadCountOnUpdate++;
|
|
|
+ UploadData(false);
|
|
|
+ }
|
|
|
+ if (GameMgr.ins.gameOver) {
|
|
|
+ UploadData(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void UploadData(bool isEnd) {
|
|
|
+ if (gameIsEnd) return;
|
|
|
+ if (isEnd) gameIsEnd = true;
|
|
|
+ try {
|
|
|
+ UserPlayer.ins.call("UserGameAnalyseComp.uploadUserGameRecord", gameType, startTime, (int) duration);
|
|
|
+ }
|
|
|
+ catch (System.Exception) {}
|
|
|
+ }
|
|
|
+}
|