diff --git a/DungeonShooting_Godot/DungeonShooting.csproj b/DungeonShooting_Godot/DungeonShooting.csproj index db88a8d..cdcc424 100644 --- a/DungeonShooting_Godot/DungeonShooting.csproj +++ b/DungeonShooting_Godot/DungeonShooting.csproj @@ -2,4 +2,13 @@ net472 + + + + + + + + + \ No newline at end of file diff --git a/DungeonShooting_Godot/scene/TestNavigation.tscn b/DungeonShooting_Godot/scene/TestNavigation.tscn index 7db499e..d310e7d 100644 --- a/DungeonShooting_Godot/scene/TestNavigation.tscn +++ b/DungeonShooting_Godot/scene/TestNavigation.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=8 format=2] -[ext_resource path="res://src/game/TestNavigation.cs" type="Script" id=1] +[ext_resource path="res://src/test/TestNavigation.cs" type="Script" id=1] [ext_resource path="res://icon.png" type="Texture" id=2] [ext_resource path="res://resource/sprite/environment/craftpix-net-248911/16x16.png" type="Texture" id=3] diff --git a/DungeonShooting_Godot/src/framework/Component.cs b/DungeonShooting_Godot/src/framework/Component.cs index 87cf541..0c0227b 100644 --- a/DungeonShooting_Godot/src/framework/Component.cs +++ b/DungeonShooting_Godot/src/framework/Component.cs @@ -1,6 +1,6 @@ using Godot; -public abstract class Component : IProcess where TN : Node where TG : Node2D +public abstract class Component : IComponent where TN : Node where TG : Node2D { public GameObject GameObject { get; private set; } public TN Node { get; } diff --git a/DungeonShooting_Godot/src/framework/GameObject.cs b/DungeonShooting_Godot/src/framework/GameObject.cs index 421e504..e3cc636 100644 --- a/DungeonShooting_Godot/src/framework/GameObject.cs +++ b/DungeonShooting_Godot/src/framework/GameObject.cs @@ -1,14 +1,15 @@ using System.Collections.Generic; using Godot; -public class GameObject where T : Node2D +public abstract class GameObject : IProcess where T : Node2D { public Vector3 Position { get; set; } public Vector2 Position2D { get; set; } public T Node; - private List _components = new List(); + private List> _components = new List>(); + private bool _isDestroy = false; public GameObject(T node) { @@ -50,4 +51,18 @@ arr[i].PhysicsProcess(delta); } } + + public void Destroy() + { + if (_isDestroy) + { + return; + } + _isDestroy = true; + } + + public bool IsDestroy() + { + return _isDestroy; + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/IComponent.cs b/DungeonShooting_Godot/src/framework/IComponent.cs new file mode 100644 index 0000000..7002919 --- /dev/null +++ b/DungeonShooting_Godot/src/framework/IComponent.cs @@ -0,0 +1,9 @@ + +using Godot; + +public interface IComponent : IProcess where TN : Node2D +{ + GameObject GameObject { get; } + + void SetGameObject(GameObject gameObject); +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/TestNavigation.cs b/DungeonShooting_Godot/src/game/TestNavigation.cs deleted file mode 100644 index f393083..0000000 --- a/DungeonShooting_Godot/src/game/TestNavigation.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Godot; - -public class TestNavigation : Node2D -{ - - private Navigation2D Navigation2D; - private Vector2[] points = new Vector2[0]; - - public override void _Ready() - { - Navigation2D = GetNode("Position2D/Navigation2D"); - } - - public override void _Input(InputEvent @event) - { - if (@event is InputEventMouseButton ieb) { - if (ieb.ButtonIndex == (int)ButtonList.Left && ieb.Pressed) - { - points = Navigation2D.GetSimplePath(Vector2.Zero, Navigation2D.ToLocal(ieb.Position)); - Update(); - string str = ""; - foreach (var item in points) - { - str += item; - } - GD.Print("路径: " + points.Length + ", " + str); - } - } - } - - public override void _Draw() - { - if (points.Length >= 2) - { - GD.Print("绘制线段..."); - DrawPolyline(points, Colors.Red); - // DrawMultiline(points, Colors.Red); - } - } -} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/manager/GameManager.cs b/DungeonShooting_Godot/src/game/manager/GameManager.cs index 0216d77..48a9d2b 100644 --- a/DungeonShooting_Godot/src/game/manager/GameManager.cs +++ b/DungeonShooting_Godot/src/game/manager/GameManager.cs @@ -5,7 +5,6 @@ /// public class GameManager : Node2D { - public static GameManager Instance { get; private set; } public GameManager() @@ -15,5 +14,4 @@ //扫描并注册当前程序集下的武器 WeaponManager.RegisterWeaponFromAssembly(GetType().Assembly); } - } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/test/TestNavigation.cs b/DungeonShooting_Godot/src/test/TestNavigation.cs new file mode 100644 index 0000000..f393083 --- /dev/null +++ b/DungeonShooting_Godot/src/test/TestNavigation.cs @@ -0,0 +1,40 @@ +using Godot; + +public class TestNavigation : Node2D +{ + + private Navigation2D Navigation2D; + private Vector2[] points = new Vector2[0]; + + public override void _Ready() + { + Navigation2D = GetNode("Position2D/Navigation2D"); + } + + public override void _Input(InputEvent @event) + { + if (@event is InputEventMouseButton ieb) { + if (ieb.ButtonIndex == (int)ButtonList.Left && ieb.Pressed) + { + points = Navigation2D.GetSimplePath(Vector2.Zero, Navigation2D.ToLocal(ieb.Position)); + Update(); + string str = ""; + foreach (var item in points) + { + str += item; + } + GD.Print("路径: " + points.Length + ", " + str); + } + } + } + + public override void _Draw() + { + if (points.Length >= 2) + { + GD.Print("绘制线段..."); + DrawPolyline(points, Colors.Red); + // DrawMultiline(points, Colors.Red); + } + } +} \ No newline at end of file