| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using LocalRank;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- //打鸭子,塔防
- /* 用户游戏情况统计分析-主要向服务器是上传用户游戏数据 */
- public class UserGameAnalyse1 : MonoBehaviour
- {
- //重新玩操作,记录对应的数据信息。叠加时间和射箭次数
- public static float allTimeSecond = 0;
- public static int allShootingCount = 0;
- string targetScene;
- int gameType;
- long startTime; //毫秒
- float duration; //秒
- float sceneTimeOnStart;
- float uploadCountOnUpdate = 0;
- bool gameIsEnd = false;
- public int shootingCount = 0;
- private static UserGameAnalyse1 _Instance;
- public static UserGameAnalyse1 Instance
- {
- get
- {
- return _Instance;
- }
- }
- public static UserGameAnalyse1 CreateWhenGameStartAndReturn(int gameType)
- {
- //if (_Instance)
- //{
- // _Instance.shootingCount = 0;
- // _Instance.duration = 0;
- // _Instance.gameIsEnd = false;
- // return _Instance;
- //};
- UserGameAnalyse1 userGameAnalyse = new GameObject("UserGameAnaly1").AddComponent<UserGameAnalyse1>();
- userGameAnalyse.gameType = gameType;
- switch (gameType)
- {
- case 13:
- userGameAnalyse.targetScene = "DuckHunter";
- break;
- case 14:
- userGameAnalyse.targetScene = "WildAttack";
- break;
- case 15:
- userGameAnalyse.targetScene = "FruitMaster";
- break;
- case 16:
- userGameAnalyse.targetScene = "MovingTarget";
- break;
- }
- return userGameAnalyse;
- }
- void Awake()
- {
- _Instance = this;
- //DontDestroyOnLoad(gameObject);
- startTime = JCUnityLib.TimeUtils.GetTimestamp();
- sceneTimeOnStart = Time.realtimeSinceStartup;
- }
- void OnDestroy()
- {
- if (_Instance == this) _Instance = null;
- UploadData(true);
- }
- void Update()
- {
- //if (!IsTargetScene())
- //{
- // Destroy(gameObject);
- // return;
- //}
- if (gameIsEnd) return;
- duration = Time.realtimeSinceStartup - sceneTimeOnStart;
- if (duration / 60 >= uploadCountOnUpdate) //每60秒上传一次
- {
- uploadCountOnUpdate++;
- UploadData(false);
- }
- }
- public void UploadData(bool isEnd)
- {
- if (gameIsEnd) return;
- if (isEnd)
- {
- gameIsEnd = true;
- //本轮游戏结束时候,记录一次数据
- allTimeSecond += duration;
- }
- int durationTime = (int)duration;
- if (UserPlayer.ins != null)
- {
- UserPlayer.ins.call("UserGameAnalyseComp.uploadUserGameRecord", gameType, startTime, durationTime);
- //Debug.Log("上传" + targetScene + "(" + gameType + ")游戏时长统计数据:" + durationTime + ",allTimeSecond:" + allTimeSecond);
- }
- }
- bool IsTargetScene()
- {
- return SceneManager.GetActiveScene().name == targetScene;
- }
- public int changeShootingCount(int value = 1)
- {
- shootingCount += value;
- allShootingCount += value;
- return shootingCount;
- }
- public GameResultView showResultView(Action callback)
- {
- UploadData(true);
- //Debug.Log("ShowResultView" + targetScene + "(" + gameType + ") allTimeSecond:" + allTimeSecond + ",startTime:"+ startTime + ",duration:" + duration);
- StandaloneAPI.PauseGame();
- GameObject resultObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_GameResultView);
- GameInfo gameInfo = TextureMgr.ins.GetGameInfos(gameType);
- if (gameInfo == null) Debug.LogError("缺少GameInfo信息");
- GameResultView gameResultView = resultObj.GetComponent<GameResultView>();
- gameResultView.OnBackClicked += callback;
- gameResultView.setGameResultInfo(gameInfo.textId, (int)allTimeSecond, allShootingCount);
-
- //b端直接返回,不处理弹出框
- if (CommonConfig.StandaloneModeOrPlatformB)
- {
- resultObj.SetActive(false);
- callback?.Invoke();
- }
- onResetOverlayData();
- return gameResultView;
- }
- public void onResetOverlayData()
- {
- allTimeSecond = 0;
- allShootingCount = 0;
- }
- }
|