Add bow sounds, fix 2nd floor roof, add lights to archery range

This commit is contained in:
Toomas Tamm
2021-02-15 17:50:18 +02:00
parent acb632d3c0
commit 93451e92bd
454 changed files with 2916 additions and 19 deletions

View File

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

View File

@@ -0,0 +1,43 @@
using System.Collections.Generic;
using UnityEngine;
namespace Audio
{
[CreateAssetMenu(menuName = "AudioClipGroup")]
public class AudioClipGroup : ScriptableObject
{
[Range(0, 2)] public float volumeMin = 1;
[Range(0, 2)] public float volumeMax = 1;
[Range(0, 2)] public float pitchMin = 1;
[Range(0, 2)] public float pitchMax = 1;
public float delay = 0.1f;
public List<AudioClip> audioClips;
private float _timestamp;
public void OnEnable()
{
_timestamp = 0;
}
public void Play()
{
if (AudioSourcePool.Instance == null) return;
Play(AudioSourcePool.Instance.GetAudioSource());
}
public void Play(AudioSource source)
{
if (audioClips.Count <= 0) return;
if (_timestamp > Time.time) return;
_timestamp = Time.time + delay;
source.volume = Random.Range(volumeMin, volumeMax);
source.pitch = Random.Range(pitchMin, pitchMax);
source.clip = audioClips[Random.Range(0, audioClips.Count)];
source.Play();
}
}
}

View File

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

View File

@@ -0,0 +1,34 @@
using System.Collections.Generic;
using UnityEngine;
namespace Audio
{
public class AudioSourcePool : MonoBehaviour
{
public static AudioSourcePool Instance;
public AudioSource audioSourcePrefab;
private List<AudioSource> _audioSources;
public void Awake()
{
Instance = this;
_audioSources = new List<AudioSource>();
}
public AudioSource GetAudioSource()
{
foreach (AudioSource source in _audioSources)
{
if (!source.isPlaying)
{
return source;
}
}
AudioSource newSource = Instantiate(audioSourcePrefab, this.transform);
_audioSources.Add(newSource);
return newSource;
}
}
}

View File

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

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections;
using Audio;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
@@ -7,6 +8,8 @@ namespace Bow
{
public class Arrow : XRGrabInteractable
{
public AudioClipGroup hitSounds;
public float speed = 2000.0f;
public Transform tip = null;
@@ -37,6 +40,7 @@ namespace Bow
hit.collider.gameObject.SendMessage("OnArrowHit", this,
SendMessageOptions.DontRequireReceiver);
Stop();
hitSounds.Play();
}
}

View File

@@ -1,13 +1,16 @@
using UnityEngine.XR.Interaction.Toolkit;
using Audio;
using UnityEngine.XR.Interaction.Toolkit;
namespace Bow
{
public class Notch : XRSocketInteractor
{
public AudioClipGroup nockSounds;
public AudioClipGroup releaseSounds;
private Puller _puller = null;
private Arrow _currentArrow = null;
protected override void Awake()
{
base.Awake();
@@ -34,10 +37,10 @@ namespace Bow
private void StoreArrow(XRBaseInteractable interactable)
{
if (interactable is Arrow arrow)
{
_currentArrow = arrow;
}
if (!(interactable is Arrow arrow)) return;
_currentArrow = arrow;
nockSounds.Play();
}
private void TryToReleaseArrow(XRBaseInteractor interactor)
@@ -60,6 +63,7 @@ namespace Bow
{
_currentArrow.Release(_puller.PullAmount);
_currentArrow = null;
releaseSounds.Play();
}
public override XRBaseInteractable.MovementType? selectedInteractableMovementTypeOverride =>

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using Audio;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
namespace Bow
@@ -6,6 +7,9 @@ namespace Bow
public class Puller : XRBaseInteractable
{
public float PullAmount { get; private set; } = 0.0f;
public AudioClipGroup pullSounds;
public AudioClipGroup maxPullSounds;
public Transform start = null;
public Transform end = null;
@@ -33,7 +37,19 @@ namespace Bow
if (!isSelected) return;
Vector3 pullPosition = _pullingInteractor.transform.position;
PullAmount = CalculatePull(pullPosition);
float newPull = CalculatePull(pullPosition);
if (PullAmount == 0 & newPull > 0)
{
pullSounds.Play();
}
if (PullAmount < 0.98f & newPull >= 0.98f)
{
maxPullSounds.Play();
}
PullAmount = newPull;
}
private float CalculatePull(Vector3 pullPosition)