VR4RoboticArm2/VR4RoboticArm/Library/PackageCache/com.meta.xr.sdk.movement/Shared/Scripts/Samples/MovementHipPinningNotification.cs
IonutMocanu 48cccc22ad Main2
2025-09-08 11:13:29 +03:00

73 lines
2.0 KiB
C#

// Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
using Meta.XR.Movement.Retargeting;
using Meta.XR.Movement.Utils;
using UnityEngine;
namespace Meta.XR.Movement.Samples
{
/// <summary>
/// Activates/deactivates this game object based on the hip pinning leave event.
/// </summary>
public class MovementHipPinningNotification : MonoBehaviour
{
[SerializeField]
protected CharacterRetargeter _retargeter;
/// <summary>
/// The amount of time that this notification should be enabled for.
/// </summary>
[SerializeField]
protected float _displayTime = 5.0f;
private float _timer;
private HipPinningSkeletalProcessor _hipPinningProcessor;
private void Awake()
{
_hipPinningProcessor = _retargeter.GetTargetProcessor<HipPinningSkeletalProcessor>();
if (_hipPinningProcessor != null)
{
_hipPinningProcessor.OnEnterHipPinningArea += OnEnterHipPinningArea;
_hipPinningProcessor.OnExitHipPinningArea += OnExitHipPinningArea;
}
gameObject.SetActive(false);
}
private void OnDestroy()
{
if (_hipPinningProcessor != null)
{
_hipPinningProcessor.OnEnterHipPinningArea -= OnEnterHipPinningArea;
_hipPinningProcessor.OnExitHipPinningArea -= OnExitHipPinningArea;
}
}
private void Update()
{
if (_timer > 0.0f)
{
_timer -= Time.deltaTime;
}
else
{
gameObject.SetActive(false);
}
}
private void OnEnterHipPinningArea()
{
_timer = 0.0f;
gameObject.SetActive(false);
}
private void OnExitHipPinningArea()
{
_timer = _displayTime;
gameObject.SetActive(true);
}
}
}