mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
refactor(assets): 将资源相关抽象移至专用模块
- 将 AssetCatalog.cs、IAssetCatalogSystem.cs、IResourceFactorySystem.cs 和 ResourceFactory.cs 从 GFramework.Game 移至 GFramework.Game.Abstractions - 在 GFramework.Game 项目中添加对 GFramework.Game.Abstractions 的引用 - 更新 AbstractAssetCatalogSystem.cs 以使用新的命名空间引用 - 在 GFramework.Godot 项目中添加对 GFramework.Game.Abstractions 的引用 - 更新 ResourceLoadSystem.cs 以使用新的命名空间并修正命名空间声明 - 在解决方案文件中注册新的 GFramework.Game.Abstractions 项目 - 为 GFramework.Game.Abstractions 项目添加 Directory.Build.props 配置文件 - 在主项目文件中排除新抽象模块的编译和资源文件以避免重复包含
This commit is contained in:
parent
1a13809bae
commit
7299126a18
24
GFramework.Game.Abstractions/Directory.Build.props
Normal file
24
GFramework.Game.Abstractions/Directory.Build.props
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<Project>
|
||||||
|
<!-- import parent: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build -->
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
|
||||||
|
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||||
|
<!--
|
||||||
|
we use a higher version than supported by the target framework to have nullable types and other nice features
|
||||||
|
(a lot of features get polyfilled by Meziantou.Polyfill)
|
||||||
|
however we need to be careful with the available features!
|
||||||
|
-->
|
||||||
|
<LangVersion>preview</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Meziantou.Analyzer" Version="2.0.264">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Meziantou.Polyfill" Version="1.0.71">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
配置项目构建属性
|
||||||
|
设置项目不可打包、生成文档文件,并包含特定的Polyfill
|
||||||
|
-->
|
||||||
|
<PropertyGroup>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<MeziantouPolyfill_IncludedPolyfills>T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute</MeziantouPolyfill_IncludedPolyfills>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\GFramework.Core.Abstractions\GFramework.Core.Abstractions.csproj" PrivateAssets="all"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<!-- 引入必要的命名空间 -->
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="GFramework.Game.Abstractions"/>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
52
GFramework.Game.Abstractions/assets/AssetCatalog.cs
Normal file
52
GFramework.Game.Abstractions/assets/AssetCatalog.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
namespace System.Runtime.CompilerServices
|
||||||
|
{
|
||||||
|
// 这个类用于支持C# 9.0中的init访问器和记录类型功能
|
||||||
|
internal static class IsExternalInit;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace GFramework.Game.Abstractions.assets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 资源目录类,用于定义和管理游戏中的场景和资源标识符
|
||||||
|
/// </summary>
|
||||||
|
public static class AssetCatalog
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 资源标识符接口,定义了资源路径的访问接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IAssetId
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源的路径
|
||||||
|
/// </summary>
|
||||||
|
string Path { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源目录映射结构体,用于存储资源目录的键值对映射关系
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Key">资源目录的键</param>
|
||||||
|
/// <param name="Id">资源标识符</param>
|
||||||
|
public readonly record struct AssetCatalogMapping(string Key, IAssetId Id);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 场景页面资源标识符结构体,用于标识场景页面资源
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Path">场景页面资源路径</param>
|
||||||
|
public readonly record struct ScenePageId(string Path) : IAssetId;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 场景单元资源标识符结构体,用于标识场景单元资源
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Path">场景单元资源路径</param>
|
||||||
|
public readonly record struct SceneUnitId(string Path) : IAssetId;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通用资源标识符结构体,实现IAssetId接口
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Path">资源路径</param>
|
||||||
|
public readonly record struct AssetId(string Path) : IAssetId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
using GFramework.Core.Abstractions.system;
|
using GFramework.Core.Abstractions.system;
|
||||||
|
|
||||||
namespace GFramework.Game.assets;
|
namespace GFramework.Game.Abstractions.assets;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源目录系统接口,用于管理场景和资源的获取与查询
|
/// 资源目录系统接口,用于管理场景和资源的获取与查询
|
||||||
@ -1,6 +1,7 @@
|
|||||||
using GFramework.Core.Abstractions.system;
|
using System;
|
||||||
|
using GFramework.Core.Abstractions.system;
|
||||||
|
|
||||||
namespace GFramework.Game.assets;
|
namespace GFramework.Game.Abstractions.assets;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源工厂系统接口,用于获取指定类型的资源创建函数
|
/// 资源工厂系统接口,用于获取指定类型的资源创建函数
|
||||||
@ -1,4 +1,8 @@
|
|||||||
namespace GFramework.Game.assets;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace GFramework.Game.Abstractions.assets;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源工厂类,用于注册和解析各种资源的创建工厂
|
/// 资源工厂类,用于注册和解析各种资源的创建工厂
|
||||||
@ -8,5 +8,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\GFramework.Core\GFramework.Core.csproj"/>
|
<ProjectReference Include="..\GFramework.Core\GFramework.Core.csproj"/>
|
||||||
|
<ProjectReference Include="..\GFramework.Game.Abstractions\GFramework.Game.Abstractions.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using GFramework.Core.system;
|
using GFramework.Core.system;
|
||||||
|
using GFramework.Game.Abstractions.assets;
|
||||||
|
|
||||||
namespace GFramework.Game.assets;
|
namespace GFramework.Game.assets;
|
||||||
|
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
namespace GFramework.Game.assets;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源目录类,用于定义和管理游戏中的场景和资源标识符
|
|
||||||
/// </summary>
|
|
||||||
public static class AssetCatalog
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 资源标识符接口,定义了资源路径的访问接口
|
|
||||||
/// </summary>
|
|
||||||
public interface IAssetId
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 获取资源的路径
|
|
||||||
/// </summary>
|
|
||||||
string Path { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源目录映射结构体,用于存储资源目录的键值对映射关系
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="Key">资源目录的键</param>
|
|
||||||
/// <param name="Id">资源标识符</param>
|
|
||||||
public readonly record struct AssetCatalogMapping(string Key, IAssetId Id);
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 场景页面资源标识符结构体,用于标识场景页面资源
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="Path">场景页面资源路径</param>
|
|
||||||
public readonly record struct ScenePageId(string Path) : IAssetId;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 场景单元资源标识符结构体,用于标识场景单元资源
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="Path">场景单元资源路径</param>
|
|
||||||
public readonly record struct SceneUnitId(string Path) : IAssetId;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 通用资源标识符结构体,实现IAssetId接口
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="Path">资源路径</param>
|
|
||||||
public readonly record struct AssetId(string Path) : IAssetId;
|
|
||||||
}
|
|
||||||
@ -16,6 +16,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\GFramework.Core.Abstractions\GFramework.Core.Abstractions.csproj" PrivateAssets="all"/>
|
<ProjectReference Include="..\GFramework.Core.Abstractions\GFramework.Core.Abstractions.csproj" PrivateAssets="all"/>
|
||||||
|
<ProjectReference Include="..\GFramework.Game.Abstractions\GFramework.Game.Abstractions.csproj" PrivateAssets="all"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!-- 引入必要的命名空间 -->
|
<!-- 引入必要的命名空间 -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
using GFramework.Core.Abstractions.system;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using GFramework.Core.Abstractions.system;
|
||||||
|
using GFramework.Game.Abstractions.assets;
|
||||||
|
|
||||||
namespace GFramework.Godot.Abstractions.assets;
|
namespace GFramework.Godot.Abstractions.assets;
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\GFramework.Game.Abstractions\GFramework.Game.Abstractions.csproj"/>
|
||||||
<ProjectReference Include="..\GFramework.Game\GFramework.Game.csproj"/>
|
<ProjectReference Include="..\GFramework.Game\GFramework.Game.csproj"/>
|
||||||
<ProjectReference Include="..\GFramework.Godot.Abstractions\GFramework.Godot.Abstractions.csproj"/>
|
<ProjectReference Include="..\GFramework.Godot.Abstractions\GFramework.Godot.Abstractions.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using GFramework.Core.architecture;
|
using GFramework.Core.architecture;
|
||||||
using GFramework.Core.constants;
|
using GFramework.Core.constants;
|
||||||
|
using GFramework.Godot.Abstractions.architecture;
|
||||||
using GFramework.Godot.extensions;
|
using GFramework.Godot.extensions;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using GFramework.Core.Abstractions.architecture;
|
using GFramework.Core.Abstractions.architecture;
|
||||||
using GFramework.Core.architecture;
|
using GFramework.Core.architecture;
|
||||||
|
using GFramework.Godot.Abstractions.architecture;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace GFramework.Godot.architecture;
|
namespace GFramework.Godot.architecture;
|
||||||
@ -9,6 +10,11 @@ namespace GFramework.Godot.architecture;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractGodotModule : IGodotModule
|
public abstract class AbstractGodotModule : IGodotModule
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取模块关联的Godot节点
|
||||||
|
/// </summary>
|
||||||
|
public abstract Node Node { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当架构阶段发生变化时调用此方法
|
/// 当架构阶段发生变化时调用此方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -33,9 +39,11 @@ public abstract class AbstractGodotModule : IGodotModule
|
|||||||
public abstract void Install(IArchitecture architecture);
|
public abstract void Install(IArchitecture architecture);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取模块关联的Godot节点
|
/// 当模块从架构中分离时调用此方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract Node Node { get; }
|
public virtual void OnDetach()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当模块被附加到架构时调用此方法
|
/// 当模块被附加到架构时调用此方法
|
||||||
@ -44,11 +52,4 @@ public abstract class AbstractGodotModule : IGodotModule
|
|||||||
public virtual void OnAttach(Architecture architecture)
|
public virtual void OnAttach(Architecture architecture)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 当模块从架构中分离时调用此方法
|
|
||||||
/// </summary>
|
|
||||||
public virtual void OnDetach()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,9 +1,9 @@
|
|||||||
using GFramework.Core.system;
|
using GFramework.Core.system;
|
||||||
using GFramework.Game.assets;
|
using GFramework.Game.Abstractions.assets;
|
||||||
using GFramework.Godot.Abstractions.assets;
|
using GFramework.Godot.Abstractions.assets;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace GFramework.Godot.system;
|
namespace GFramework.Godot.assets;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源加载系统,用于统一管理和缓存Godot资源(如场景、纹理等)的加载与实例化。
|
/// 资源加载系统,用于统一管理和缓存Godot资源(如场景、纹理等)的加载与实例化。
|
||||||
|
|||||||
@ -44,6 +44,8 @@
|
|||||||
<None Remove="GFramework.Godot.SourceGenerators.Abstractions\**"/>
|
<None Remove="GFramework.Godot.SourceGenerators.Abstractions\**"/>
|
||||||
<None Remove="GFramework.SourceGenerators.Abstractions\**"/>
|
<None Remove="GFramework.SourceGenerators.Abstractions\**"/>
|
||||||
<None Remove="GFramework.Core.Abstractions\**"/>
|
<None Remove="GFramework.Core.Abstractions\**"/>
|
||||||
|
<None Remove="GFramework.Godot.Abstractions\**"/>
|
||||||
|
<None Remove="GFramework.Game.Abstractions\**"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!-- 聚合核心模块 -->
|
<!-- 聚合核心模块 -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -71,6 +73,8 @@
|
|||||||
<Compile Remove="GFramework.Godot.SourceGenerators.Abstractions\**"/>
|
<Compile Remove="GFramework.Godot.SourceGenerators.Abstractions\**"/>
|
||||||
<Compile Remove="GFramework.SourceGenerators.Abstractions\**"/>
|
<Compile Remove="GFramework.SourceGenerators.Abstractions\**"/>
|
||||||
<Compile Remove="GFramework.Core.Abstractions\**"/>
|
<Compile Remove="GFramework.Core.Abstractions\**"/>
|
||||||
|
<Compile Remove="GFramework.Godot.Abstractions\**"/>
|
||||||
|
<Compile Remove="GFramework.Game.Abstractions\**"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Remove="GFramework.Core\**"/>
|
<EmbeddedResource Remove="GFramework.Core\**"/>
|
||||||
@ -84,9 +88,8 @@
|
|||||||
<EmbeddedResource Remove="GFramework.Godot.SourceGenerators.Abstractions\**"/>
|
<EmbeddedResource Remove="GFramework.Godot.SourceGenerators.Abstractions\**"/>
|
||||||
<EmbeddedResource Remove="GFramework.SourceGenerators.Abstractions\**"/>
|
<EmbeddedResource Remove="GFramework.SourceGenerators.Abstractions\**"/>
|
||||||
<EmbeddedResource Remove="GFramework.Core.Abstractions\**"/>
|
<EmbeddedResource Remove="GFramework.Core.Abstractions\**"/>
|
||||||
</ItemGroup>
|
<EmbeddedResource Remove="GFramework.Godot.Abstractions\**"/>
|
||||||
<ItemGroup>
|
<EmbeddedResource Remove="GFramework.Game.Abstractions\**"/>
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.14.0"/>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AdditionalFiles Remove="AnalyzerReleases.Shipped.md"/>
|
<AdditionalFiles Remove="AnalyzerReleases.Shipped.md"/>
|
||||||
|
|||||||
@ -24,6 +24,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Core.Abstraction
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Godot.Abstractions", "GFramework.Godot.Abstractions\GFramework.Godot.Abstractions.csproj", "{EFE2EF31-CEAC-4BFD-851B-5E00FEBC945D}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Godot.Abstractions", "GFramework.Godot.Abstractions\GFramework.Godot.Abstractions.csproj", "{EFE2EF31-CEAC-4BFD-851B-5E00FEBC945D}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Game.Abstractions", "GFramework.Game.Abstractions\GFramework.Game.Abstractions.csproj", "{E20DBA4C-CEB9-4184-B614-5A99A9AE4472}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -78,5 +80,9 @@ Global
|
|||||||
{EFE2EF31-CEAC-4BFD-851B-5E00FEBC945D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{EFE2EF31-CEAC-4BFD-851B-5E00FEBC945D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{EFE2EF31-CEAC-4BFD-851B-5E00FEBC945D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{EFE2EF31-CEAC-4BFD-851B-5E00FEBC945D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{EFE2EF31-CEAC-4BFD-851B-5E00FEBC945D}.Release|Any CPU.Build.0 = Release|Any CPU
|
{EFE2EF31-CEAC-4BFD-851B-5E00FEBC945D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{E20DBA4C-CEB9-4184-B614-5A99A9AE4472}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E20DBA4C-CEB9-4184-B614-5A99A9AE4472}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E20DBA4C-CEB9-4184-B614-5A99A9AE4472}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E20DBA4C-CEB9-4184-B614-5A99A9AE4472}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user