96 lines
2.5 KiB
C#
96 lines
2.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using Valheim;
|
|
|
|
public class DataReportManager : MonoBehaviour
|
|
{
|
|
public static DataReportManager Ins { get; private set; }
|
|
|
|
private DataReportInfo info;
|
|
private long gameStart = 0;
|
|
private int totalShots = 0;
|
|
private int totalHits = 0;
|
|
private int death = 0;
|
|
private float moveDis = 0f;
|
|
private Vector3 lastPos = Vector3.zero;
|
|
|
|
void Awake()
|
|
{
|
|
Ins = this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (gameStart != 0 && GameInit.Ins.self != null)
|
|
{
|
|
if (lastPos != Vector3.zero)
|
|
{
|
|
moveDis += Vector3.Distance(lastPos, GameInit.Ins.self.transform.position);
|
|
}
|
|
lastPos = GameInit.Ins.self.transform.position;
|
|
}
|
|
}
|
|
|
|
void Init()
|
|
{
|
|
info = new DataReportInfo();
|
|
info.gamePackageName = "com.njartech.dinosaur";
|
|
info.versionNumber = "1.0.4";
|
|
info.gameLaunchTime = (long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
|
totalShots = 0;
|
|
totalHits = 0;
|
|
death = 0;
|
|
moveDis = 0;
|
|
}
|
|
|
|
public void ShotAdd()
|
|
{
|
|
totalShots++;
|
|
}
|
|
|
|
public void HitAdd()
|
|
{
|
|
totalHits++;
|
|
}
|
|
|
|
public void DeathAdd()
|
|
{
|
|
death++;
|
|
}
|
|
|
|
// 开始记录
|
|
public void StartRecord(bool debug = false)
|
|
{
|
|
info.debug = debug;
|
|
info.isMaster = MRNetworkManager.Ins.mode == Mirror.NetworkManagerMode.ClientOnly ? false : true;
|
|
gameStart = (long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
|
info.gameStartTime = gameStart;
|
|
}
|
|
|
|
// 停止记录
|
|
public DataReportInfo StopRecord()
|
|
{
|
|
// info.deviceIp = GameManager.Ins.GetIP();
|
|
info.deviceId = GameManager.Ins.GetSn();
|
|
info.roomId = info.deviceId + "-" + GameManager.ConvertTimestampToDateTime(MRNetworkManager.Ins.CreateTime);
|
|
long nowTime = (long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
|
info.gameEndTime = nowTime;
|
|
info.appExitTime = nowTime;
|
|
info.gameDurationSeconds = (int)(nowTime - gameStart);
|
|
info.totalOnlinePlayers = MRNetworkManager.Ins.numPlayers;
|
|
info.totalShotsFired = totalShots;
|
|
info.totalHits = totalHits;
|
|
info.hitRate = 0;
|
|
info.deathCount = 0;
|
|
info.totalMovementDistanceMeters = moveDis;
|
|
info.playerHeightCm = (int)(Camera.main.transform.position.y * 100);
|
|
info.score = 0;
|
|
return info;
|
|
}
|
|
}
|