DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ItemSoundHandler.c
См. документацию.
2{
3 float m_FadeIn = 0;
4 float m_FadeOut = 0;
5 bool m_Loop = false;
6}
7
8/*
9Provides functionality to start item related sound from server and synchronize it to clients
10Useful in situations where unique animation can't be used to bind the sound
11
12Steps to add new item sound:
13 1) Add new sound ID to SoundConstants class
14 2) Override InitItemSounds() method on subject item to link the new sound ID to a soundset
15 2.5) Generally soundset is retreived by adding override to the subject item class, but retreiving from config or using other means could also be used here
16 3) Start sound using ItemBase::StartItemSoundServer(int id) called from server side
17 3.5) For looped sounds which do not end on their own, use ItemBase::StopItemSoundServer(int id)
18
19Limitations:
20 Avoid starting two sounds at the same time using this handler as just single variable is used for synchronization (can be solved by secondary synch var if need arises)
21
22*/
24{
25 protected ItemBase m_Parent;
26
30
32 {
33 m_Parent = parent;
34 Init();
35 }
36
38 {
39 if (!m_PlayingSounds)
40 return;
41
42 foreach (EffectSound sound : m_PlayingSounds)
43 {
44 if (sound)
45 sound.SoundStop();
46 }
47 }
48
55
56 void PlayItemSoundClient(int id, int slotId = InventorySlots.INVALID)
57 {
58 InventoryItemType itemType = m_Parent.GetInventoryItemType();
59
60 string soundSet = GetSoundSetForEvent(id, slotId);
61 if (soundSet == string.Empty)
62 {
63 Debug.Log("No soundset defined for sound event id " + typename.EnumToString(SoundConstants, id) + ". Item: " + m_Parent.GetType() + " | Slot ID: " + slotId);
64 return;
65 }
66
67 if (m_PlayingSounds.Get(id)) // already playing
68 return;
69
70 EffectSound sound;
71 SoundParameters params = m_SoundParamsMap.Get(id);
72 vector position = m_Parent.GetPosition();
73
74 if (params)
75 sound = SEffectManager.PlaySoundCachedParams(soundSet, position, params.m_FadeIn, params.m_FadeOut, params.m_Loop);
76 else
77 sound = SEffectManager.PlaySound(soundSet, position);
78
79 if (sound)
80 sound.SetAutodestroy(true);
81 else
82 Debug.Log("Null when creating sound from set: " + soundSet + " Item: " + m_Parent.GetType() );
83
84 m_PlayingSounds.Insert(id, sound);
85 }
86
87 string GetSoundSetForEvent(int id, int slotId = InventorySlots.INVALID)
88 {
89 string soundSet;
90 InventoryItemType itemType = m_Parent.GetInventoryItemType();
91
92 switch (id)
93 {
94 case SoundConstants.ITEM_ATTACH:
95 {
96 if (itemType)
97 soundSet = itemType.GetSlotAttachSoundSet(slotId);
98 if (soundSet == "")
99 soundSet = m_AvailableSoundsets[id];
100 break;
101 }
102 case SoundConstants.ITEM_DETACH:
103 {
104 if (itemType)
105 soundSet = itemType.GetSlotDetachSoundSet(slotId);
106 if (soundSet == "")
107 soundSet = m_AvailableSoundsets[id];
108 break;
109 }
110 default:
111 {
112 soundSet = m_AvailableSoundsets[id];
113 break;
114 }
115 }
116 return soundSet;
117 }
118
120 {
121 if (g_Game.IsHeadlessOrDedicatedServer())
122 return;
123
124 EffectSound sound = m_PlayingSounds.Get(id);
125 if (sound)
126 {
127 sound.SetSoundFadeOut(0.1);
128 sound.SoundStop();
129 }
130
131 m_PlayingSounds.Remove(id);
132 }
133
134 void AddSound(int sound, string soundset, SoundParameters params = null)
135 {
136 m_AvailableSoundsets.Insert(sound, soundset);
137
138 if (params)
139 m_SoundParamsMap.Insert(sound, params);
140 }
141}
void InventoryItemType()
Entity m_Parent
Определения CachedEquipmentStorageBase.c:17
map
Определения ControlsXboxNew.c:4
DayZGame g_Game
Определения DayZGame.c:4074
vector position
Определения DustKickupEffects.c:20
Empty
Определения Hand_States.c:14
ref map< int, string > m_AvailableSoundsets
Определения ItemSoundHandler.c:28
string GetSoundSetForEvent(int id, int slotId=InventorySlots.INVALID)
Определения ItemSoundHandler.c:87
void PlayItemSoundClient(int id, int slotId=InventorySlots.INVALID)
Определения ItemSoundHandler.c:56
void ~ItemSoundHandler()
Определения ItemSoundHandler.c:37
void AddSound(int sound, string soundset, SoundParameters params=null)
Определения ItemSoundHandler.c:134
void ItemSoundHandler(ItemBase parent)
Определения ItemSoundHandler.c:31
void StopItemSoundClient(int id)
Определения ItemSoundHandler.c:119
ref map< int, ref EffectSound > m_PlayingSounds
Определения ItemSoundHandler.c:27
ref map< int, ref SoundParameters > m_SoundParamsMap
Определения ItemSoundHandler.c:29
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Определения 3_Game/DayZ/tools/Debug.c:183
Определения 3_Game/DayZ/tools/Debug.c:2
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Определения EffectSound.c:607
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
Определения EffectSound.c:908
void SoundStop()
Stops sound.
Определения EffectSound.c:217
Wrapper class for managing sound through SEffectManager.
Определения EffectSound.c:5
const int INVALID
Invalid slot (-1)
Определения InventorySlots.c:17
provides access to slot configuration
Определения InventorySlots.c:6
static void Init()
Определения PPERequesterBank.c:53
TODO doc.
Определения EnScript.c:118
static EffectSound PlaySoundCachedParams(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound, using or creating cached SoundParams.
Определения EffectManager.c:216
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
Определения EffectManager.c:178
Manager class for managing Effect (EffectParticle, EffectSound)
Определения EffectManager.c:6
bool m_Loop
Определения ItemSoundHandler.c:5
float m_FadeIn
Определения ItemSoundHandler.c:3
float m_FadeOut
Определения ItemSoundHandler.c:4
Определения Transport.c:70
Определения EnConvert.c:119