| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- /* 用户游戏情况统计分析-主要向服务器是上传用户游戏数据 */
- public class UserGameAnalyse : MonoBehaviour
- {
- //跳转关卡时候,记录对应的数据信息。叠加时间和射箭次数
- public static float allTimeSecond = 0;
- public static int allShootingCount = 0;
- int gameType;
- long startTime; //毫秒
- float duration; //秒
- float sceneTimeOnStart;
- float uploadCountOnUpdate = 0;
- bool gameIsEnd = false;
- public int shootingCount = 0;
- public static UserGameAnalyse CreateWhenGameStartAndReturn(int gameType)
- {
- UserGameAnalyse userGameAnalyse = new GameObject("UserGameAnaly").AddComponent<UserGameAnalyse>();
- userGameAnalyse.gameType = gameType;
- return userGameAnalyse;
- }
- void Start()
- {
- startTime = JCUnityLib.TimeUtils.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;
- //本轮游戏结束时候,记录一次数据
- allTimeSecond += duration;
- }
- try {
- UserPlayer.ins.call("UserGameAnalyseComp.uploadUserGameRecord", gameType, startTime, (int) duration);
- //Debug.Log("上传" + "(" + gameType + ")游戏时长统计数据:" + (int)duration + ",allTimeSecond:" + allTimeSecond);
- }
- catch (System.Exception) {}
- }
- /**
- * shootCheck 触发
- */
- public void onShootEvent() {
- changeShootingCount();
- }
- int changeShootingCount(int value = 1)
- {
- shootingCount += value;
- allShootingCount += value;
- return shootingCount;
- }
- public void showResultView(Action callback)
- {
- //不端直接返回,不处理弹出框
- if (CommonConfig.StandaloneModeOrPlatformB)
- {
- UploadData(true);
- onResetOverlayData();
- callback?.Invoke();
- return;
- }
- //上传一次数据
- UploadData(true);
- //显示面板
- GameMgr.ins.StopGame();
- GameObject resultObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_GameResultView);
- GameInfo gameInfo = TextureMgr.ins.GetGameInfos(gameType);
- GameResultView gameResultView = resultObj.GetComponent<GameResultView>();
- gameResultView.OnBackClicked += callback;
- gameResultView.setGameResultInfo(gameInfo.textId, (int)allTimeSecond, allShootingCount);
- //如果弹出结算面板,则清空一次数据
- onResetOverlayData();
- }
- public void onResetOverlayData() {
- allTimeSecond = 0;
- allShootingCount = 0;
- }
- }
|