forked from Misaki/GhostEngine
Major ECS API overhaul: added ComponentSet, refactored ComponentRegistry, and updated all entity/component creation methods. Introduced robust custom serialization infrastructure and per-component source generators for registration and (de)serialization. Updated editor, engine, and test code to use new APIs. Improved code quality, naming, and performance throughout. Removed obsolete code and updated dependencies.
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using Ghost.Editor.Core.Utilities;
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
|
|
namespace Ghost.Editor.Core.AssetHandle;
|
|
|
|
public static partial class AssetDatabase
|
|
{
|
|
private static readonly Dictionary<string, Action<string>> _assetOpenHandlers = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
private static void InitializeAssetHandle()
|
|
{
|
|
var methods = TypeCache.GetTypes()
|
|
.SelectMany(t => t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
|
|
.Where(m => m.GetCustomAttribute<AssetOpenHandlerAttribute>() != null &&
|
|
m.GetParameters().Length == 1 &&
|
|
m.GetParameters()[0].ParameterType == typeof(string));
|
|
|
|
foreach (var method in methods)
|
|
{
|
|
var attr = method.GetCustomAttribute<AssetOpenHandlerAttribute>()!;
|
|
var del = (Action<string>)Delegate.CreateDelegate(typeof(Action<string>), method);
|
|
foreach (var ext in attr.Extensions)
|
|
{
|
|
if (_assetOpenHandlers.ContainsKey(ext))
|
|
{
|
|
throw new InvalidOperationException($"Duplicate handler for extension '{ext}'");
|
|
}
|
|
|
|
_assetOpenHandlers[ext] = del;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void OpenAsset(string path)
|
|
{
|
|
var extension = Path.GetExtension(path);
|
|
if (_assetOpenHandlers.TryGetValue(extension, out var handler))
|
|
{
|
|
handler(path);
|
|
}
|
|
else
|
|
{
|
|
Process.Start(new ProcessStartInfo(path)
|
|
{
|
|
UseShellExecute = true
|
|
});
|
|
}
|
|
}
|
|
} |