소스 검색

app-用户数据记录

lvjincheng 3 년 전
부모
커밋
583f42ee1e

+ 50 - 0
Assets/BowArrow/Scripts/Expand/UserGameAnalyse.cs

@@ -0,0 +1,50 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class UserGameAnalyse : MonoBehaviour
+{
+    int gameType;
+    long startTime; //毫秒
+    float duration; //秒
+    float sceneTimeOnStart;
+    float uploadCountOnUpdate = 0;
+    bool gameIsEnd = false;
+
+    public static void CreateWhenGameStart(int gameType) {
+        new GameObject("UserGameAnaly").AddComponent<UserGameAnalyse>().gameType = gameType;
+    }
+
+    void Start()
+    {
+        startTime = JC.CS.Utility.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; 
+        try {
+            UserPlayer.ins.call("UserGameAnalyseComp.uploadUserGameRecord", gameType, startTime, (int) duration);    
+        }
+        catch (System.Exception) {}
+    }
+}

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

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

+ 1 - 0
Assets/BowArrow/Scripts/Manager/GameMgr.cs

@@ -38,6 +38,7 @@ public class GameMgr : MonoBehaviour
             }
         }
         // GameSceneLoadBtns.Create();
+        UserGameAnalyse.CreateWhenGameStart(gameType);
     }
 
     void Start()