Added ClickableComponent. Not sure what to do with it, though...
parent
3e90e3fad0
commit
1597903d13
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using Godot;
|
||||
using GoDotLog;
|
||||
|
||||
public class ClickableComponent : Spatial
|
||||
{
|
||||
[Export] public string ClickName = "ClickName";
|
||||
|
||||
[Signal]
|
||||
delegate void Clicked();
|
||||
|
||||
public bool IsMouseOver = false;
|
||||
|
||||
// private members
|
||||
private CollisionObject _collisionObject;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_collisionObject = (CollisionObject)FindNode("Area", false);
|
||||
if (_collisionObject == null)
|
||||
{
|
||||
GD.PrintErr("Error: could not find Area for Clickable Component!");
|
||||
return;
|
||||
}
|
||||
|
||||
_collisionObject.Connect("input_event", this, nameof(OnAreaInputEvent));
|
||||
_collisionObject.Connect("mouse_entered", this, nameof(OnAreaMouseEntered));
|
||||
_collisionObject.Connect("mouse_exited", this, nameof(OnAreaMouseExited));
|
||||
}
|
||||
|
||||
public void OnAreaInputEvent(Node camera, InputEvent inputEvent, Vector3 position, Vector3 normal,
|
||||
int shapeIndex)
|
||||
{
|
||||
if (IsMouseOver && inputEvent is InputEventMouseButton)
|
||||
{
|
||||
InputEventMouseButton mouseButtonEvent = (InputEventMouseButton)inputEvent;
|
||||
if (mouseButtonEvent.ButtonIndex == 1 && mouseButtonEvent.Pressed)
|
||||
{
|
||||
GD.Print("Clicked on Clickable Component!");
|
||||
EmitSignal("Clicked", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAreaMouseEntered()
|
||||
{
|
||||
IsMouseOver = true;
|
||||
}
|
||||
|
||||
public void OnAreaMouseExited()
|
||||
{
|
||||
IsMouseOver = false;
|
||||
}
|
||||
}
|
|
@ -28,13 +28,6 @@ public class Player : Entity
|
|||
_navigationComponent = (NavigationComponent)FindNode("Navigation", false);
|
||||
_navigationComponent.TileWorld = _worldInfo.TileWorld;
|
||||
TaskQueueComponent = new TaskQueueComponent();
|
||||
|
||||
_movable = (MovableComponent)FindNode("Movable", false);
|
||||
if (_movable != null)
|
||||
{
|
||||
_movable.Connect("OrientationUpdated", this, nameof(OnOrientationUpdated));
|
||||
}
|
||||
|
||||
_geometry = (Spatial)FindNode("Geometry", false);
|
||||
}
|
||||
|
||||
|
@ -74,12 +67,5 @@ public class Player : Entity
|
|||
{
|
||||
_navigationComponent.UpdateCurrentGoal(GlobalTransform);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnOrientationUpdated(float newOrientation)
|
||||
{
|
||||
_geometry.Transform = new Transform(new Quat(Vector3.Up, newOrientation), Vector3.Zero);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=22 format=2]
|
||||
[gd_scene load_steps=27 format=2]
|
||||
|
||||
[ext_resource path="res://scenes/StreamContainer.cs" type="Script" id=1]
|
||||
[ext_resource path="res://components/NavigationComponent.cs" type="Script" id=2]
|
||||
|
@ -11,6 +11,8 @@
|
|||
[ext_resource path="res://scenes/Game.cs" type="Script" id=9]
|
||||
[ext_resource path="res://scenes/DebugCamera.gd" type="Script" id=10]
|
||||
[ext_resource path="res://assets/CreatusPiratePack/characters/Pirate1final_0.01.glb" type="PackedScene" id=13]
|
||||
[ext_resource path="res://components/ClickableComponent.cs" type="Script" id=14]
|
||||
[ext_resource path="res://entities/Flower.cs" type="Script" id=15]
|
||||
|
||||
[sub_resource type="OpenSimplexNoise" id=10]
|
||||
period = 39.6
|
||||
|
@ -279,8 +281,31 @@ script = ExtResource( 2 )
|
|||
[node name="Chest" parent="Entities" instance=ExtResource( 7 )]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.01499, 0, -1.3224 )
|
||||
|
||||
[node name="Flower" type="KinematicBody" parent="Entities"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 3.75737, 0, -3.73012 )
|
||||
input_ray_pickable = false
|
||||
script = ExtResource( 15 )
|
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="Entities/Flower"]
|
||||
transform = Transform( 0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0 )
|
||||
mesh = SubResource( 17 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="Entities/Flower"]
|
||||
shape = SubResource( 18 )
|
||||
|
||||
[node name="ClickableComponent" type="Spatial" parent="Entities/Flower"]
|
||||
script = ExtResource( 14 )
|
||||
|
||||
[node name="Area" type="Area" parent="Entities/Flower/ClickableComponent"]
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="Entities/Flower/ClickableComponent/Area"]
|
||||
transform = Transform( 0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0 )
|
||||
shape = SubResource( 19 )
|
||||
|
||||
[node name="Chest3" parent="Entities" instance=ExtResource( 7 )]
|
||||
transform = Transform( 0.550568, 0, -0.83479, 0, 1, 0, 0.83479, 0, 0.550568, 4.88275, 0, -1.70504 )
|
||||
|
||||
[node name="Chest2" parent="Entities" instance=ExtResource( 7 )]
|
||||
transform = Transform( 0.793576, 0, -0.608471, 0, 1, 0, 0.608471, 0, 0.793576, 2.79265, 0, -5.36551 )
|
||||
|
||||
[editable path="Entities/Chest"]
|
||||
|
|
Loading…
Reference in New Issue