From 40b52abb485b49fa6efdae8275f80596a21a3041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=A7=E9=9B=A8=E7=83=A8?= Date: Sun, 16 Jun 2024 17:05:19 +0800 Subject: [PATCH] fixed bug, add return for CreateItem --- scripts/item/ItemTypeManager.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/item/ItemTypeManager.cs b/scripts/item/ItemTypeManager.cs index cf7261d..f91b4e2 100644 --- a/scripts/item/ItemTypeManager.cs +++ b/scripts/item/ItemTypeManager.cs @@ -67,12 +67,13 @@ public static class ItemTypeManager /// 全局坐标中的位置 /// /// - public static void CreateItem(string id, Node? parent = null, Vector2? position = null) + public static IItem? CreateItem(string id, Node? parent = null, Vector2? position = null) { var item = NewItem(id); - parent?.AddChild(item as Node); - if (item is not Node2D node) return; + parent?.CallDeferred("add_child", (item as Node)!); + if (item is not Node2D node) return item; if (position is { } pos) node.GlobalPosition = pos; + return item; } /// @@ -87,12 +88,16 @@ public static class ItemTypeManager /// 全局坐标中的位置 /// /// - public static void CreateItems(string id, int amount, Node? parent = null, Vector2? position = null) + public static IList CreateItems(string id, int amount, Node? parent = null, Vector2? position = null) { + IList result = []; for (int i = 0; i < amount; i++) { - CreateItem(id, parent, position); + if (CreateItem(id, parent, position) is { } item) + result.Add(item); } + + return result; } ///