1
This commit is contained in:
82
Unity/Scripts/Diagnostics/UnityDiagnostics.cs
Normal file
82
Unity/Scripts/Diagnostics/UnityDiagnostics.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine.Pool;
|
||||
using BITModel;
|
||||
namespace BITKit
|
||||
{
|
||||
public class UnityDiagnostics : MonoBehaviour, IDiagnostics
|
||||
{
|
||||
[BITCommand]
|
||||
public static void SelfDiagnostics()
|
||||
{
|
||||
singleton.Diagnostics();
|
||||
}
|
||||
static UnityDiagnostics singleton;
|
||||
public Provider output;
|
||||
[ContextMenu(nameof(Diagnostics))]
|
||||
public void Diagnostics()
|
||||
{
|
||||
if (output)
|
||||
{
|
||||
BIT4Log.Log<UnityDiagnostics>("已找到Output");
|
||||
}
|
||||
else
|
||||
{
|
||||
BIT4Log.Warnning<UnityDiagnostics>("没有找到Output");
|
||||
var components = GetComponents<MonoBehaviour>();
|
||||
foreach (var x in components)
|
||||
{
|
||||
BIT4Log.Log<UnityDiagnostics>($"已找到组件:{x.name}");
|
||||
}
|
||||
return;
|
||||
}
|
||||
var dictionary = DictionaryPool<string, object>.Get();
|
||||
List<GameObject> gameObjects = new();
|
||||
gameObjects.AddRange(gameObject.scene.GetRootGameObjects());
|
||||
//gameObjects.Add(BITAppForUnity.GameObject);
|
||||
|
||||
BIT4Log.Log<UnityDiagnostics>("已完成场景加载");
|
||||
var diagnostics = gameObjects
|
||||
.SelectMany(x => x ? x.GetComponentsInChildren<IDiagnostics>() : null);
|
||||
try
|
||||
{
|
||||
BIT4Log.Log<UnityDiagnostics>($"正在诊断:");
|
||||
foreach (var dx in diagnostics)
|
||||
{
|
||||
if (dx is not null)
|
||||
{
|
||||
BIT4Log.Log($"{dx.GetName()}:{dx.GetDiagnostics()}");
|
||||
dictionary.Add(dx.GetName(), dx.GetDiagnostics());
|
||||
}
|
||||
else
|
||||
BIT4Log.Log<UnityDiagnostics>($"检测到引用异常");
|
||||
}
|
||||
var json = JsonConvert.SerializeObject(dictionary, Formatting.Indented);
|
||||
output.Set(json);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
BIT4Log.Log<UnityDiagnostics>("已完成诊断");
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return gameObject.name;
|
||||
}
|
||||
|
||||
public object GetDiagnostics()
|
||||
{
|
||||
return "OK";
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
singleton = this;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user