Rope sound done. Good enough
This commit is contained in:
parent
62e8769965
commit
dfe3685e06
|
@ -36,7 +36,6 @@ MonoBehaviour:
|
|||
- {fileID: 8300000, guid: 2fc5510c93077614ea99731a8e690f6b, type: 3}
|
||||
- {fileID: 8300000, guid: 27f2cebd20efe6a4faf50b23ad487154, type: 3}
|
||||
- {fileID: 8300000, guid: fc82c40acffc19741a0707c947a1d767, type: 3}
|
||||
- {fileID: 8300000, guid: 2a5efb61897b6af4ab3ecae350829b5c, type: 3}
|
||||
- {fileID: 8300000, guid: 6778ae1bc0a92c64d8ba759c3c13727d, type: 3}
|
||||
- {fileID: 8300000, guid: 7182af998117fba4fa696e5fd33ad99a, type: 3}
|
||||
- {fileID: 8300000, guid: 88b0c2079547b85458daa063fb59e720, type: 3}
|
||||
|
@ -44,3 +43,4 @@ MonoBehaviour:
|
|||
- {fileID: 8300000, guid: 8abb5f3f03f30f842b9d673933bdafb4, type: 3}
|
||||
- {fileID: 8300000, guid: f68b9fed55ed886479faaf1b33c59651, type: 3}
|
||||
- {fileID: 8300000, guid: e24c2fccb4285ab4eacc6da16f5c62eb, type: 3}
|
||||
- {fileID: 8300000, guid: fd92966d4cde3244d9a711094cb947f6, type: 3}
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d9817ed7f73fc14db871e07a93a5931
|
||||
guid: fd92966d4cde3244d9a711094cb947f6
|
||||
AudioImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 7
|
|
@ -3421,7 +3421,7 @@ MonoBehaviour:
|
|||
m_CorrespondingSourceObject: {fileID: 7717684785049474632, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
|
||||
m_PrefabInstance: {fileID: 4910321061857220295}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_GameObject: {fileID: 4910321061857220296}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 27ac133d9e10e544ba603e07122e3359, type: 3}
|
||||
|
@ -3737,8 +3737,128 @@ PrefabInstance:
|
|||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_AddedComponents:
|
||||
- targetCorrespondingSourceObject: {fileID: 5991265243222894942, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 4910321061857220297}
|
||||
- targetCorrespondingSourceObject: {fileID: 5991265243222894942, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 4910321061857220300}
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
|
||||
--- !u!1 &4910321061857220296 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 5991265243222894942, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
|
||||
m_PrefabInstance: {fileID: 4910321061857220295}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!114 &4910321061857220297
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4910321061857220296}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 8766ad5393174fa488ef4a58b62181b4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
PlayTime: 1
|
||||
--- !u!82 &4910321061857220300
|
||||
AudioSource:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4910321061857220296}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 4
|
||||
OutputAudioMixerGroup: {fileID: 0}
|
||||
m_audioClip: {fileID: 8300000, guid: fd92966d4cde3244d9a711094cb947f6, type: 3}
|
||||
m_PlayOnAwake: 0
|
||||
m_Volume: 0.107
|
||||
m_Pitch: 1
|
||||
Loop: 1
|
||||
Mute: 0
|
||||
Spatialize: 0
|
||||
SpatializePostEffects: 0
|
||||
Priority: 128
|
||||
DopplerLevel: 1
|
||||
MinDistance: 1
|
||||
MaxDistance: 500
|
||||
Pan2D: 0
|
||||
rolloffMode: 0
|
||||
BypassEffects: 0
|
||||
BypassListenerEffects: 0
|
||||
BypassReverbZones: 0
|
||||
rolloffCustomCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
panLevelCustomCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
spreadCustomCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
reverbZoneMixCustomCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
--- !u!1001 &5796191506433166633
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityUtils
|
||||
|
@ -56,5 +58,22 @@ namespace UnityUtils
|
|||
v1.y != 0 ? v0.y / v1.y : v0.y,
|
||||
v1.z != 0 ? v0.z / v1.z : v0.z);
|
||||
}
|
||||
public static Vector3 Mean(this List<Vector3> vectors)
|
||||
{
|
||||
if (vectors == null || vectors.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("The input list of vectors is empty or null.");
|
||||
}
|
||||
|
||||
Vector3 sum = Vector3.zero;
|
||||
|
||||
foreach (var vector in vectors)
|
||||
{
|
||||
sum += vector;
|
||||
}
|
||||
|
||||
return sum / vectors.Count;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class AudioManager : MonoBehaviour
|
|||
return Instance.audioLibrary.Clips.First(x => x.name == nameOfClip);
|
||||
}
|
||||
|
||||
public static AudioSource PlaySound(string nameOfClip, Vector3 sourcePos, bool is3D = true, bool loop = false, bool fadeIn = false)
|
||||
public static AudioSource PlaySound(string nameOfClip, Vector3 sourcePos, bool manuallyHandle = false, bool is3D = true, bool loop = false, bool fadeIn = false)
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
|
@ -57,6 +57,7 @@ public class AudioManager : MonoBehaviour
|
|||
audioSource.spatialBlend = 1f;
|
||||
}
|
||||
|
||||
if (!manuallyHandle)
|
||||
Instance.StartCoroutine(Instance.StartSound(audioSource, fadeIn));
|
||||
return audioSource;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class RopeSimulator : MonoBehaviour
|
|||
|
||||
public float Overshoot => rope.CalculateLengthOvershoot();
|
||||
|
||||
Rope rope;
|
||||
public Rope rope;
|
||||
|
||||
Dictionary<Collider2D, float> colliderToSquezeForce = new();
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d19feedeaa6e99458ae00d9141125be
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,47 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityUtils;
|
||||
|
||||
public class RopeSounding : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float PlayTime = 1f;
|
||||
|
||||
RopeSimulator rope;
|
||||
|
||||
AudioSource AS;
|
||||
float playTimeLeft = 0;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (rope == null)
|
||||
{
|
||||
if (TryGetComponent(out rope))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (AS == null)
|
||||
{
|
||||
TryGetComponent(out AS);
|
||||
AS.Play();
|
||||
AS.Pause();
|
||||
}
|
||||
|
||||
|
||||
if (rope.Overshoot >= 0.5f)
|
||||
{
|
||||
Vector3 soundPos = rope.rope.points.Select(x => x.position).ToList().Mean();
|
||||
AS.transform.position = soundPos;
|
||||
AS.UnPause();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Pause
|
||||
AS.Pause();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8766ad5393174fa488ef4a58b62181b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue