|
|
@@ -0,0 +1,63 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+using UnityEngine.SceneManagement;
|
|
|
+
|
|
|
+//打鸭子专用
|
|
|
+/* 用户游戏情况统计分析-主要向服务器是上传用户游戏数据 */
|
|
|
+public class UserGameAnalyse1 : MonoBehaviour
|
|
|
+{
|
|
|
+ int gameType;
|
|
|
+ long startTime; //毫秒
|
|
|
+ float duration; //秒
|
|
|
+ float sceneTimeOnStart;
|
|
|
+ float uploadCountOnUpdate = 0;
|
|
|
+
|
|
|
+ private static UserGameAnalyse1 _Instance;
|
|
|
+
|
|
|
+ public static void CreateWhenGameStart() {
|
|
|
+ if (_Instance) return;
|
|
|
+ new GameObject("UserGameAnaly1").AddComponent<UserGameAnalyse1>();
|
|
|
+ }
|
|
|
+
|
|
|
+ void Awake()
|
|
|
+ {
|
|
|
+ _Instance = this;
|
|
|
+ DontDestroyOnLoad(gameObject);
|
|
|
+ gameType = 13;
|
|
|
+ startTime = JCUnityLib.TimeUtils.GetTimestamp();
|
|
|
+ sceneTimeOnStart = Time.realtimeSinceStartup;
|
|
|
+ }
|
|
|
+
|
|
|
+ void OnDestroy() {
|
|
|
+ if (_Instance == this) _Instance = null;
|
|
|
+ UploadData();
|
|
|
+ }
|
|
|
+
|
|
|
+ void Update()
|
|
|
+ {
|
|
|
+ if (!IsTargetScene())
|
|
|
+ {
|
|
|
+ Destroy(gameObject);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ duration = Time.realtimeSinceStartup - sceneTimeOnStart;
|
|
|
+ if (duration / 60 >= uploadCountOnUpdate) //每60秒上传一次
|
|
|
+ {
|
|
|
+ uploadCountOnUpdate++;
|
|
|
+ UploadData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void UploadData()
|
|
|
+ {
|
|
|
+ int durationTime = (int) duration;
|
|
|
+ UserPlayer.ins.call("UserGameAnalyseComp.uploadUserGameRecord", gameType, startTime, durationTime);
|
|
|
+ Debug.Log("上传用户打鸭子游戏时长统计数据:" + durationTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ bool IsTargetScene()
|
|
|
+ {
|
|
|
+ return SceneManager.GetActiveScene().name == "DuckHunter";
|
|
|
+ }
|
|
|
+}
|