update diagnostic system
This commit is contained in:
@@ -12,6 +12,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string OperationName;
|
||||
|
||||
/// <summary>
|
||||
/// 任务说明
|
||||
/// </summary>
|
||||
public string OperationDesc;
|
||||
|
||||
/// <summary>
|
||||
/// 优先级
|
||||
/// </summary>
|
||||
@@ -37,6 +42,12 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string Status;
|
||||
|
||||
/// <summary>
|
||||
/// 子任务列表
|
||||
/// TODO : Serialization depth limit 10 exceeded
|
||||
/// </summary>
|
||||
public List<DebugOperationInfo> Childs;
|
||||
|
||||
public int CompareTo(DebugOperationInfo other)
|
||||
{
|
||||
return Compare(this, other);
|
||||
|
||||
@@ -10,6 +10,11 @@ namespace YooAsset
|
||||
/// 采样一次
|
||||
/// </summary>
|
||||
SampleOnce = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 自动采集
|
||||
/// </summary>
|
||||
SampleAuto = 1,
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace YooAsset
|
||||
{
|
||||
internal class RemoteDebuggerDefine
|
||||
{
|
||||
public static readonly Guid kMsgSendPlayerToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
|
||||
public static readonly Guid kMsgSendEditorToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
|
||||
public static readonly Guid kMsgPlayerSendToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
|
||||
public static readonly Guid kMsgEditorSendToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
|
||||
}
|
||||
}
|
||||
@@ -7,47 +7,66 @@ namespace YooAsset
|
||||
{
|
||||
internal class RemoteDebuggerInRuntime : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 编辑器下获取报告的回调
|
||||
/// </summary>
|
||||
public static Action<int, DebugReport> EditorHandleDebugReportCallback;
|
||||
private static bool _sampleOnce = false;
|
||||
private static bool _autoSample = false;
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下请求报告数据
|
||||
/// </summary>
|
||||
public static void EditorRequestDebugReport()
|
||||
private void Awake()
|
||||
{
|
||||
if (UnityEditor.EditorApplication.isPlaying)
|
||||
{
|
||||
var report = YooAssets.GetDebugReport();
|
||||
EditorHandleDebugReportCallback?.Invoke(0, report);
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
RemotePlayerConnection.Instance.Initialize();
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
private void OnEnable()
|
||||
{
|
||||
PlayerConnection.instance.Register(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
|
||||
#if UNITY_EDITOR
|
||||
RemotePlayerConnection.Instance.Register(RemoteDebuggerDefine.kMsgEditorSendToPlayer, OnHandleEditorMessage);
|
||||
#else
|
||||
PlayerConnection.instance.Register(RemoteDebuggerDefine.kMsgEditorSendToPlayer, OnHandleEditorMessage);
|
||||
#endif
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
PlayerConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
|
||||
#if UNITY_EDITOR
|
||||
RemotePlayerConnection.Instance.Unregister(RemoteDebuggerDefine.kMsgEditorSendToPlayer);
|
||||
#else
|
||||
PlayerConnection.instance.Unregister(RemoteDebuggerDefine.kMsgEditorSendToPlayer, OnHandleEditorMessage);
|
||||
#endif
|
||||
}
|
||||
private void OnHandleEditorMessage(MessageEventArgs args)
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (_autoSample || _sampleOnce)
|
||||
{
|
||||
_sampleOnce = false;
|
||||
var debugReport = YooAssets.GetDebugReport();
|
||||
var data = DebugReport.Serialize(debugReport);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
RemotePlayerConnection.Instance.Send(RemoteDebuggerDefine.kMsgPlayerSendToEditor, data);
|
||||
#else
|
||||
PlayerConnection.instance.Send(RemoteDebuggerDefine.kMsgPlayerSendToEditor, data);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnHandleEditorMessage(MessageEventArgs args)
|
||||
{
|
||||
var command = RemoteCommand.Deserialize(args.data);
|
||||
YooLogger.Log($"On handle remote command : {command.CommandType} Param : {command.CommandParam}");
|
||||
if (command.CommandType == (int)ERemoteCommand.SampleOnce)
|
||||
{
|
||||
var debugReport = YooAssets.GetDebugReport();
|
||||
var data = DebugReport.Serialize(debugReport);
|
||||
PlayerConnection.instance.Send(RemoteDebuggerDefine.kMsgSendPlayerToEditor, data);
|
||||
_sampleOnce = true;
|
||||
}
|
||||
else if (command.CommandType == (int)ERemoteCommand.SampleAuto)
|
||||
{
|
||||
if (command.CommandParam == "open")
|
||||
_autoSample = true;
|
||||
else
|
||||
_autoSample = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException(command.CommandType.ToString());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Networking.PlayerConnection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RemoteEditorConnection
|
||||
{
|
||||
private static RemoteEditorConnection _instance;
|
||||
public static RemoteEditorConnection Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
_instance = new RemoteEditorConnection();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<Guid, UnityAction<MessageEventArgs>> _messageCallbacks = new Dictionary<Guid, UnityAction<MessageEventArgs>>();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_messageCallbacks.Clear();
|
||||
}
|
||||
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
|
||||
{
|
||||
if (messageID == Guid.Empty)
|
||||
throw new ArgumentException("messageID is empty !");
|
||||
|
||||
if (_messageCallbacks.ContainsKey(messageID) == false)
|
||||
_messageCallbacks.Add(messageID, callback);
|
||||
}
|
||||
public void Unregister(Guid messageID)
|
||||
{
|
||||
if (_messageCallbacks.ContainsKey(messageID))
|
||||
_messageCallbacks.Remove(messageID);
|
||||
}
|
||||
public void Send(Guid messageID, byte[] data)
|
||||
{
|
||||
if (messageID == Guid.Empty)
|
||||
throw new ArgumentException("messageID is empty !");
|
||||
|
||||
// 接收对方的消息
|
||||
RemotePlayerConnection.Instance.HandleEditorMessage(messageID, data);
|
||||
}
|
||||
|
||||
internal void HandlePlayerMessage(Guid messageID, byte[] data)
|
||||
{
|
||||
if (_messageCallbacks.TryGetValue(messageID, out UnityAction<MessageEventArgs> value))
|
||||
{
|
||||
var args = new MessageEventArgs();
|
||||
args.playerId = 0;
|
||||
args.data = data;
|
||||
value?.Invoke(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 557f37a710d7e2c4d80fe0f778d66463
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Networking.PlayerConnection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RemotePlayerConnection
|
||||
{
|
||||
private static RemotePlayerConnection _instance;
|
||||
public static RemotePlayerConnection Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
_instance = new RemotePlayerConnection();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<Guid, UnityAction<MessageEventArgs>> _messageCallbacks = new Dictionary<Guid, UnityAction<MessageEventArgs>>();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Debug.LogWarning("X=Initialize");
|
||||
_messageCallbacks.Clear();
|
||||
}
|
||||
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
|
||||
{
|
||||
Debug.LogWarning("X=Register");
|
||||
if (messageID == Guid.Empty)
|
||||
throw new ArgumentException("messageID is empty !");
|
||||
|
||||
if (_messageCallbacks.ContainsKey(messageID) == false)
|
||||
_messageCallbacks.Add(messageID, callback);
|
||||
}
|
||||
public void Unregister(Guid messageID)
|
||||
{
|
||||
Debug.LogWarning("X=Unregister");
|
||||
if (_messageCallbacks.ContainsKey(messageID))
|
||||
_messageCallbacks.Remove(messageID);
|
||||
}
|
||||
public void Send(Guid messageID, byte[] data)
|
||||
{
|
||||
if (messageID == Guid.Empty)
|
||||
throw new ArgumentException("messageID is empty !");
|
||||
|
||||
// 接收对方的消息
|
||||
RemoteEditorConnection.Instance.HandlePlayerMessage(messageID, data);
|
||||
}
|
||||
|
||||
internal void HandleEditorMessage(Guid messageID, byte[] data)
|
||||
{
|
||||
if (_messageCallbacks.TryGetValue(messageID, out UnityAction<MessageEventArgs> value))
|
||||
{
|
||||
var args = new MessageEventArgs();
|
||||
args.playerId = 0;
|
||||
args.data = data;
|
||||
value?.Invoke(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a726a61cbc448749a4ee80b8c9860b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user