using Godot; using Godot.Collections; public partial class SelectTool : Node3D, ITool { public int ToolID { get{ return -1; } } // -1 for non-existant tool stat Options _Options; Reference _Reference; [Export] PackedScene SelectToolFrame; [Export] Material HoverMaterial; Material _defaultMaterial; MeshInstance3D _lookingAt; Control _SelectToolFrame; bool mouseDown = false; bool mouseDownDebounce = false; bool equipped = false; public (bool, Dictionary) screenSpaceToRay( float Distance ) { Vector2 ClickPos = GetViewport().GetMousePosition(); Vector3 from = _Reference.Camera.ProjectRayOrigin( ClickPos ); Vector3 to = from + _Reference.Camera.ProjectRayNormal( ClickPos ) * Distance; PhysicsDirectSpaceState3D spaceState = GetWorld3D().DirectSpaceState; Dictionary rayArray = spaceState.IntersectRay(new PhysicsRayQueryParameters3D(){ From=from, To=to }); if( rayArray.Count > 0 ) { return (true, rayArray); } return (false, null); } void ClearLookingAt() { if( _lookingAt != null ) { _lookingAt.SetSurfaceOverrideMaterial( 0, _defaultMaterial ); _lookingAt = null; _SelectToolFrame.Visible = false; } } public override void _PhysicsProcess( double delta ) { if( equipped ) { var x = screenSpaceToRay(_Options.ClickDistance); if( x.Item1 ) { Node test = (Node)x.Item2["collider"]; if( test is Pickup ) { int ItemID = ((Pickup)test).ItemID; int Quantity = ((Pickup)test).Quantity; GameItem item = new GameItem(ItemID); item.GameObject = test; if (item.ItemStats.IsQuantityItem) { item.InventoryObject.Quantity = Quantity; } if( _lookingAt == null ) { _lookingAt = test.GetChild( 1 ); _defaultMaterial = _lookingAt.GetSurfaceOverrideMaterial( 0 ); _lookingAt.SetSurfaceOverrideMaterial( 0, HoverMaterial ); _SelectToolFrame.Visible = true; _SelectToolFrame.GetChild