| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 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) {}
- }
- }
|