rj-action-library/Runtime/Interactions/Pointer.cs

75 lines
1.6 KiB
C#
Raw Normal View History

2024-08-04 09:08:12 +00:00
using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
2025-01-21 20:58:56 +00:00
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/Pointer.svg")]
2025-01-08 18:46:17 +00:00
public partial class Pointer:Node3D
2024-08-04 09:08:12 +00:00
{
[Export]
2025-01-21 20:58:56 +00:00
public Caster caster;
2025-01-08 18:46:17 +00:00
[Export]
2025-01-21 20:58:56 +00:00
public HighlightEffect defaultHighlighter;
[ExportGroup("Read Only")]
[Export]
public Pointable pointable;
2024-08-04 09:08:12 +00:00
public override void _Process( double delta )
{
2025-01-08 18:46:17 +00:00
if ( caster == null )
2024-08-04 09:08:12 +00:00
{
return;
}
2025-01-08 18:46:17 +00:00
var currentCollider = caster.NumColliders() == 0 ? null : caster.GetCollider( 0 );
2024-08-04 09:08:12 +00:00
2025-01-08 18:46:17 +00:00
var currentPointable = currentCollider == null ? null : Nodes.Find<Pointable>( currentCollider );
2024-08-04 09:08:12 +00:00
// RJLog.Log( currentCollider, currentPointable );
if ( currentPointable == pointable )
{
return;
}
if ( pointable != null )
2025-01-18 12:49:14 +00:00
{
Highlight( HighlightActionType.End, pointable );
2024-08-04 09:08:12 +00:00
pointable.UpdatePointerState( this, false );
}
pointable = currentPointable;
if ( pointable != null )
{
pointable.UpdatePointerState( this, true );
2025-01-18 12:49:14 +00:00
Highlight( HighlightActionType.Start, pointable );
}
}
void Highlight( HighlightActionType type, Pointable p )
{
2025-01-21 20:58:56 +00:00
if ( p.highlightTargets == null || p.highlightTargets.Length == 0 )
2025-01-18 12:49:14 +00:00
{
return;
}
2025-01-21 20:58:56 +00:00
if ( p.highlightEffect == null && defaultHighlighter == null )
{
return;
}
var highlightEffect = p.highlightEffect ?? defaultHighlighter;
highlightEffect.Highlight( type, p.highlightTargets );
2025-01-18 12:49:14 +00:00
2024-08-04 09:08:12 +00:00
}
}
}