forked from cgvr/DeltaVR
Merge branch 'SamWorkset'
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
using FishNet.Object;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
using FMOD.Studio;
|
||||
using static MouseLook;
|
||||
|
||||
public class CarDrivingRoutine : MonoBehaviour
|
||||
public class CarDrivingRoutine : NetworkBehaviour
|
||||
{
|
||||
public AudioSource _stopSound;
|
||||
public AudioSource _tireSound;
|
||||
@@ -19,14 +21,22 @@ public class CarDrivingRoutine : MonoBehaviour
|
||||
private float targetSpeed;
|
||||
private float targetRotationSpeed;
|
||||
|
||||
private bool stopSoundPlayed = false;
|
||||
private float stopThreshold = 0.05f; // consider speed "0" when below this
|
||||
|
||||
private bool isBeingStoppedByPlayer = false;
|
||||
|
||||
|
||||
[Header("Tires")]
|
||||
public List<GameObject> FrontTires;
|
||||
public List<GameObject> BackTires;
|
||||
|
||||
public CarAudioController AudioController;
|
||||
private void Start()
|
||||
{
|
||||
targetSpeed = StraightSpeed;
|
||||
targetRotationSpeed = rotationSpeed;
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -47,23 +57,26 @@ public class CarDrivingRoutine : MonoBehaviour
|
||||
|
||||
rollTires(); // Just an aesthetic improvement.
|
||||
|
||||
if (Quaternion.Angle(transform.rotation, desiredRotation) > 1f) // If the car is turning.
|
||||
if (!isBeingStoppedByPlayer)
|
||||
{
|
||||
if (!isTurning)
|
||||
if (Quaternion.Angle(transform.rotation, desiredRotation) > 1f)
|
||||
{
|
||||
setTireRotation(tireTurnAngle);
|
||||
if (!isTurning)
|
||||
{
|
||||
setTireRotation(tireTurnAngle);
|
||||
AudioController.SetRPM(1300);
|
||||
}
|
||||
isTurning = true;
|
||||
}
|
||||
|
||||
isTurning = true;
|
||||
}
|
||||
if (Quaternion.Angle(transform.rotation, desiredRotation) <= 1f) // Reset the turn value.
|
||||
{
|
||||
if (isTurning)
|
||||
else
|
||||
{
|
||||
setTireRotation(-tireTurnAngle);
|
||||
if (isTurning)
|
||||
{
|
||||
setTireRotation(-tireTurnAngle);
|
||||
AudioController.SetRPM(1450);
|
||||
}
|
||||
isTurning = false;
|
||||
}
|
||||
|
||||
isTurning = false;
|
||||
}
|
||||
|
||||
// Check if close enough to the waypoint
|
||||
@@ -73,6 +86,18 @@ public class CarDrivingRoutine : MonoBehaviour
|
||||
// Proceed to the next waypoint
|
||||
_waypoint = _waypoint.Next;
|
||||
}
|
||||
|
||||
if (StraightSpeed <= stopThreshold && !stopSoundPlayed)
|
||||
{
|
||||
float currentRPM = AudioController.GetCurrentRPM();
|
||||
//Debug.LogError(currentRPM);
|
||||
if (currentRPM <= 550f) // confirms we are in the correct engine state
|
||||
{
|
||||
stopSoundPlayed = true;
|
||||
AudioController.PlayStopSound();
|
||||
//Debug.LogError("piiks");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void rollTires()
|
||||
@@ -101,21 +126,29 @@ public class CarDrivingRoutine : MonoBehaviour
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{;
|
||||
if (other.GetComponent<XROrigin>() == null) return;
|
||||
StartCoroutine(SmoothAdjustSpeed(0, 0, haltspeed)); // Smoothly halt in 1 second
|
||||
_tireSound.Stop();
|
||||
_stopSound.Play();
|
||||
{
|
||||
if (other.GetComponentInParent<XRPlayerMirror>() == null) return;
|
||||
|
||||
isBeingStoppedByPlayer = true;
|
||||
|
||||
StartCoroutine(SmoothAdjustSpeed(0, 0, haltspeed));
|
||||
|
||||
AudioController.SetRPM(475);
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.GetComponent<XROrigin>() == null) return;
|
||||
StartCoroutine(SmoothAdjustSpeed(targetSpeed, targetRotationSpeed, haltspeed)); // Smoothly resume speed in 1 second
|
||||
_stopSound.Stop();
|
||||
_tireSound.Play();
|
||||
if (other.GetComponentInParent<XRPlayerMirror>() == null) return;
|
||||
|
||||
isBeingStoppedByPlayer = false;
|
||||
|
||||
StartCoroutine(SmoothAdjustSpeed(targetSpeed, targetRotationSpeed, haltspeed));
|
||||
|
||||
AudioController.SetRPM(1450);
|
||||
stopSoundPlayed = false;
|
||||
}
|
||||
|
||||
|
||||
private IEnumerator SmoothAdjustSpeed(float targetStraightSpeed, float targetRotationSpeed, float duration)
|
||||
{
|
||||
float initialStraightSpeed = StraightSpeed;
|
||||
@@ -137,5 +170,12 @@ public class CarDrivingRoutine : MonoBehaviour
|
||||
// Ensure final values are set
|
||||
StraightSpeed = targetStraightSpeed;
|
||||
rotationSpeed = targetRotationSpeed;
|
||||
|
||||
// If we just came to a full stop, mark for sound playback
|
||||
if (StraightSpeed == 0)
|
||||
{
|
||||
stopSoundPlayed = false; // allow stop sound to fire
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using FishNet.Object;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class Carbehavior : MonoBehaviour
|
||||
public class Carbehavior : NetworkBehaviour
|
||||
{
|
||||
public AudioSource _carAlarm;
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
using FMOD.Studio;
|
||||
|
||||
public class CarAudioController : MonoBehaviour
|
||||
{
|
||||
private EventInstance carMovementInstance;
|
||||
private EventInstance carStopInstance;
|
||||
private FirstPersonOcclusion occlusion;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
//Debug.LogError("AUDIO MANAGER:");
|
||||
//Debug.LogError(AudioManager.Instance);
|
||||
//Debug.LogError("FMOD EVENTS INSTANCE:");
|
||||
//Debug.LogError(FMODEvents.Instance);
|
||||
//Debug.LogError("Car Simple Driving:");
|
||||
//Debug.LogError(FMODEvents.Instance.BoltCarSimpleDriving);
|
||||
carMovementInstance = AudioManager.Instance.CreateInstance(FMODEvents.Instance.CarModulatedDriving);
|
||||
carStopInstance = AudioManager.Instance.CreateInstance(FMODEvents.Instance.BoltCarStopSound);
|
||||
|
||||
carMovementInstance.setParameterByName("RPM", 1450);
|
||||
carMovementInstance.setParameterByName("Load", 0);
|
||||
|
||||
carMovementInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
carStopInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
|
||||
occlusion = GetComponent<FirstPersonOcclusion>();
|
||||
|
||||
if (occlusion != null)
|
||||
{
|
||||
occlusion.InitialiseWithInstance(carMovementInstance); // main looping engine sound
|
||||
occlusion.AddInstance(carStopInstance); // additional sound
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
carMovementInstance.start();
|
||||
AudioManager.Instance.SetGlobalParameter("CarPassengerLogic", 0.0f); //change the value of the global parameter in FMOD, initial value
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Always update 3D position to follow the car model transform
|
||||
carMovementInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
carStopInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
}
|
||||
|
||||
// These methods are called externally by CarDrivingRoutine
|
||||
public void SetRPM(float value)
|
||||
{
|
||||
carMovementInstance.setParameterByName("RPM", value);
|
||||
}
|
||||
|
||||
public void PlayStopSound()
|
||||
{
|
||||
carStopInstance.start();
|
||||
//AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.BoltCarStopSound, gameObject);
|
||||
|
||||
}
|
||||
public float GetCurrentRPM()
|
||||
{
|
||||
carMovementInstance.getParameterByName("RPM", out float value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfb4dce81082ebf46801139bdb2ce8ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,6 @@
|
||||
using _PROJECT.NewHandPresence;
|
||||
using FishNet.Object;
|
||||
using FMODUnity;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.CoreUtils;
|
||||
@@ -6,7 +8,7 @@ using UnityEngine;
|
||||
using UnityEngine.XR.Content.Interaction;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class PassangerSeat : LocomotionProvider
|
||||
public class PassangerSeat : NetworkBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
public GameObject ExitSpot;
|
||||
@@ -36,13 +38,14 @@ public class PassangerSeat : LocomotionProvider
|
||||
Transform cameraTransform = cameraChild.transform.parent.transform;
|
||||
|
||||
Vector3 cameraShift = cameraTransform.localPosition;
|
||||
|
||||
|
||||
AudioManager.Instance.SetGlobalParameter("CarPassengerLogic", 2.0f); //change the value of the global parameter in FMOD, changed value
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.DoorOpen, gameObject); //play 3d oneshot
|
||||
currentPassanger = player;
|
||||
player.transform.SetParent(this.transform);
|
||||
player.transform.localPosition = -cameraShift;
|
||||
player.transform.localRotation = Quaternion.identity;
|
||||
cameraTransform.localRotation = this.transform.rotation;
|
||||
BeginLocomotion();
|
||||
disablePlayerLocomotion(player);
|
||||
}
|
||||
private void disablePlayerLocomotion(XROrigin player)
|
||||
@@ -67,15 +70,16 @@ public class PassangerSeat : LocomotionProvider
|
||||
public void ExitCar()
|
||||
{
|
||||
if (currentPassanger == null) return;
|
||||
EndLocomotion();
|
||||
enablePlayerLocomotion(currentPassanger);
|
||||
|
||||
TutorialController cameraChild = currentPassanger.GetComponentInChildren<TutorialController>();
|
||||
if (cameraChild == null) return;
|
||||
|
||||
Transform cameraTransform = cameraChild.transform.parent.transform;
|
||||
AudioManager.Instance.SetGlobalParameter("CarPassengerLogic", 0.0f); //change the value of the global parameter in FMOD, initial value
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.DoorClose, gameObject); //play 3d oneshot
|
||||
|
||||
// Set the player<65>s parent to null (making it part of the scene hierarchy)
|
||||
// Set the player<65>s parent to null (making it part of the scene hierarchy)
|
||||
currentPassanger.transform.SetParent(null);
|
||||
|
||||
// Put the player outside;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using FishNet.Object;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Waypoint : MonoBehaviour
|
||||
public class Waypoint : NetworkBehaviour
|
||||
{
|
||||
public float DesiredRotation = 0;
|
||||
public Waypoint Next;
|
||||
|
||||
Reference in New Issue
Block a user