76 lines
1.6 KiB
C#
76 lines
1.6 KiB
C#
using Godot;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Godot.Collections;
|
|
|
|
namespace Rokojori
|
|
{
|
|
|
|
[GlobalClass]
|
|
public partial class Pointer:Node3D
|
|
{
|
|
[Export]
|
|
public Pointable pointable;
|
|
|
|
[Export]
|
|
public Caster caster;
|
|
|
|
[Export]
|
|
public Highlighter[] highlighters;
|
|
|
|
public override void _Process( double delta )
|
|
{
|
|
if ( caster == null )
|
|
{
|
|
return;
|
|
}
|
|
|
|
var currentCollider = caster.NumColliders() == 0 ? null : caster.GetCollider( 0 );
|
|
|
|
|
|
var currentPointable = currentCollider == null ? null : Nodes.Find<Pointable>( currentCollider );
|
|
|
|
// RJLog.Log( currentCollider, currentPointable );
|
|
|
|
if ( currentPointable == pointable )
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
if ( pointable != null )
|
|
{
|
|
Highlight( HighlightActionType.End, pointable );
|
|
pointable.UpdatePointerState( this, false );
|
|
}
|
|
|
|
pointable = currentPointable;
|
|
|
|
if ( pointable != null )
|
|
{
|
|
pointable.UpdatePointerState( this, true );
|
|
Highlight( HighlightActionType.Start, pointable );
|
|
}
|
|
}
|
|
|
|
void Highlight( HighlightActionType type, Pointable p )
|
|
{
|
|
if ( p.highlightFlag == null || p.highlightTargets == null || p.highlightTargets.Length == 0 )
|
|
{
|
|
return;
|
|
}
|
|
|
|
var highlighterIndex = Arrays.FindIndex( highlighters, ( h )=> h.flag == pointable.highlightFlag );
|
|
|
|
if ( highlighterIndex == -1 )
|
|
{
|
|
return;
|
|
}
|
|
|
|
var highlighter = highlighters[ highlighterIndex ];
|
|
|
|
highlighter.Highlight( type, p.highlightTargets );
|
|
|
|
}
|
|
}
|
|
} |