namespace VRTK.Prefabs.Interactions.Interactables.Grab
{
using UnityEngine;
using UnityEngine.Events;
using System;
using Malimbe.BehaviourStateRequirementMethod;
///
/// Emits an appropriate event based on the state of whether an is currently being grabbed or not.
///
public class InteractableGrabStateEmitter : MonoBehaviour
{
///
/// Defines the event with the specified .
///
[Serializable]
public class UnityEvent : UnityEvent
{
}
///
/// Emitted if the is grabbed.
///
public UnityEvent Grabbed = new UnityEvent();
///
/// Emitted if the is not grabbed.
///
public UnityEvent NotGrabbed = new UnityEvent();
///
/// Determines if the given Interactable is currently grabbed by a valid Interactor.
///
/// The Interactable to check.
/// Whether the Interactable is being grabbed.
[RequiresBehaviourState]
public virtual bool IsGrabbed(InteractableFacade interactable)
{
if (interactable == null)
{
return false;
}
if (interactable.IsGrabbed)
{
Grabbed?.Invoke(interactable);
return true;
}
else
{
NotGrabbed?.Invoke(interactable);
return false;
}
}
///
/// Determines if the given Interactable is currently grabbed by a valid Interactor.
///
/// The Interactable to check.
public virtual void DoIsGrabbed(InteractableFacade interactable)
{
IsGrabbed(interactable);
}
///
/// Determines if the given 's is currently grabbed by a valid Interactor.
///
/// The to check.
/// Whether the Interactable is being grabbed.
public virtual bool IsGrabbed(GameObject interactable)
{
if (interactable == null)
{
return false;
}
return IsGrabbed(interactable.GetComponent());
}
///
/// Determines if the given 's is currently grabbed by a valid Interactor.
///
/// The to check.
public virtual void DoIsGrabbed(GameObject interactable)
{
IsGrabbed(interactable);
}
}
}