Refactor Vector3Field and update project structure

Changed Vector3Field.cs to derive from ValueControl<Vector3> and use NumberBox controls for better UI handling.
Changed EditorControls.xaml to update resource paths for new controls.
Changed InternalControls.xaml to simplify the resource dictionary by removing unnecessary references.
Changed IComponentEditor.cs to reflect updates in the component editor's lifecycle methods.
Changed project files for Ghost.Editor and Ghost.Core to include new dependencies and project references.
Changed FileExtensions.cs and IInspectorService.cs to align with the new namespace structure.
Changed Result.cs to enhance error handling and success checking methods.
Changed TypeHandle.cs to improve type handling compatibility.
Changed AssemblyInfo.cs files to include new assembly visibility attributes for better encapsulation.
Added new graphics-related classes and interfaces in the Ghost.Engine project, including IGraphicsDevice and DX12GraphicsDevice.
Added a new Mesh class to handle 3D mesh data and provide methods for creating geometric shapes.
Added GraphicsPipeline.cs to manage the graphics rendering loop and device initialization.
Added ScenePage.xaml and ScenePage.xaml.cs to create a new page for rendering scenes.
Updated HierarchyPage.xaml.cs and InspectorPage.xaml.cs to use the new service locator pattern for service retrieval.
Updated LandingWindow.xaml.cs and EngineEditorWindow.xaml.cs to utilize the new service locator pattern for better service access.
Updated Logger.cs to enhance logging capabilities with optional stack traces and assertion logging.
Updated QueryFilter.cs and QueryEnumerable.cs to use the new TypeHandle structure for improved efficiency.
Updated WorldNode.cs and WorldNodeSerializer.cs to enhance serialization and management of world nodes.
Updated AssetDatabase and related classes to improve asset management and metadata generation.
Updated Ghost.UnitTest.csproj to include new project references and package dependencies for unit tests.
This commit is contained in:
2025-06-27 20:02:02 +09:00
parent 1724072f7e
commit 4110c166cf
191 changed files with 2286 additions and 1462 deletions

View File

@@ -0,0 +1,158 @@
using Ghost.Core;
using Ghost.Editor.Core.Utilities;
using Ghost.Engine.Services;
using System.Reflection;
using System.Text.Json;
namespace Ghost.Editor.Core.AssetHandle;
public static partial class AssetDatabase
{
private static readonly Dictionary<string, Type> _importerTypeLookup = new();
private static void InitializeMetaData()
{
if (_watcher == null)
{
throw new InvalidOperationException("AssetDatabase is not initialized. Ensure that Initialize() is called before registering asset importers.");
}
var importerTypes = TypeCache.GetTypes().Where(t => t.GetCustomAttribute<AssetImporterAttribute>() != null);
foreach (var type in importerTypes)
{
var attribute = type.GetCustomAttribute<AssetImporterAttribute>()!;
foreach (var extension in attribute.SupportedExtensions)
{
_importerTypeLookup[extension] = type;
}
}
_watcher.Created += OnAssetCreated;
_watcher.Deleted += OnAssetDeleted;
_watcher.Renamed += OnAssetRenamed;
}
private static Result<string> GetMetaFilePath(string assetPath)
{
if (Directory.Exists(assetPath))
{
return Result<string>.Error("Folder does not have meta data");
}
if (Path.GetExtension(assetPath).Equals(".meta", StringComparison.OrdinalIgnoreCase))
{
return Result<string>.Error("Asset path cannot be a meta file");
}
return Result<string>.OK(assetPath + ".meta");
}
private static ImporterSettings? GetDefaultSettingsForAsset(string assetPath)
{
var extension = Path.GetExtension(assetPath);
if (_importerTypeLookup.TryGetValue(extension, out var importerType))
{
var settingsType = importerType.BaseType?.GetGenericArguments()[0];
if (settingsType == null || !typeof(ImporterSettings).IsAssignableFrom(settingsType))
{
return null;
}
return (ImporterSettings?)Activator.CreateInstance(settingsType);
}
return null;
}
private static void WriteMetaFile(string metaFilePath, AssetMeta metaData)
{
using var fileStream = File.Create(metaFilePath);
try
{
JsonSerializer.Serialize(fileStream, metaData);
}
catch (Exception ex)
{
Logger.LogError(ex);
}
}
internal static void GenerateMetaFile(string assetPath)
{
var metaFileResult = GetMetaFilePath(assetPath);
if (!metaFileResult.success)
{
Logger.LogError(metaFileResult.message);
return;
}
if (File.Exists(metaFileResult.value))
{
var existingMeta = JsonSerializer.Deserialize<AssetMeta>(File.ReadAllText(metaFileResult.value));
if (existingMeta != null && _assetPathLookup.TryGetValue(existingMeta.Guid, out var path))
{
if (assetPath != path)
{
existingMeta.Guid = Guid.NewGuid();
WriteMetaFile(metaFileResult.value, existingMeta);
}
}
return;
}
var defaultSettings = GetDefaultSettingsForAsset(assetPath);
var metaData = new AssetMeta
{
Guid = Guid.NewGuid(),
Settings = defaultSettings
};
WriteMetaFile(metaFileResult.value, metaData);
}
private static void OnAssetCreated(object sender, FileSystemEventArgs e)
{
GenerateMetaFile(e.FullPath);
}
private static void OnAssetDeleted(object sender, FileSystemEventArgs e)
{
var metaFileResult = GetMetaFilePath(e.FullPath);
if (metaFileResult.success && File.Exists(metaFileResult.value))
{
try
{
var meta = JsonSerializer.Deserialize<AssetMeta>(File.ReadAllText(metaFileResult.value));
if (meta != null
&& _assetPathLookup.TryGetValue(meta.Guid, out var path)
&& path == e.FullPath)
{
_assetPathLookup.Remove(meta.Guid);
}
File.Delete(metaFileResult.value);
}
catch (Exception ex)
{
Logger.LogError(ex);
}
}
}
private static void OnAssetRenamed(object sender, RenamedEventArgs e)
{
var oldMetaPath = e.OldFullPath + ".meta";
var newMetaPath = e.FullPath + ".meta";
if (File.Exists(oldMetaPath))
{
File.Move(oldMetaPath, newMetaPath);
}
else
{
GenerateMetaFile(e.FullPath);
}
}
}