1
0
mirror of synced 2024-11-24 06:40:11 +01:00

Merge pull request #19 from muskit/main

Add locomotion toggling
This commit is contained in:
xpeng 2022-05-24 14:19:31 +02:00 committed by GitHub
commit 8adb7483d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 2494 additions and 183 deletions

Binary file not shown.

View File

@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: 15a013a0c90197f4aacd50e80e006409
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: 1b1e3bea19569c145b0fb1d2c4758914
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class LocomotionStatus : MonoBehaviour
{
private TextMeshPro text;
// Start is called before the first frame update
void Start()
{
text = GetComponent<TextMeshPro>();
UpdateText(LocomotionToggle.IsEnabled);
}
public void UpdateText(bool status)
{
text.text = "LOCOMOTION: " + (status ? "ENABLED" : "DISABLED");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 351fc1d968d436d44b431f42a0570812
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,86 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
[RequireComponent(typeof(AudioSource))]
public class LocomotionToggle : MonoBehaviour
{
[System.Serializable]
public class LocomotionToggleEvent : UnityEvent<bool> { }
public static bool IsEnabled
{
get { return _state; }
}
private static bool _state = true;
private float timer = 0;
private bool actionDone = false;
private bool leftHeld = false;
private bool rightHeld = false;
public LocomotionToggleEvent locoEvent;
private AudioClip soundOn;
private AudioClip soundOff;
private AudioSource audioSrc;
[Header("Settings")]
[SerializeField]
private float holdTime;
[Header("References")]
[SerializeField]
private GameObject locomotionController;
[SerializeField]
private InputActionProperty leftHandAction;
[SerializeField]
private InputActionProperty rightHandAction;
private void Start()
{
if (locoEvent == null)
locoEvent = new LocomotionToggleEvent();
audioSrc = GetComponent<AudioSource>();
audioSrc.playOnAwake = false;
soundOn = Resources.Load<AudioClip>("Audio/loco on");
soundOff = Resources.Load<AudioClip>("Audio/loco off");
leftHandAction.action.started +=
(InputAction.CallbackContext _) => leftHeld = true;
leftHandAction.action.canceled +=
(InputAction.CallbackContext _) => leftHeld = false;
rightHandAction.action.started +=
(InputAction.CallbackContext _) => rightHeld = true;
rightHandAction.action.canceled +=
(InputAction.CallbackContext _) => rightHeld = false;
locomotionController.SetActive(_state);
}
private void Update()
{
if (leftHeld && rightHeld)
{
timer += Time.unscaledDeltaTime;
if (timer >= holdTime && !actionDone)
{
_state = !_state;
locoEvent.Invoke(_state);
locomotionController.SetActive(_state);
actionDone = true;
audioSrc.clip = _state ? soundOn : soundOff;
audioSrc.Play();
}
}
else
{
timer = 0;
actionDone = false;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e28739818e0aced4fbf1afd49f82dcff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -45,9 +45,9 @@ public class PanelButton : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
_insideColliderCount += 1;
ButtonPress();
if (doesBeep)
audioSrc.Play();
ButtonPress();
}
private void OnTriggerExit(Collider other)

View File

@ -35,7 +35,7 @@ public class PanelLocker : MonoBehaviour
private void Start()
{
statusImg.texture = unlockImg;
statusImg.texture = isLocked ? lockImg : unlockImg;
audioSrc.clip = lockSound;
}
@ -61,19 +61,18 @@ public class PanelLocker : MonoBehaviour
if (ratio >= 1 && !actionTaken)
{
isLocked = !isLocked;
audioSrc.clip = isLocked ? lockSound : unlockSound;
audioSrc.Play();
timerRing.color = Color.cyan;
statusImg.texture = isLocked ? lockImg : unlockImg;
foreach (var btn in panelButtons)
{
btn.SetActive(!isLocked);
}
actionTaken = true;
timerRing.color = Color.cyan;
statusImg.texture = isLocked ? lockImg : unlockImg;
audioSrc.clip = isLocked ? lockSound : unlockSound;
audioSrc.Play();
}
}
else

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b7d4e5e75e98f8e4384a0a48e42b93b1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 0f61ebe746c23ef42b8010bd8ac1e3ab
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 0
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace: