Add debug feature

This commit is contained in:
Mikhail 2023-03-27 17:34:04 +08:00
parent 9509da8b95
commit 5f668bb516
7 changed files with 77 additions and 2 deletions

8
src/Debug.meta Normal file
View File

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

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6ed7ff62966b45141b388716e91dfac0 guid: 0c0c879077450ac479afb5b86efc5a93
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -0,0 +1,56 @@
using System;
using Unity.Profiling;
using UnityEngine;
namespace DCFApixels.DragonECS.Unity
{
public class UnityDebugService : DebugService
{
public static void Set()
{
DebugService.Set<UnityDebugService>();
}
private ProfilerMarker[] _profilerMarkers = new ProfilerMarker[64];
public override void Print(string tag, object v)
{
string log = $"[{tag}] {v}";
string taglower = tag.ToLower();
if (taglower.Contains("warning"))
{
Debug.LogWarning(log);
return;
}
if (taglower.Contains("error"))
{
Debug.LogError(log);
return;
}
Debug.Log(log);
}
public override void ProfileMarkBegin(int id)
{
_profilerMarkers[id].Begin();
}
public override double ProfileMarkEnd(int id)
{
_profilerMarkers[id].End();
return -1;
}
protected override void OnDelMark(int id)
{
_profilerMarkers[id] = default;
}
protected override void OnNewMark(int id, string name)
{
if (id >= _profilerMarkers.Length) Array.Resize(ref _profilerMarkers, _profilerMarkers.Length << 1);
_profilerMarkers[id] = new ProfilerMarker(ProfilerCategory.Scripts, name);
}
}
}

View File

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

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 1d334d67cff28704c94924d2e6c8df84 guid: 45a14256c767cab49879fb8aa88ec193
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2