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().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) {} } }