using System.Diagnostics; using Godot; public class Workbench : Entity { public bool IsMouseOver; private MeshInstance _geometry; [Signal] public delegate void EntityClicked(Entity entity); // Called when the node enters the scene tree for the first time. public override void _Ready() { _geometry = GetNode("Geometry/workbench"); Debug.Assert(_geometry != null); Connect("input_event", this, nameof(OnAreaInputEvent)); Connect("mouse_entered", this, nameof(OnAreaMouseEntered)); 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) { EmitSignal("EntityClicked", this); } } } public void OnAreaMouseEntered() { IsMouseOver = true; SpatialMaterial overrideMaterial = new(); overrideMaterial.AlbedoColor = new Color(1, 0, 0); _geometry.MaterialOverride = overrideMaterial; } public void OnAreaMouseExited() { IsMouseOver = false; _geometry.MaterialOverride = null; } // // Called every frame. 'delta' is the elapsed time since the previous frame. // public override void _Process(float delta) // { // // } }