03-27-2024 03:20 PM - edited 03-27-2024 03:22 PM
Unity 2022.3.20f1
Meta SDK v62
09-04-2024 03:11 PM
This is what I did in lieu of an official fix by Meta to satisfy my specific use case (to predictably play audio on hover events):
using UnityEngine;
using Oculus.Interaction;
public class PlayAudioOnHoverMETA : MonoBehaviour
{
[SerializeField] private AudioSource audioSource;
private bool isPointerOver = false;
void Start()
{
PointableCanvasModule.WhenSelectableHovered += OnSelectableHovered;
PointableCanvasModule.WhenSelectableUnhovered += OnSelectableUnhovered;
}
void OnDestroy()
{
PointableCanvasModule.WhenSelectableHovered -= OnSelectableHovered;
PointableCanvasModule.WhenSelectableUnhovered -= OnSelectableUnhovered;
}
private void OnSelectableHovered(PointableCanvasEventArgs args)
{
if (args.Hovered == this.gameObject && audioSource != null && !audioSource.isPlaying && !isPointerOver)
{
audioSource.Play();
isPointerOver = true;
//Debug.Log("Play Audio Clip on Enter\n");
}
}
private void OnSelectableUnhovered(PointableCanvasEventArgs args)
{
if (audioSource != null)
{
audioSource.Stop();
isPointerOver = false;
//Debug.Log("Stop Audio Clip on Exit\n");
}
}
}