using Godot; using System.Collections; using System.Collections.Generic; using Godot.Collections; using System.Drawing; using Rokojori.Extensions; namespace Rokojori { [Tool] [GlobalClass,Icon("res://addons/rokojori_action_library/Icons/Pointer.svg")] public partial class Pointer:Action { [Export] public Caster caster; [Export] public HighlightEffect defaultHighlighter; [Export] public Node3D visualizer; [Export] public Action onPointed; [Export] public Action onUnpointed; [Export] public Action onPointerChanged; [ExportGroup("Read Only")] [Export] public Pointable pointable; public readonly EventSlot onPointerChange = new EventSlot(); [Export] public bool printPointables = false; protected override void _OnTrigger() { if ( caster == null ) { return; } var currentCollider = caster.NumColliders() == 0 ? null : caster.GetCollider( 0 ); var currentPointable = currentCollider == null ? null : Nodes.Find( currentCollider ); SetPointable( currentPointable ); } protected void SetPointable( Pointable next ) { if ( next == pointable ) { if ( visualizer != null && pointable != null ) { var pointable3D = pointable.pointerPosition; visualizer.CopyGlobalPoseFrom( pointable3D ); } return; } if ( pointable != null ) { pointable.UpdatePointerState( this, false ); Highlight( HighlightActionType.End, pointable ); } pointable = next; if ( pointable != null ) { pointable.UpdatePointerState( this, true ); Highlight( HighlightActionType.Start, pointable ); } onPointerChange.DispatchEvent( pointable ); onPointerChanged?.Trigger(); if ( pointable == null ) { onUnpointed?.Trigger(); } else { onPointed?.Trigger(); } if ( visualizer != null && pointable != null ) { var pointable3D = pointable.pointerPosition; visualizer.CopyGlobalPoseFrom( pointable3D ); } if ( printPointables ) { this.LogInfo( pointable ); } } void Highlight( HighlightActionType type, Pointable p ) { if ( p.highlightTargets == null || p.highlightTargets.Length == 0 ) { return; } if ( p.highlightEffect == null && defaultHighlighter == null ) { return; } var highlightEffect = p.highlightEffect ?? defaultHighlighter; // this.LogInfo( "Set Highlight", highlightEffect == null ? "" : HierarchyName.Of( highlightEffect ) ); highlightEffect.Highlight( type, p.highlightTargets ); } } }