lvjincheng 3 лет назад
Родитель
Сommit
d35222b117

+ 63 - 0
Assets/BowArrow/Scripts/Expand/UserGameAnalyse1.cs

@@ -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";
+    }
+}

+ 11 - 0
Assets/BowArrow/Scripts/Expand/UserGameAnalyse1.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 0ceca427a63fc6e49ad8be3f31a11ef3
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 0
Assets/DuckHunter/Scripts/GameManager.cs

@@ -39,6 +39,8 @@ namespace DuckHunter
                 AutoNextLevel = false;
                 StartGame(true);
             }
+
+            UserGameAnalyse1.CreateWhenGameStart();
         }
 
         void Update()