From fdc51e23b7252afe0ee2ba2581587f498e506371 Mon Sep 17 00:00:00 2001
From: GwWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Thu, 11 Dec 2025 10:14:00 +0800
Subject: [PATCH] =?UTF-8?q?refactor(godot):=20=E9=87=8D=E6=9E=84Godot?=
=?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=89=A9=E5=B1=95=E5=B9=B6=E8=BF=81=E7=A7=BB?=
=?UTF-8?q?=E8=87=B3=E6=96=B0=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 将NodeExtensions和UnRegisterExtension迁移至GFramework.Core.Godot项目
- 更新命名空间以匹配新的项目结构
- 为扩展方法参数添加可空注解以提高安全性
- 移除旧的条件编译指令#if GODOT和#endif
- 创建新的GFramework.Core.Godot.csproj项目文件
- 在解决方案中注册新的GFramework.Core.Godot项目
- 更新主项目文件以排除新项目中的文件冲突
- 添加GodotSharpEditor包引用以支持Godot编辑器功能
- 链接新项目的扩展文件到原有路径以保持兼容性
---
.../GFramework.Core.Godot.csproj | 18 ++++++++++++++++++
.../godot/extensions}/NodeExtensions.cs | 17 +++++++----------
.../godot}/extensions/UnRegisterExtension.cs | 9 +++------
GFramework.csproj | 12 ++++++++++++
GFramework.sln | 6 ++++++
5 files changed, 46 insertions(+), 16 deletions(-)
create mode 100644 GFramework.Core.Godot/GFramework.Core.Godot.csproj
rename {GFramework.Core/godot => GFramework.Core.Godot/godot/extensions}/NodeExtensions.cs (89%)
rename {GFramework.Core => GFramework.Core.Godot/godot}/extensions/UnRegisterExtension.cs (89%)
diff --git a/GFramework.Core.Godot/GFramework.Core.Godot.csproj b/GFramework.Core.Godot/GFramework.Core.Godot.csproj
new file mode 100644
index 0000000..7b08386
--- /dev/null
+++ b/GFramework.Core.Godot/GFramework.Core.Godot.csproj
@@ -0,0 +1,18 @@
+
+
+
+ GeWuYou.GFramework.Core.Godot
+ enable
+ enable
+ net9.0;net8.0
+
+
+
+
+
+
+
+
+
+
+
diff --git a/GFramework.Core/godot/NodeExtensions.cs b/GFramework.Core.Godot/godot/extensions/NodeExtensions.cs
similarity index 89%
rename from GFramework.Core/godot/NodeExtensions.cs
rename to GFramework.Core.Godot/godot/extensions/NodeExtensions.cs
index 9e22fe9..3317682 100644
--- a/GFramework.Core/godot/NodeExtensions.cs
+++ b/GFramework.Core.Godot/godot/extensions/NodeExtensions.cs
@@ -1,7 +1,5 @@
-#if GODOT
-using System.Threading.Tasks;
-using Godot;
-namespace GFramework.framework.godot;
+using Godot;
+namespace GFramework.Core.Godot.godot.extensions;
///
/// 节点扩展方法类,提供对Godot节点的扩展功能
@@ -12,7 +10,7 @@ public static class NodeExtensions
/// 安全地将节点加入删除队列,在下一帧开始时释放节点资源
///
/// 要释放的节点实例
- public static void QueueFreeX(this Node node)
+ public static void QueueFreeX(this Node? node)
{
// 检查节点是否为空
if (node is null)
@@ -40,7 +38,7 @@ public static class NodeExtensions
/// 立即释放节点资源,不等待下一帧
///
/// 要立即释放的节点实例
- public static void FreeX(this Node node)
+ public static void FreeX(this Node? node)
{
// 检查节点是否为空
if (node is null)
@@ -82,7 +80,7 @@ public static class NodeExtensions
/// 2. Godot 实例仍然存在(未被释放)
/// 3. 已经加入 SceneTree
///
- public static bool IsValidNode(this Node node)
+ public static bool IsValidNode(this Node? node)
{
return node is not null &&
GodotObject.IsInstanceValid(node) &&
@@ -97,11 +95,10 @@ public static class NodeExtensions
///
/// 返回 true 表示该节点不可用。
///
- public static bool IsInvalidNode(this Node node)
+ public static bool IsInvalidNode(this Node? node)
{
return node is null ||
!GodotObject.IsInstanceValid(node) ||
!node.IsInsideTree();
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/GFramework.Core/extensions/UnRegisterExtension.cs b/GFramework.Core.Godot/godot/extensions/UnRegisterExtension.cs
similarity index 89%
rename from GFramework.Core/extensions/UnRegisterExtension.cs
rename to GFramework.Core.Godot/godot/extensions/UnRegisterExtension.cs
index 8624599..0b317dc 100644
--- a/GFramework.Core/extensions/UnRegisterExtension.cs
+++ b/GFramework.Core.Godot/godot/extensions/UnRegisterExtension.cs
@@ -1,8 +1,7 @@
-#if GODOT
+using GFramework.Core.events;
using Godot;
-using GWFramework.framework.events;
-namespace GWFramework.framework.extensions;
+namespace GFramework.Core.Godot.godot.extensions;
///
/// 提供取消注册扩展方法的静态类
@@ -21,6 +20,4 @@ public static class UnRegisterExtension
node.TreeExiting += unRegister.UnRegister;
return unRegister;
}
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/GFramework.csproj b/GFramework.csproj
index 3a64a79..d06260d 100644
--- a/GFramework.csproj
+++ b/GFramework.csproj
@@ -38,6 +38,18 @@
+
+
+
+
+ GFramework.Godot\godot\extensions\NodeExtensions.cs
+
+
+ GFramework.Godot\godot\extensions\UnRegisterExtension.cs
+
+
+
+
diff --git a/GFramework.sln b/GFramework.sln
index e5505f5..5fb5554 100644
--- a/GFramework.sln
+++ b/GFramework.sln
@@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Generator.Attrib
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Core", "GFramework.Core\GFramework.Core.csproj", "{A6D5854D-79EA-487A-9ED9-396E6A1F8031}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Core.Godot", "GFramework.Core.Godot\GFramework.Core.Godot.csproj", "{FC56D81A-3A3B-4B49-B318-363DFA0D8206}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -30,5 +32,9 @@ Global
{A6D5854D-79EA-487A-9ED9-396E6A1F8031}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6D5854D-79EA-487A-9ED9-396E6A1F8031}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6D5854D-79EA-487A-9ED9-396E6A1F8031}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FC56D81A-3A3B-4B49-B318-363DFA0D8206}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FC56D81A-3A3B-4B49-B318-363DFA0D8206}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FC56D81A-3A3B-4B49-B318-363DFA0D8206}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FC56D81A-3A3B-4B49-B318-363DFA0D8206}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal