first commit

This commit is contained in:
lethanhsonvsp
2025-11-17 15:36:52 +07:00
commit 6f2eafa33c
14093 changed files with 1253472 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using System.Diagnostics;
namespace Unity.VisualScripting
{
public class ProfiledSegment
{
public ProfiledSegment(ProfiledSegment parent, string name)
{
this.parent = parent;
this.name = name;
stopwatch = new Stopwatch();
children = new ProfiledSegmentCollection();
}
public string name { get; private set; }
public Stopwatch stopwatch { get; private set; }
public long calls { get; set; }
public ProfiledSegment parent { get; private set; }
public ProfiledSegmentCollection children { get; private set; }
}
}

View File

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

View File

@@ -0,0 +1,12 @@
using System.Collections.ObjectModel;
namespace Unity.VisualScripting
{
public class ProfiledSegmentCollection : KeyedCollection<string, ProfiledSegment>
{
protected override string GetKeyForItem(ProfiledSegment item)
{
return item.name;
}
}
}

View File

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

View File

@@ -0,0 +1,17 @@
using System;
namespace Unity.VisualScripting
{
public struct ProfilingScope : IDisposable
{
public ProfilingScope(string name)
{
ProfilingUtility.BeginSample(name);
}
public void Dispose()
{
ProfilingUtility.EndSample();
}
}
}

View File

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

View File

@@ -0,0 +1,68 @@
using System.Diagnostics;
using System.Threading;
using UnityEngine.Profiling;
namespace Unity.VisualScripting
{
public static class ProfilingUtility
{
static ProfilingUtility()
{
currentSegment = rootSegment = new ProfiledSegment(null, "Root");
}
private static readonly object @lock = new object();
public static ProfiledSegment rootSegment { get; private set; }
public static ProfiledSegment currentSegment { get; set; }
[Conditional("ENABLE_PROFILER")]
public static void Clear()
{
currentSegment = rootSegment = new ProfiledSegment(null, "Root");
}
public static ProfilingScope SampleBlock(string name)
{
return new ProfilingScope(name);
}
[Conditional("ENABLE_PROFILER")]
public static void BeginSample(string name)
{
Monitor.Enter(@lock);
if (!currentSegment.children.Contains(name))
{
currentSegment.children.Add(new ProfiledSegment(currentSegment, name));
}
currentSegment = currentSegment.children[name];
currentSegment.calls++;
currentSegment.stopwatch.Start();
if (UnityThread.allowsAPI)
{
Profiler.BeginSample(name);
}
}
[Conditional("ENABLE_PROFILER")]
public static void EndSample()
{
currentSegment.stopwatch.Stop();
if (currentSegment.parent != null)
{
currentSegment = currentSegment.parent;
}
if (UnityThread.allowsAPI)
{
Profiler.EndSample();
}
Monitor.Exit(@lock);
}
}
}

View File

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