diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs index 2647504..be07875 100644 --- a/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs @@ -19,6 +19,12 @@ /// </summary> [Export(PropertyHint.Layers2dPhysics)] public uint CollisionMask; + + /// <summary> + /// 当前物体渲染层级 + /// </summary> + [Export] + public int ZIndex; public override void _Ready() { @@ -42,16 +48,7 @@ { owner = parent; } - - //创建 Sprite - if (GetNodeOrNull("AnimatedSprite") == null) - { - var sp = new AnimatedSprite(); - sp.Name = "AnimatedSprite"; - AddChild(sp); - sp.Owner = owner; - } - + //创建Shadow if (GetNodeOrNull("ShadowSprite") == null) { @@ -61,6 +58,15 @@ AddChild(sd); sd.Owner = owner; } + + //创建 Sprite + if (GetNodeOrNull("AnimatedSprite") == null) + { + var sp = new AnimatedSprite(); + sp.Name = "AnimatedSprite"; + AddChild(sp); + sp.Owner = owner; + } //创建Collision if (GetNodeOrNull("Collision") == null) diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn deleted file mode 100644 index a9f7c92..0000000 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ /dev/null @@ -1,10 +0,0 @@ -[gd_scene load_steps=4 format=2] - -[ext_resource path="res://prefab/role/Role.tscn" type="PackedScene" id=1] -[ext_resource path="res://src/game/role/Player.cs" type="Script" id=2] -[ext_resource path="res://prefab/weapon/Weapon.tscn" type="PackedScene" id=4] - -[node name="Player" instance=ExtResource( 1 )] -collision_layer = 8 -script = ExtResource( 2 ) -GunPrefab = ExtResource( 4 ) diff --git a/DungeonShooting_Godot/prefab/role/Role.tscn b/DungeonShooting_Godot/prefab/role/Role.tscn index 76a842c..1b76c68 100644 --- a/DungeonShooting_Godot/prefab/role/Role.tscn +++ b/DungeonShooting_Godot/prefab/role/Role.tscn @@ -1,10 +1,9 @@ [gd_scene load_steps=19 format=2] -[ext_resource path="res://src/game/role/Role.cs" type="Script" id=1] -[ext_resource path="res://resource/sprite/role/role2.png" type="Texture" id=2] +[ext_resource path="res://resource/materlal/Shadow.tres" type="Material" id=1] +[ext_resource path="res://addons/dungeonShooting_plugin/ActivityObjectTemplate.cs" type="Script" id=2] [ext_resource path="res://resource/sprite/role/role1.png" type="Texture" id=3] - [sub_resource type="AtlasTexture" id=17] atlas = ExtResource( 3 ) region = Rect2( 0, 24, 16, 24 ) @@ -77,10 +76,12 @@ [sub_resource type="RectangleShape2D" id=29] extents = Vector2( 5, 7.5 ) -[node name="Role" type="KinematicBody2D"] -collision_layer = 0 -script = ExtResource( 1 ) -Texture = ExtResource( 2 ) +[node name="Role" type="Node"] +script = ExtResource( 2 ) +ZIndex = 3 + +[node name="ShadowSprite" type="Sprite" parent="."] +material = ExtResource( 1 ) [node name="BackMountPoint" type="Position2D" parent="."] position = Vector2( 0, -10 ) @@ -89,6 +90,7 @@ position = Vector2( 0, -12 ) frames = SubResource( 6 ) animation = "idle" +frame = 1 playing = true [node name="Collision" type="CollisionShape2D" parent="."] @@ -115,6 +117,3 @@ [node name="MountPoint" type="Position2D" parent="."] position = Vector2( 2, -4 ) - -[connection signal="area_entered" from="InteractiveArea" to="." method="_OnPropsEnter"] -[connection signal="area_exited" from="InteractiveArea" to="." method="_OnPropsExit"] diff --git a/DungeonShooting_Godot/prefab/weapon/Weapon.tscn b/DungeonShooting_Godot/prefab/weapon/Weapon.tscn index c095c86..ebebb5b 100644 --- a/DungeonShooting_Godot/prefab/weapon/Weapon.tscn +++ b/DungeonShooting_Godot/prefab/weapon/Weapon.tscn @@ -1,6 +1,8 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] +[ext_resource path="res://resource/materlal/Shadow.tres" type="Material" id=1] [ext_resource path="res://resource/materlal/Shadow.gdshader" type="Shader" id=2] +[ext_resource path="res://addons/dungeonShooting_plugin/ActivityObjectTemplate.cs" type="Script" id=3] [sub_resource type="ShaderMaterial" id=9] resource_local_to_scene = true @@ -71,9 +73,11 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 7.8, 3.5 ) -[sub_resource type="RectangleShape2D" id=10] +[node name="Weapon" type="Node"] +script = ExtResource( 3 ) -[node name="Weapon" type="KinematicBody2D"] +[node name="ShadowSprite" type="Sprite" parent="."] +material = ExtResource( 1 ) [node name="WeaponBody" type="Area2D" parent="."] collision_layer = 4 @@ -104,6 +108,6 @@ position = Vector2( 0.59999, 0.199997 ) shape = SubResource( 1 ) +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] + [node name="Collision" type="CollisionShape2D" parent="."] -shape = SubResource( 10 ) -disabled = true diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs index 0a200b8..8e24ba1 100644 --- a/DungeonShooting_Godot/src/framework/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using Godot; +using Plugin; /// <summary> /// 房间内活动物体基类 @@ -12,7 +13,7 @@ /// 当前物体显示的精灵图像, 节点名称必须叫 "AnimatedSprite", 类型为 AnimatedSprite /// </summary> public AnimatedSprite AnimatedSprite { get; } - + /// <summary> /// 当前物体显示的阴影图像, 节点名称必须叫 "ShadowSprite", 类型为 Sprite /// </summary> @@ -22,13 +23,13 @@ /// 当前物体碰撞器节点, 节点名称必须叫 "Collision", 类型为 CollisionShape2D /// </summary> public CollisionShape2D Collision { get; } - - + + /// <summary> /// 是否调用过 Destroy() 函数 /// </summary> public bool IsDestroyed { get; private set; } - + private List<KeyValuePair<Type, Component>> _components = new List<KeyValuePair<Type, Component>>(); public ActivityObject(string scenePath) @@ -40,7 +41,12 @@ throw new Exception("创建 ActivityObject 的参数 scenePath 为 null !"); } - var tempNode = tempPrefab.Instance<ActivityObject>(); + var tempNode = tempPrefab.Instance<ActivityObjectTemplate>(); + ZIndex = tempNode.ZIndex; + CollisionLayer = tempNode.CollisionLayer; + CollisionMask = tempNode.CollisionMask; + + //移动子节点 var count = tempNode.GetChildCount(); for (int i = 0; i < count; i++) { @@ -74,7 +80,7 @@ /// </summary> /// <param name="master">触发者</param> public abstract void Interactive(ActivityObject master); - + public void AddComponent(Component component) { if (!ContainsComponent(component)) @@ -112,7 +118,7 @@ if (component == null) return null; return (TC)component; } - + public override void _Process(float delta) { var arr = _components.ToArray(); @@ -140,7 +146,7 @@ } } } - + public void Destroy() { if (IsDestroyed) @@ -166,6 +172,7 @@ return true; } } + return false; } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index ef863a8..9b72e36 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -205,6 +205,7 @@ public override void _Process(float delta) { + base._Process(delta); if (Master == null) //这把武器被扔在地上 { Reloading = false; diff --git a/DungeonShooting_Godot/src/game/role/Player.cs b/DungeonShooting_Godot/src/game/role/Player.cs index 854d901..9402cbf 100644 --- a/DungeonShooting_Godot/src/game/role/Player.cs +++ b/DungeonShooting_Godot/src/game/role/Player.cs @@ -49,11 +49,6 @@ [Export] public PackedScene GunPrefab; - public Player(string scenePath) : base(scenePath) - { - - } - public override void _EnterTree() { base._EnterTree(); diff --git a/DungeonShooting_Godot/src/game/role/Role.cs b/DungeonShooting_Godot/src/game/role/Role.cs index 69cff63..b3fc853 100644 --- a/DungeonShooting_Godot/src/game/role/Role.cs +++ b/DungeonShooting_Godot/src/game/role/Role.cs @@ -113,12 +113,13 @@ } - protected Role(string scenePath) : base(scenePath) + public Role() : base("res://prefab/role/Role.tscn") { } public override void _Ready() { + base._Ready(); StartScele = Scale; MountPoint = GetNode<Position2D>("MountPoint"); BackMountPoint = GetNode<Position2D>("BackMountPoint"); @@ -133,6 +134,7 @@ public override void _Process(float delta) { + base._Process(delta); //检查可互动的道具 bool findFlag = false; for (int i = 0; i < InteractiveItemList.Count; i++) diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index b66bccf..97620c5 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -37,6 +37,11 @@ var node = GetNode("MapRoot").GetChild(0).GetNode("Config"); Color color = (Color)node.GetMeta("ClearColor"); VisualServer.SetDefaultClearColor(color); + + //创建玩家 + var player = new Player(); + player.Name = "Player"; + SortRoot.AddChild(player); } public override void _Ready()