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

51 lines
969 B
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
{
[GlobalClass]
2025-01-08 18:46:17 +00:00
public partial class Pointer:Node3D
2024-08-04 09:08:12 +00:00
{
[Export]
2025-01-08 18:46:17 +00:00
public Pointable pointable;
[Export]
public Caster caster;
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 )
{
pointable.UpdatePointerState( this, false );
}
pointable = currentPointable;
if ( pointable != null )
{
pointable.UpdatePointerState( this, true );
}
}
}
}