Browse Source

增加ISendLogService代码

蓝色星空 1 year ago
parent
commit
d3c8d8cbc1

+ 60 - 2
Assets/Prefab/BluePrefabs/BlueRoot.prefab

@@ -30,7 +30,7 @@ Transform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 5886227751517987777}
-  m_RootOrder: 0
+  m_RootOrder: 1
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!114 &1004673917
 MonoBehaviour:
@@ -74,7 +74,7 @@ Transform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 5886227751517987777}
-  m_RootOrder: 1
+  m_RootOrder: 2
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!114 &1691766443
 MonoBehaviour:
@@ -99,6 +99,7 @@ GameObject:
   serializedVersion: 6
   m_Component:
   - component: {fileID: 5886227751517987777}
+  - component: {fileID: 6577798671095520273}
   m_Layer: 0
   m_Name: BlueRoot
   m_TagString: Untagged
@@ -118,8 +119,65 @@ Transform:
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children:
+  - {fileID: 5192568582079240754}
   - {fileID: 1004673916}
   - {fileID: 1691766442}
   m_Father: {fileID: 0}
   m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!114 &6577798671095520273
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 4965398655029255260}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 4632509381976ba4c9f1e18039e130cd, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+--- !u!1 &8893702449747549102
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 5192568582079240754}
+  - component: {fileID: 5439870886630026804}
+  m_Layer: 0
+  m_Name: SendLog
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!4 &5192568582079240754
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 8893702449747549102}
+  m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 5886227751517987777}
+  m_RootOrder: 0
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!114 &5439870886630026804
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 8893702449747549102}
+  m_Enabled: 0
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 6c86d5592573321408bd23353c7aa8ca, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 

+ 1 - 1
Assets/Scripts/Blue/MRNavigatorPro.cs

@@ -16,7 +16,7 @@ public class MRNavigatorPro : AbstractArchitecture<MRNavigatorPro>
 
     private void RegisterService()
     {
-
+        this.RegisterService<ISendLogService>(new SendLogService());
     }
 
     private void RegisterUtility()

+ 83 - 0
Assets/Scripts/Blue/Service/ISendLogService.cs

@@ -0,0 +1,83 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.Text;
+using Blue;
+using LitJson;
+using UnityEngine;
+using UnityEngine.Networking;
+
+public interface ISendLogService : IService
+{
+    void SendLog(string tag, string message);
+}
+
+public class SendLogService : ISendLogService
+{
+    private Queue<string> sendLogMessage;
+    private Dictionary<string, string> requestHeader = new Dictionary<string, string>();  //  header
+    private BindableProperty<int> MessageCount { get; set; } = new BindableProperty<int> { Value = 0 };
+    public void OnInit()
+    {
+        requestHeader.Add("Content-Type", "application/json");
+        sendLogMessage = new Queue<string>();
+        MessageCount.Subscribe(newInt=>
+        {
+            PostMessage("", sendLogMessage.Dequeue());
+        });
+    }
+    public void SendLog(string level, string message)
+    {
+        SendLogInfo sendHLog = new SendLogInfo();
+        sendHLog.level = level;
+        sendHLog.tag = Application.productName;
+        sendHLog.message = message;
+
+        string json = JsonMapper.ToJson(sendHLog);
+        sendLogMessage.Enqueue(json);
+
+        MessageCount.Value += 1;
+    }
+
+    private void PostMessage(string methodName, string jsonString)
+    {
+        CoroutineExtensionUtility.StartCoroutine(PostRequestTest(methodName, jsonString));
+    }
+    private IEnumerator PostRequestTest(string methodName, string jsonString)
+    {
+        string url = "https://fat2.qulivr.com/mr-navigator/v1/unity/log";
+        Debug.Log(url + jsonString);
+
+        using (UnityWebRequest webRequest = new UnityWebRequest(url, "POST"))
+        {
+            byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonString);
+            webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
+            webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
+
+            foreach (var v in requestHeader)
+            {
+                webRequest.SetRequestHeader(v.Key, v.Value);
+            }
+
+            yield return webRequest.SendWebRequest();
+
+            if (webRequest.error != null)
+            {
+                Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text + "\n" + methodName);
+                //GameManager.Instance.text2.text = webRequest.error;
+            }
+            else
+            {
+                Debug.Log(webRequest.downloadHandler.text);
+
+            }
+        }
+    }
+}
+
+public class SendLogInfo
+{
+    public string level { get; set; }
+    public string tag { get; set; }
+    public string message { get; set; }
+
+}

+ 11 - 0
Assets/Scripts/Blue/Service/ISendLogService.cs.meta

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

+ 8 - 0
Assets/Scripts/Blue/System.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: e58a0f87610d1694b8bf9e733412269e
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 22 - 0
Assets/Scripts/Blue/System/RootSystem.cs

@@ -0,0 +1,22 @@
+using System.Collections;
+using UnityEngine;
+using Blue;
+
+public class RootSystem : SingletonMonobehaviour<RootSystem>
+{
+    /// <summary>
+    /// 启动一个协程
+    /// </summary>
+    public Coroutine Start_Coroutine(IEnumerator coroutine)
+    {
+        return StartCoroutine(coroutine);
+    }
+
+    /// <summary>
+    /// 停止一个协程序
+    /// </summary>
+    public void Stop_Coroutine(Coroutine routine)
+    {
+        StopCoroutine(routine);
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/System/RootSystem.cs.meta

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

+ 19 - 0
Assets/Scripts/Blue/Test/TempSendLog.cs

@@ -0,0 +1,19 @@
+using Blue;
+using UnityEngine;
+
+/// <summary>
+/// 发送日志测试代码
+/// </summary>
+public class TempSendLog : AbstractController
+{
+    private int TempCount = 0;
+    void Update()
+    {
+        if (Input.GetKeyDown(KeyCode.L))
+        {
+            TempCount++;
+            this.GetService<ISendLogService>().SendLog("Blue","Temp:"+TempCount);
+            Debug.LogError("Temp:"+TempCount);
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/Test/TempSendLog.cs.meta

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

+ 15 - 0
Assets/Scripts/Blue/Utility/CoroutineExtensionUtility.cs

@@ -0,0 +1,15 @@
+using System.Collections;
+using UnityEngine;
+
+public static class CoroutineExtensionUtility
+{
+    public static void StartCoroutine(IEnumerator  coroutine)
+    {
+        RootSystem.Instance.Start_Coroutine(coroutine);
+    }
+
+    public static void StopCoroutine(Coroutine  coroutine)
+    {
+        RootSystem.Instance.Stop_Coroutine(coroutine);
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/Utility/CoroutineExtensionUtility.cs.meta

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