using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using LocalRank; /* 用户游戏情况统计分析-主要向服务器是上传用户游戏数据 */ 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.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 GameResultView showResultView(Action callback) { //上传一次数据 UploadData(true); //显示面板 GameMgr.ins.StopGame(); GameObject resultObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_GameResultView); GameInfo gameInfo = TextureMgr.ins.GetGameInfos(gameType); GameResultView gameResultView = resultObj.GetComponent(); gameResultView.OnBackClicked += callback; gameResultView.setGameResultInfo(gameInfo.textId, (int)allTimeSecond, allShootingCount); //如果弹出结算面板,则清空一次数据 onResetOverlayData(); //b端直接返回,不处理弹出框 if (CommonConfig.StandaloneModeOrPlatformB) { resultObj.SetActive(false); callback?.Invoke(); } return gameResultView; } public void onResetOverlayData() { allTimeSecond = 0; allShootingCount = 0; } }