forked from cgvr/DeltaVR
radio button can be released
This commit is contained in:
Binary file not shown.
66
Assets/_PROJECT/Scripts/ModeGeneration/ReleasableButton.cs
Normal file
66
Assets/_PROJECT/Scripts/ModeGeneration/ReleasableButton.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
using DG.Tweening;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class ReleasableButton : MonoBehaviour
|
||||||
|
{
|
||||||
|
public delegate void OnButtonPressedDelegate();
|
||||||
|
public event OnButtonPressedDelegate OnButtonPressed;
|
||||||
|
|
||||||
|
public Transform movableParts;
|
||||||
|
public float moveDuration = 0.25f;
|
||||||
|
public float moveAmount = 0.05f;
|
||||||
|
|
||||||
|
private float upPositionY;
|
||||||
|
private float downPositionY;
|
||||||
|
private bool isButtonDown;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
upPositionY = movableParts.localPosition.y;
|
||||||
|
downPositionY = movableParts.localPosition.y - moveAmount;
|
||||||
|
isButtonDown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCollisionEnter(Collision collision)
|
||||||
|
{
|
||||||
|
if (!isButtonDown && collision.gameObject.tag.EndsWith("Hand"))
|
||||||
|
{
|
||||||
|
Activate();
|
||||||
|
OnButtonPressed?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCollisionExit(Collision collision)
|
||||||
|
{
|
||||||
|
if (isButtonDown && collision.gameObject.tag.EndsWith("Hand"))
|
||||||
|
{
|
||||||
|
Deactivate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Activate()
|
||||||
|
{
|
||||||
|
movableParts.DOLocalMoveY(downPositionY, moveDuration);
|
||||||
|
isButtonDown = true;
|
||||||
|
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Click, gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Deactivate()
|
||||||
|
{
|
||||||
|
movableParts.DOLocalMoveY(upPositionY, moveDuration);
|
||||||
|
isButtonDown = false;
|
||||||
|
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Click, gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 48207ddbbdf76d642af7251a5bb13936
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -11,7 +11,7 @@ public class RadioTransmitter : XRGrabInteractable
|
|||||||
|
|
||||||
[Header("Custom Config")]
|
[Header("Custom Config")]
|
||||||
public FMODWhisperBridge fmodWhisperBridge;
|
public FMODWhisperBridge fmodWhisperBridge;
|
||||||
public PushableButton radioButton;
|
public ReleasableButton radioButton;
|
||||||
public TextMeshProUGUI computerScreen;
|
public TextMeshProUGUI computerScreen;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
|
|||||||
Reference in New Issue
Block a user