DayZ 1.29
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 break;
99 }
100 case SoundConstants.ITEM_DETACH:
101 {
102 if (itemType)
103 soundSet = itemType.GetSlotDetachSoundSet(slotId);
104 break;
105 }
106 default:
107 {
108 soundSet = m_AvailableSoundsets[id];
109 break;
110 }
111 }
112 return soundSet;
113 }
114
116 {
117 if (g_Game.IsDedicatedServer())
118 return;
119
120 EffectSound sound = m_PlayingSounds.Get(id);
121 if (sound)
122 {
123 sound.SetSoundFadeOut(0.1);
124 sound.SoundStop();
125 }
126
127 m_PlayingSounds.Remove(id);
128 }
129
130 void AddSound(int sound, string soundset, SoundParameters params = null)
131 {
132 m_AvailableSoundsets.Insert(sound, soundset);
133
134 if (params)
135 m_SoundParamsMap.Insert(sound, params);
136 }
137}
void InventoryItemType()
Entity m_Parent
Определения CachedEquipmentStorageBase.c:15
map
Определения ControlsXboxNew.c:4
DayZGame g_Game
Определения DayZGame.c:3942
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:130
void ItemSoundHandler(ItemBase parent)
Определения ItemSoundHandler.c:31
void StopItemSoundClient(int id)
Определения ItemSoundHandler.c:115
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:182
Определения 3_Game/DayZ/tools/Debug.c:2
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Определения EffectSound.c:603
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
Определения EffectSound.c:904
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:51
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:207
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:169
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
Определения CachedEquipmentStorage.c:4
Определения EnConvert.c:119