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