// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.UI;
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit.Dwell
{
///
/// Example script to demonstrate dwell visuals in sample scene
///
public abstract class BaseDwellPressableButton : MonoBehaviour
{
[SerializeField]
protected MeshRenderer dwellVisualImage = null;
[SerializeField]
protected Interactable targetButton = null;
///
/// The dwell handler associated with the target
///
protected DwellHandler DwellHandler { get; set; }
///
/// Whether the targeting is being dwelled on
///
protected bool IsDwelling { get; set; } = false;
///
/// Assign the DwellHandler at Awake()
///
protected virtual void Awake()
{
DwellHandler = this.GetComponent();
}
///
/// Function called when entering dwell started state
///
public virtual void DwellStarted(IMixedRealityPointer pointer) { IsDwelling = true; }
///
/// Function called when entering dwell intended state
///
public virtual void DwellIntended(IMixedRealityPointer pointer) { }
///
/// Function called when entering dwell canceled state
///
public virtual void DwellCanceled(IMixedRealityPointer pointer) { IsDwelling = false; }
///
/// Function called when entering dwell completed state
///
public virtual void DwellCompleted(IMixedRealityPointer pointer)
{
IsDwelling = false;
if (targetButton != null)
{
targetButton.TriggerOnClick();
}
}
///
/// Function called when the target button is pressed
///
public virtual void ButtonExecute() { }
}
}