73 lines
1.2 KiB
C#
73 lines
1.2 KiB
C#
using Godot;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Godot.Collections;
|
|
|
|
namespace Rokojori
|
|
{
|
|
|
|
[GlobalClass]
|
|
public partial class Pointable:Node3D
|
|
{
|
|
[Export]
|
|
public int pointingPriority;
|
|
|
|
[Export]
|
|
public Action onPointed;
|
|
|
|
[Export]
|
|
public Action onUnpointed;
|
|
|
|
[Export]
|
|
public Action onPointerAdded;
|
|
|
|
[Export]
|
|
public Action onPointerRemoved;
|
|
|
|
List<Pointer> _pointers = new List<Pointer>();
|
|
|
|
public int numPointing => _pointers.Count;
|
|
|
|
public bool IsPointedBy( Pointer pointer )
|
|
{
|
|
return _pointers.Contains( pointer );
|
|
}
|
|
|
|
public void UpdatePointerState( Pointer pointer, bool pointed )
|
|
{
|
|
var isCurrentlyPointed = IsPointedBy( pointer );
|
|
|
|
if ( isCurrentlyPointed == pointed )
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
if ( pointed )
|
|
{
|
|
_pointers.Add( pointer );
|
|
Action.Trigger( onPointerAdded );
|
|
|
|
if ( _pointers.Count == 1 )
|
|
{
|
|
Action.Trigger( onPointed );
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
_pointers.Remove( pointer );
|
|
|
|
Action.Trigger( onPointerRemoved );
|
|
|
|
if ( _pointers.Count == 0 )
|
|
{
|
|
Action.Trigger( onUnpointed );
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
} |