mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-22 12:03:04 +00:00
play sound while panicing
This commit is contained in:
parent
fb17bc3707
commit
8bf6157183
8 changed files with 223 additions and 1 deletions
|
@ -173,6 +173,9 @@ MonoBehaviour:
|
|||
timeUntilMovementStateCanBeEnteredFromOtherMovementState: 0.166
|
||||
timeUntilAimMovementStateCanBeSwitchedToOtherAimMovementState: 0.166
|
||||
timeUntilAimMovementStateCanBeEnteredFromOtherAimMovementState: 0.166
|
||||
timeIntervalToUpdateUnderAimStatus: 0.25
|
||||
pedMouthAudioSourcePrefab: {fileID: 1241726729665878427, guid: 05646d228b24e82459d6ab3aedfa5e74,
|
||||
type: 3}
|
||||
cameraDistanceFromPed: 5
|
||||
minCameraDistanceFromPed: 2
|
||||
maxCameraDistanceFromPed: 30
|
||||
|
@ -195,6 +198,7 @@ MonoBehaviour:
|
|||
healthBackgroundColor: {r: 0.5, g: 0, b: 0, a: 1}
|
||||
AIStoppingDistance: 3
|
||||
AIVehicleEnterDistance: 1.25
|
||||
AIWeaponHearingDistance: 40
|
||||
pedSyncRate: 20
|
||||
ragdollPrefab: {fileID: 2141754834917738923, guid: 14d22e60f4926f64cbd36f393fe11b9a,
|
||||
type: 3}
|
||||
|
|
120
Assets/Prefabs/PedMouthAudioSource.prefab
Normal file
120
Assets/Prefabs/PedMouthAudioSource.prefab
Normal file
|
@ -0,0 +1,120 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &1241726729665878427
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 6149468222765612185}
|
||||
- component: {fileID: 2734110348128017540}
|
||||
m_Layer: 0
|
||||
m_Name: PedMouthAudioSource
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &6149468222765612185
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1241726729665878427}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!82 &2734110348128017540
|
||||
AudioSource:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1241726729665878427}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 4
|
||||
OutputAudioMixerGroup: {fileID: 0}
|
||||
m_audioClip: {fileID: 0}
|
||||
m_PlayOnAwake: 0
|
||||
m_Volume: 1
|
||||
m_Pitch: 1
|
||||
Loop: 0
|
||||
Mute: 0
|
||||
Spatialize: 0
|
||||
SpatializePostEffects: 0
|
||||
Priority: 128
|
||||
DopplerLevel: 1
|
||||
MinDistance: 1
|
||||
MaxDistance: 40
|
||||
Pan2D: 0
|
||||
rolloffMode: 1
|
||||
BypassEffects: 0
|
||||
BypassListenerEffects: 0
|
||||
BypassReverbZones: 0
|
||||
rolloffCustomCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0.02
|
||||
value: 1
|
||||
inSlope: -50.01992
|
||||
outSlope: -50.01992
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
panLevelCustomCurve:
|
||||
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
|
||||
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
|
7
Assets/Prefabs/PedMouthAudioSource.prefab.meta
Normal file
7
Assets/Prefabs/PedMouthAudioSource.prefab.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 05646d228b24e82459d6ab3aedfa5e74
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -12,6 +12,8 @@ namespace SanAndreasUnity.Behaviours.Audio
|
|||
public string fileName;
|
||||
public int bankIndex;
|
||||
public int audioIndex;
|
||||
|
||||
public bool IsValid => !string.IsNullOrEmpty(fileName) && bankIndex >= 0 && audioIndex >= 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -225,6 +225,8 @@ namespace SanAndreasUnity.Behaviours
|
|||
void OnDisable ()
|
||||
{
|
||||
s_allPeds.Remove (this);
|
||||
|
||||
this.Sound_OnDisable();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,8 +10,17 @@ namespace SanAndreasUnity.Behaviours
|
|||
private AudioSource _mouthAudioSource;
|
||||
|
||||
|
||||
private void PlaySoundFromPedMouth(SoundId soundId)
|
||||
private void Sound_OnDisable()
|
||||
{
|
||||
if (_mouthAudioSource != null)
|
||||
_mouthAudioSource.Stop();
|
||||
}
|
||||
|
||||
public void PlaySoundFromPedMouth(SoundId soundId)
|
||||
{
|
||||
if (!soundId.IsValid)
|
||||
return;
|
||||
|
||||
this.AddAudioSourceForMouth();
|
||||
|
||||
if (null == _mouthAudioSource)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using SanAndreasUnity.Importing.Animation;
|
||||
using SanAndreasUnity.Importing.Items.Definitions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SanAndreasUnity.Behaviours.Peds.States
|
||||
{
|
||||
|
@ -9,12 +11,78 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
public override AnimId movementWeaponAnim => this.movementAnim;
|
||||
|
||||
|
||||
private const string kSfxFileName = "PAIN_A";
|
||||
private const int kMaleBankIndex = 2;
|
||||
private const int kMaleSoundIndexMin = 69;
|
||||
private const int kMaleSoundIndexMax = 100;
|
||||
private const int kFemaleBankIndex = 1;
|
||||
private const int kFemaleSoundIndexMin = 88;
|
||||
private const int kFemaleSoundIndexMax = 130;
|
||||
|
||||
private float _timeWhenEmittedSound = 0f;
|
||||
public float randomAverageTimeIntervalToEmitSound = 10f;
|
||||
private float _timeToEmitSound;
|
||||
|
||||
|
||||
/*public override void OnBecameActive()
|
||||
{
|
||||
base.OnBecameActive();
|
||||
|
||||
if (m_isServer)
|
||||
this.TryEmitSound();
|
||||
}*/
|
||||
|
||||
public override void UpdateState()
|
||||
{
|
||||
this.TryEmitSound();
|
||||
|
||||
base.UpdateState();
|
||||
}
|
||||
|
||||
protected override void SwitchToAimState()
|
||||
{
|
||||
// don't switch to aim state
|
||||
// we will switch to aim state from other movement states
|
||||
}
|
||||
|
||||
private Audio.SoundId GetSoundToPlay()
|
||||
{
|
||||
if (null == m_ped.PedDef)
|
||||
return default;
|
||||
|
||||
var soundId = new Audio.SoundId
|
||||
{
|
||||
fileName = kSfxFileName,
|
||||
isStream = false,
|
||||
};
|
||||
|
||||
if (m_ped.PedDef.DefaultType.IsMale())
|
||||
{
|
||||
soundId.bankIndex = kMaleBankIndex;
|
||||
soundId.audioIndex = Random.Range(kMaleSoundIndexMin, kMaleSoundIndexMax + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
soundId.bankIndex = kFemaleBankIndex;
|
||||
soundId.audioIndex = Random.Range(kFemaleSoundIndexMin, kFemaleSoundIndexMax + 1);
|
||||
}
|
||||
|
||||
return soundId;
|
||||
}
|
||||
|
||||
private void TryEmitSound()
|
||||
{
|
||||
if (Time.time - _timeWhenEmittedSound < _timeToEmitSound)
|
||||
return;
|
||||
|
||||
_timeToEmitSound = Random.Range(
|
||||
this.randomAverageTimeIntervalToEmitSound * 0.5f,
|
||||
this.randomAverageTimeIntervalToEmitSound * 1.5f);
|
||||
|
||||
_timeWhenEmittedSound = Time.time;
|
||||
m_ped.PlaySoundFromPedMouth(this.GetSoundToPlay());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,6 +47,16 @@ namespace SanAndreasUnity.Importing.Items.Definitions
|
|||
{
|
||||
return pedestrianType == PedestrianType.Cop;
|
||||
}
|
||||
|
||||
public static bool IsFemale(this PedestrianType pedestrianType)
|
||||
{
|
||||
return pedestrianType == PedestrianType.CivFemale || pedestrianType == PedestrianType.Prostitute;
|
||||
}
|
||||
|
||||
public static bool IsMale(this PedestrianType pedestrianType)
|
||||
{
|
||||
return !pedestrianType.IsFemale();
|
||||
}
|
||||
}
|
||||
|
||||
[Section("peds")]
|
||||
|
|
Loading…
Reference in a new issue