basic interface and no success trying to use them in a Tool script
This commit is contained in:
8
interfaces/spawnable/ISpawnable.cs
Normal file
8
interfaces/spawnable/ISpawnable.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
|
||||||
|
interface ISpawnable
|
||||||
|
{
|
||||||
|
Resource GetSpawnInitResource();
|
||||||
|
void TestMethod();
|
||||||
|
}
|
||||||
1
interfaces/spawnable/ISpawnable.cs.uid
Normal file
1
interfaces/spawnable/ISpawnable.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bethuw2c1at8o
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
[gd_scene load_steps=11 format=3 uid="uid://q7uc1h2jpbd2"]
|
[gd_scene load_steps=13 format=3 uid="uid://q7uc1h2jpbd2"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://bei4nhkf8lwdo" path="res://player_controller/PlayerController.tscn" id="1_62kkh"]
|
[ext_resource type="PackedScene" uid="uid://bei4nhkf8lwdo" path="res://player_controller/PlayerController.tscn" id="1_62kkh"]
|
||||||
[ext_resource type="Material" uid="uid://31aulub2nqov" path="res://assets/greybox/m_greybox.tres" id="2_3uydm"]
|
[ext_resource type="Material" uid="uid://31aulub2nqov" path="res://assets/greybox/m_greybox.tres" id="2_3uydm"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dxt0e2ugmttqq" path="res://scenes/enemies/first_enemy.tscn" id="3_3uydm"]
|
[ext_resource type="PackedScene" uid="uid://dxt0e2ugmttqq" path="res://scenes/enemies/first_enemy.tscn" id="3_3uydm"]
|
||||||
[ext_resource type="Script" uid="uid://b2vdwkiqauhk3" path="res://scenes/enemies/EnemyInitInputs.cs" id="4_nd7vd"]
|
[ext_resource type="Script" uid="uid://b2vdwkiqauhk3" path="res://scenes/enemies/EnemyInitInputs.cs" id="4_nd7vd"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://c305mfrtumcyq" path="res://scenes/spawners/spawner.tscn" id="5_8fd2t"]
|
||||||
|
|
||||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_0xm2m"]
|
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_0xm2m"]
|
||||||
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
|
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
|
||||||
@@ -42,6 +43,11 @@ script = ExtResource("4_nd7vd")
|
|||||||
Speed = 6.4
|
Speed = 6.4
|
||||||
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_caohq"]
|
||||||
|
script = ExtResource("4_nd7vd")
|
||||||
|
Speed = 3.1
|
||||||
|
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
||||||
|
|
||||||
[node name="Main" type="Node3D"]
|
[node name="Main" type="Node3D"]
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource("1_62kkh")]
|
[node name="Player" parent="." instance=ExtResource("1_62kkh")]
|
||||||
@@ -122,3 +128,8 @@ Inputs = SubResource("Resource_7m3bq")
|
|||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.5, 0, -16.83681)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.5, 0, -16.83681)
|
||||||
Target = NodePath("../Player")
|
Target = NodePath("../Player")
|
||||||
Inputs = SubResource("Resource_sysok")
|
Inputs = SubResource("Resource_sysok")
|
||||||
|
|
||||||
|
[node name="Spawner" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("5_8fd2t")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 3.5, -16.5)
|
||||||
|
Inputs = SubResource("Resource_caohq")
|
||||||
|
Target = NodePath("../Player")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=50 format=3 uid="uid://bei4nhkf8lwdo"]
|
[gd_scene load_steps=51 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bbbrf5ckydfna" path="res://player_controller/Scripts/PlayerController.cs" id="1_poq2x"]
|
[ext_resource type="Script" uid="uid://bbbrf5ckydfna" path="res://player_controller/Scripts/PlayerController.cs" id="1_poq2x"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cf3rrgr1imvv4" path="res://scenes/path/path.tscn" id="2_6lejt"]
|
[ext_resource type="PackedScene" uid="uid://cf3rrgr1imvv4" path="res://scenes/path/path.tscn" id="2_6lejt"]
|
||||||
@@ -49,6 +49,8 @@ height = 1.7
|
|||||||
[sub_resource type="SphereShape3D" id="SphereShape3D_6lejt"]
|
[sub_resource type="SphereShape3D" id="SphereShape3D_6lejt"]
|
||||||
radius = 0.45
|
radius = 0.45
|
||||||
|
|
||||||
|
[sub_resource type="SphereShape3D" id="SphereShape3D_q14ux"]
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_nodcl"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_nodcl"]
|
||||||
transparency = 1
|
transparency = 1
|
||||||
albedo_color = Color(0, 0.627451, 0.6313726, 0.49019608)
|
albedo_color = Color(0, 0.627451, 0.6313726, 0.49019608)
|
||||||
@@ -164,6 +166,17 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.6, 0)
|
|||||||
MantleEndLocationDistanceFromWall = 0.3
|
MantleEndLocationDistanceFromWall = 0.3
|
||||||
MantleHeightCastStart = 2.5
|
MantleHeightCastStart = 2.5
|
||||||
|
|
||||||
|
[node name="WeaponHitbox" type="Area3D" parent="HeadSystem"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.6, 0)
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 16
|
||||||
|
monitorable = false
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="HeadSystem/WeaponHitbox"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -1)
|
||||||
|
shape = SubResource("SphereShape3D_q14ux")
|
||||||
|
|
||||||
[node name="StairsSystem" type="Node3D" parent="."]
|
[node name="StairsSystem" type="Node3D" parent="."]
|
||||||
script = ExtResource("7_bmt5a")
|
script = ExtResource("7_bmt5a")
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public partial class PlayerController : CharacterBody3D
|
|||||||
public ShapeCast3D GroundDetector;
|
public ShapeCast3D GroundDetector;
|
||||||
public ShapeCast3D CeilingDetector;
|
public ShapeCast3D CeilingDetector;
|
||||||
public RayCast3D DirectGroundDetector;
|
public RayCast3D DirectGroundDetector;
|
||||||
|
public Area3D WeaponHitbox;
|
||||||
|
|
||||||
// Inspector stuff
|
// Inspector stuff
|
||||||
[Export] public Marker3D TutorialWeaponTarget;
|
[Export] public Marker3D TutorialWeaponTarget;
|
||||||
@@ -353,6 +354,8 @@ public partial class PlayerController : CharacterBody3D
|
|||||||
var playerShape = StandingCollider.GetShape() as CapsuleShape3D;
|
var playerShape = StandingCollider.GetShape() as CapsuleShape3D;
|
||||||
_playerHeight = playerShape!.Height;
|
_playerHeight = playerShape!.Height;
|
||||||
_playerRadius = playerShape.Radius;
|
_playerRadius = playerShape.Radius;
|
||||||
|
|
||||||
|
WeaponHitbox = GetNode<Area3D>("%WeaponHitbox");
|
||||||
|
|
||||||
// State management
|
// State management
|
||||||
_playerState = StateChart.Of(GetNode("StateChart"));
|
_playerState = StateChart.Of(GetNode("StateChart"));
|
||||||
@@ -1572,10 +1575,20 @@ public partial class PlayerController : CharacterBody3D
|
|||||||
///////////////////////////
|
///////////////////////////
|
||||||
public void OnInputHitPressed()
|
public void OnInputHitPressed()
|
||||||
{
|
{
|
||||||
if (_aiming.Active)
|
if (_aiming.Active && WeaponSystem.InHandState.Active)
|
||||||
{
|
{
|
||||||
ThrowWeapon();
|
ThrowWeapon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (WeaponSystem.InHandState.Active)
|
||||||
|
{
|
||||||
|
var bodies = WeaponHitbox.GetOverlappingBodies();
|
||||||
|
foreach (var body in bodies)
|
||||||
|
{
|
||||||
|
if(body is ISpawnable spawnable)
|
||||||
|
spawnable.TestMethod();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ using Godot;
|
|||||||
using System;
|
using System;
|
||||||
using Movementtests.player_controller.Scripts;
|
using Movementtests.player_controller.Scripts;
|
||||||
|
|
||||||
public partial class FirstEnemy : CharacterBody3D
|
|
||||||
|
[GlobalClass]
|
||||||
|
public partial class FirstEnemy : CharacterBody3D, ISpawnable
|
||||||
{
|
{
|
||||||
[Export]
|
[Export]
|
||||||
public Node3D Target { get; set; }
|
public Node3D Target { get; set; }
|
||||||
@@ -17,6 +19,16 @@ public partial class FirstEnemy : CharacterBody3D
|
|||||||
_wallInFrontRayCast = GetNode<RayCast3D>("WallInFrontRayCast");
|
_wallInFrontRayCast = GetNode<RayCast3D>("WallInFrontRayCast");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Resource GetSpawnInitResource()
|
||||||
|
{
|
||||||
|
return Inputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TestMethod()
|
||||||
|
{
|
||||||
|
GD.Print("I'm an enemy");
|
||||||
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
var target = Target.GlobalPosition;
|
var target = Target.GlobalPosition;
|
||||||
|
|||||||
62
scenes/spawners/Spawner.cs
Normal file
62
scenes/spawners/Spawner.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
[Tool]
|
||||||
|
public partial class Spawner : Node3D
|
||||||
|
{
|
||||||
|
[Export(PropertyHint.NodeType)]
|
||||||
|
public PackedScene SceneToSpawn { get; set; }
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public Resource Inputs;
|
||||||
|
[Export]
|
||||||
|
public Node3D Target { get; set; }
|
||||||
|
|
||||||
|
[Export(PropertyHint.Range, "0.1, 100, 0.1, or_greater")]
|
||||||
|
public float SpawnInterval { get; set; } = 1.0f;
|
||||||
|
[Export]
|
||||||
|
public bool IsActiveOnStart { get; set; } = true;
|
||||||
|
|
||||||
|
private float _spawnTimer;
|
||||||
|
private bool _isActive;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
_isActive = IsActiveOnStart && !Engine.IsEditorHint(); // Keep it inactive in Editor
|
||||||
|
_spawnTimer = SpawnInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
if (!_isActive) return;
|
||||||
|
|
||||||
|
_spawnTimer -= (float) delta;
|
||||||
|
if (_spawnTimer <= 0) Spawn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Spawn()
|
||||||
|
{
|
||||||
|
if (SceneToSpawn == null || !SceneToSpawn.CanInstantiate()) return;
|
||||||
|
|
||||||
|
var spawnedInstance = SceneToSpawn.Instantiate() as FirstEnemy;
|
||||||
|
if (spawnedInstance == null) return;
|
||||||
|
|
||||||
|
spawnedInstance.Inputs = Inputs as EnemyInitInputs;
|
||||||
|
spawnedInstance.Target = Target;
|
||||||
|
GetTree().GetCurrentScene().AddChild(spawnedInstance);
|
||||||
|
spawnedInstance.GlobalPosition = GlobalPosition;
|
||||||
|
|
||||||
|
_spawnTimer = SpawnInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartSpawning()
|
||||||
|
{
|
||||||
|
_isActive = true;
|
||||||
|
_spawnTimer = SpawnInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopSpawning()
|
||||||
|
{
|
||||||
|
_isActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
scenes/spawners/Spawner.cs.uid
Normal file
1
scenes/spawners/Spawner.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://djyspwixi01j5
|
||||||
10
scenes/spawners/spawner.tscn
Normal file
10
scenes/spawners/spawner.tscn
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[gd_scene load_steps=3 format=3 uid="uid://c305mfrtumcyq"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://djyspwixi01j5" path="res://scenes/spawners/Spawner.cs" id="1_2otbo"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dxt0e2ugmttqq" path="res://scenes/enemies/first_enemy.tscn" id="2_2otbo"]
|
||||||
|
|
||||||
|
[node name="Spawner" type="Node3D"]
|
||||||
|
script = ExtResource("1_2otbo")
|
||||||
|
SceneToSpawn = ExtResource("2_2otbo")
|
||||||
|
|
||||||
|
[node name="Marker3D" type="Marker3D" parent="."]
|
||||||
Reference in New Issue
Block a user