123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875 |
- /**
- \brief Manager class for managing Effect (EffectParticle, EffectSound)
- \warning Keeps a ref to any Effect registered (Created/Played), make sure to perform the necessary cleanup
- */
- class SEffectManager
- {
- //! Static map of all registered effects <id, Effect>
- protected static ref map<int, ref Effect> m_EffectsMap;
- //! Static array of IDs that were previously used, but freed up by unregistering
- protected static ref array<int> m_FreeEffectIDs;
- //! Counter for quickly getting the next ID if FreeEffectIDs array is empty
- protected static int m_HighestFreeEffectID = 1;
- //! As the counter starts at 1, Effect ID can never be 0
- static const int INVALID_ID = 0;
- //! Bool to check whether Cleanup is happening, which means that the maps should no longer be accessed
- protected static bool m_IsCleanup;
- //! Bool to check whether Init was called
- protected static bool m_IsInitialized;
-
- //! Static map of cached sound params, to prevent having to recreate them
- protected static ref map<string, ref SoundParams> m_ParamsMap;
-
- //! Static invoker for the SEffectManager.Event_OnFrameUpdate called form MissionGameplay.OnUpdate
- static ref ScriptInvoker Event_OnFrameUpdate;
-
- protected static ref map<int, EffecterBase> m_EffectersMap;
- //! Static array of IDs that were previously used, but freed up by unregistering Effecters
- protected static ref array<int> m_FreeEffecterIDs;
-
- protected static int m_HighestFreeEffecterID = 1;
-
- /** \name Generic playback
- Methods for playing Effect
- \note Since 1.15, these should work on EffectSound as well
- */
- //@{
-
- /**
- *\brief Play an Effect
- * \warning As the Effect is automatically registered, it will not be freed automatically (because of the ref)
- * Unless 'SetAutodestroy(true)' is called on the created 'Effect', which will clean it up when the sound stop
- * Alternatively, SEffectManager.DestroyEffect can be called manually, which will also unregister and cleanup
- * \param eff \p Effect The Effect to play
- * \param pos \p vector The position to play the Effect
- * \return \p int The registered ID of the Effect
- */
- static int PlayInWorld(notnull Effect eff, vector pos)
- {
- // Stop the effect first, just in case
- eff.Stop();
-
- int id = EffectRegister(eff);
-
- eff.SetPosition( pos );
- eff.Start();
-
- return id;
- }
-
- /**
- *\brief Play an Effect
- * \warning Read PlayInWorld warning
- * \param eff \p Effect The Effect to play
- * \param obj \p Object The parent of the Effect
- * \param local_pos \p vector The local position to play the Effect in relation to the parent (Optional)
- * \param local_ori \p vector The local orientation to play the Effect in relation to the parent (Optional)
- * \param force_rotation_relative_to_world \p bool Whether to force the orientation to stay in WS (Optional)
- * \return \p int The registered ID of the Effect
- */
- static int PlayOnObject(notnull Effect eff, Object obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0", bool force_rotation_relative_to_world = false)
- {
- // Stop the effect first, just in case
- eff.Stop();
-
- int id = EffectRegister(eff);
-
- if (!obj)
- {
- ErrorEx("Parent object is null.", ErrorExSeverity.WARNING);
- eff.SetPosition(local_pos);
- }
- else
- {
- eff.SetPosition(obj.GetPosition());
- }
-
- eff.SetParent(obj);
- eff.SetLocalPosition(local_pos);
- eff.SetAttachedLocalOri(local_ori);
-
- if (force_rotation_relative_to_world)
- {
- EffectParticle eff_particle = EffectParticle.Cast(eff);
-
- if (eff_particle)
- {
- eff_particle.ForceParticleRotationRelativeToWorld(force_rotation_relative_to_world);
- }
- }
-
- eff.Start();
-
- return id;
- }
-
- /**
- \brief Stops the Effect
- \param effect_id \p int The ID of the Effect to Stop
- */
- static void Stop(int effect_id)
- {
- Effect eff = m_EffectsMap.Get(effect_id);
-
- if (eff)
- {
- eff.Stop();
- }
- else
- {
- ErrorEx(string.Format("Failed to stop Effect with ID %1. The ID is not registered in m_EffectsMap!", effect_id));
- }
- }
-
- //@}
-
-
- /** \name Create/Play sound
- Methods for playing/creating sound
- */
- //@{
-
- /**
- *\brief Create an EffectSound
- * \warning Read PlayInWorld warning
- * \param sound_set \p string The sound set name of the sound
- * \param position \p vector The position to play the sound
- * \param play_fade_in \p float The fade in duration of the sound (Optional)
- * \param stop_fade_out \p float The fade out duration of the sound (Optional)
- * \param loop \p bool Whether the sound should loop (Optional)
- * \param enviroment \p bool Whether to set environment variables (Optional)
- * \return \p EffectSound The created EffectSound
- */
- static EffectSound CreateSound(string sound_set, vector position, float play_fade_in = 0, float stop_fade_out = 0, bool loop = false, bool enviroment = false)
- {
- EffectSound effect_sound = new EffectSound();
- effect_sound.SetSoundSet(sound_set);
- effect_sound.SetPosition(position);
- effect_sound.SetSoundFadeIn(play_fade_in);
- effect_sound.SetSoundFadeOut(stop_fade_out);
- effect_sound.SetSoundLoop(loop);
- effect_sound.SetEnviromentVariables(enviroment);
-
- EffectRegister( effect_sound );
-
- return effect_sound;
- }
-
- /**
- *\brief Create and play an EffectSound
- * \warning Calls CreateSound, read CreateSound warning
- * \param sound_set \p string The sound set name of the sound
- * \param position \p vector The position to play the sound
- * \param play_fade_in \p float The fade in duration of the sound (Optional)
- * \param stop_fade_out \p float The fade out duration of the sound (Optional)
- * \param loop \p bool Whether the sound should loop (Optional)
- * \return \p EffectSound The created EffectSound
- */
- static EffectSound PlaySound(string sound_set, vector position, float play_fade_in = 0, float stop_fade_out = 0, bool loop = false)
- {
- EffectSound effect_sound = CreateSound(sound_set, position, play_fade_in, stop_fade_out, loop, false);
-
- effect_sound.SoundPlay();
-
- return effect_sound;
- }
-
- /**
- *\brief Create and play an EffectSound
- * \warning Calls CreateSound, read CreateSound warning
- * \param params \p SoundParams Params to create the sound with
- * \param position \p vector The position to play the sound
- * \param play_fade_in \p float The fade in duration of the sound (Optional)
- * \param stop_fade_out \p float The fade out duration of the sound (Optional)
- * \param loop \p bool Whether the sound should loop (Optional)
- * \return \p EffectSound The created EffectSound
- */
- static EffectSound PlaySoundParams(notnull SoundParams params, vector position, float play_fade_in = 0, float stop_fade_out = 0, bool loop = false)
- {
- EffectSound effect_sound = CreateSound(params.GetName(), position, play_fade_in, stop_fade_out, loop, false);
- effect_sound.SoundPlayEx(params);
-
- return effect_sound;
- }
-
- /**
- *\brief Create and play an EffectSound, using or creating cached SoundParams
- * \warning Calls CreateSound, read CreateSound warning
- * \param sound_set \p string The sound set name of the sound
- * \param position \p vector The position to play the sound
- * \param play_fade_in \p float The fade in duration of the sound (Optional)
- * \param stop_fade_out \p float The fade out duration of the sound (Optional)
- * \param loop \p bool Whether the sound should loop (Optional)
- * \return \p EffectSound The created EffectSound
- */
- static EffectSound PlaySoundCachedParams(string sound_set, vector position, float play_fade_in = 0, float stop_fade_out = 0, bool loop = false)
- {
- SoundParams params = GetCachedSoundParam(sound_set);
-
- EffectSound effect_sound = CreateSound(params.GetName(), position, play_fade_in, stop_fade_out, loop, false);
- effect_sound.SoundPlayEx(params);
-
- return effect_sound;
- }
-
- /**
- *\brief Create and play an EffectSound, updating environment variables
- * \warning Calls CreateSound, read CreateSound warning
- * \param sound_set \p string The sound set name of the sound
- * \param position \p vector The position to play the sound
- * \param play_fade_in \p float The fade in duration of the sound (Optional)
- * \param stop_fade_out \p float The fade out duration of the sound (Optional)
- * \param loop \p bool Whether the sound should loop (Optional)
- * \return \p EffectSound The created EffectSound
- */
- static EffectSound PlaySoundEnviroment(string sound_set, vector position, float play_fade_in = 0, float stop_fade_out = 0, bool loop = false)
- {
- EffectSound effect_sound = CreateSound(sound_set, position, play_fade_in, stop_fade_out, loop, true);
-
- effect_sound.SoundPlay();
-
- return effect_sound;
- }
-
- /**
- *\brief Create and play an EffectSound
- * \warning Calls CreateSound, read CreateSound warning
- * \param sound_set \p string The sound set name of the sound
- * \param parent_object \p Object The parent Object for the sound to follow
- * \param play_fade_in \p float The fade in duration of the sound (Optional)
- * \param stop_fade_out \p float The fade out duration of the sound (Optional)
- * \param loop \p bool Whether the sound should loop (Optional)
- * \return \p EffectSound The created EffectSound
- */
- static EffectSound PlaySoundOnObject(string sound_set, Object parent_object, float play_fade_in = 0, float stop_fade_out = 0, bool loop = false)
- {
- EffectSound effect_sound = CreateSound(sound_set, parent_object.GetPosition(), play_fade_in, stop_fade_out, loop);
-
- effect_sound.SetParent( parent_object );
- effect_sound.SetLocalPosition( vector.Zero );
- effect_sound.SoundPlay();
-
- return effect_sound;
- }
-
- //@}
-
-
-
- /** \name Generic API
- General methods used for SEffectManager
- */
- //@{
-
- /**
- \brief Unregisters, stops and frees the Effect
- \param effect_sound \p EffectSound The EffectSound to free
- */
- static void DestroyEffect(Effect effect)
- {
- if (effect)
- {
- if (effect.CanDestroy())
- {
- // Functionality already happens in dtor of Effect to be safe
- delete effect;
- }
- else
- {
- // Make it clean up itself when done
- effect.SetAutodestroy(true);
- effect.Stop();
- }
- }
- }
-
- /**
- \brief Checks whether an Effect ID is registered in SEffectManager
- \param effect_id \p int The Effect ID to check
- \return \p bool Whether there is an Effect registered for this ID
- */
- static bool IsEffectExist( int effect_id )
- {
- if (!m_IsCleanup)
- return m_EffectsMap[effect_id] != null;
- else
- return false;
- }
-
- /**
- \brief Gets the Effect with the given registered Effect ID
- \param effect_id \p int The Effect ID
- \return \p Effect The Effect registered to the ID or null
- */
- static Effect GetEffectByID(int effect_id)
- {
- if (!m_IsCleanup)
- return m_EffectsMap[effect_id];
- else
- return null;
- }
-
- /**
- \brief Registers Effect in SEffectManager
- \note Already handled in SEffectManager Create/Play methods
- \note This will make SEffectManager hold a strong ref for the Effect
- \param effect \p Effect The Effect to register
- \return \p int The Effect ID
- */
- static int EffectRegister(Effect effect)
- {
- if (effect.IsRegistered())
- {
- ErrorEx(string.Format("Attempted to register Effect '%1' which was already registered.", effect.GetDebugName()), ErrorExSeverity.INFO);
- return effect.GetID();
- }
-
- int id;
-
- if (!m_IsCleanup)
- {
- id = GetFreeEffectID();
- m_EffectsMap.Insert(id, effect);
- effect.Event_OnRegistered(id);
- }
- else
- ErrorEx("Attempted to register Effect while SEffectManager is cleaning up, request ignored.", ErrorExSeverity.WARNING);
-
- return id;
- }
-
- protected static int GetFreeEffecterID()
- {
- int return_id;
-
- if (m_FreeEffecterIDs.Count() > 0)
- {
- return_id = m_FreeEffecterIDs.Get(0);
- m_FreeEffecterIDs.Remove(0);
- }
- else
- {
- return_id = m_HighestFreeEffecterID;
- ++m_HighestFreeEffecterID;
- }
-
- return return_id;
- }
-
- /**
- \brief Unregisters Effect in SEffectManager
- \note Will automatically occur on stop when the Effect is AutoDestroy
- \note ID can be gotten from the Effect by calling Effect.GetID
- \note Generic Play methods will also return the ID
- \param id \p int The ID of the Effect to unregister
- */
- static void EffectUnregister(int id)
- {
- if (m_IsCleanup)
- return; // No error needed, since it will have been unregistered anyways after cleanup is finished
-
- Effect effect;
- if ( m_EffectsMap.Find(id, effect) )
- {
- effect.Event_OnUnregistered();
- m_EffectsMap.Remove(id);
- }
-
- if ( m_FreeEffectIDs.Find(id) == -1 )
- {
- m_FreeEffectIDs.Insert(id);
- }
- }
-
- /**
- \brief Unregisters Effect in SEffectManager
- \param effect \p Effect The Effect to unregister
- */
- static void EffectUnregisterEx(Effect effect)
- {
- EffectUnregister(effect.GetID());
- }
-
- /**
- \brief Helper function for EffectRegister to decide an Effect ID
- \return \p int A currently unused Effect ID
- */
- protected static int GetFreeEffectID()
- {
- int return_id;
-
- if (m_FreeEffectIDs.Count() > 0)
- {
- return_id = m_FreeEffectIDs.Get(0);
- m_FreeEffectIDs.Remove(0);
- }
- else
- {
- return_id = m_HighestFreeEffectID;
- ++m_HighestFreeEffectID;
- }
-
- return return_id;
- }
-
- //@}
-
-
-
- /** \name Sound helpers
- Sound specific helper methods
- */
- //@{
-
- /**
- \brief Legacy, backwards compatibility
- \param sound_effect \p EffectSound The EffectSound to free
- \return \p bool A bool which is always true
- */
- static bool DestroySound(EffectSound sound_effect)
- {
- DestroyEffect(sound_effect);
- return true;
- }
-
- /**
- \brief Get or create a cached SoundParams object
- \param soundset \p string The sound set name of the sound
- \return \p SoundParams The cached SoundParams for the given soundset
- */
- static SoundParams GetCachedSoundParam(string soundset)
- {
- SoundParams params;
- if (!m_ParamsMap.Find(soundset, params))
- {
- params = new SoundParams(soundset);
- m_ParamsMap.Insert(soundset, params);
- }
- return params;
- }
-
- //@}
-
-
-
- /** \name Events
- Various events that can be overriden for custom behaviour
- */
- //@{
-
- /**
- \brief Event called from EffectSound.Event_OnSoundWaveEnded
- \note Every registered sound is registered to call this
- \param effect_sound \p EffectSound The EffectSound calling the event
- */
- static void Event_OnSoundWaveEnded(EffectSound effect_sound)
- {
-
- }
-
- /**
- \brief Event called on frame
- \note Called from MissionGameplay.OnUpdate
- \note Effects register themselves by Effect.SetEnableEventFrame(true)
- \note EffectSound is automatically registered
- \param time_delta \p float Time passed since the previous frame
- */
- static void Event_OnFrameUpdate(float time_delta)
- {
- Event_OnFrameUpdate.Invoke(time_delta);
- }
-
- //@}
-
-
-
- /** \name Lifetime
- Creation and cleanup
- */
- //@{
-
- /**
- \brief Initialize the containers
- \note This is done this way, to have these not exist on server
- */
- static void Init()
- {
- m_EffectsMap = new map<int, ref Effect>;
- m_FreeEffectIDs = new array<int>;
- m_ParamsMap = new map<string, ref SoundParams>;
- Event_OnFrameUpdate = new ScriptInvoker();
-
- m_IsInitialized = true;
- }
-
- static void InitServer()
- {
- m_EffectersMap = new map<int, EffecterBase>;
- m_FreeEffecterIDs = new array<int>;
- }
-
- /**
- \brief Cleanup method to properly clean up the static data
- \note Will be called when MissionBase is destroyed
- */
- static void Cleanup()
- {
- // Nothing to clean
- if (!m_IsInitialized)
- return;
-
- m_IsCleanup = true;
-
- // There should not be anything in here on server
- if (GetGame() && GetGame().IsDedicatedServer())
- {
- if (m_ParamsMap.Count() > 0)
- ErrorEx(string.Format("SEffectManager containing SoundParams on server."), ErrorExSeverity.WARNING);
-
- if (m_EffectsMap.Count() > 0)
- ErrorEx(string.Format("SEffectManager containing Effect on server."), ErrorExSeverity.WARNING);
- }
-
- // These are intentionally cached, just clear them
- m_ParamsMap.Clear();
-
- // These might not be intentionally still here, so log how many there are
- #ifdef DEVELOPER
- Print("--- SEffectManager Cleanup dump - Begin ------------------------");
- Print(string.Format("Effect count: %1", m_EffectsMap.Count()));
- #endif
-
- // Best to call the unregister event before clearing the map
- // In case some ref is still being held elsewhere and will still be kept alive
- foreach (int id, Effect eff : m_EffectsMap)
- {
- eff.Event_OnUnregistered();
- #ifdef SFXM_DUMP
- Print(string.Format( "%1 :: %2 :: %3", eff, typename.EnumToString(EffectType, eff.GetEffectType()), eff.GetDebugName() ));
- #endif
- }
-
- foreach (int i, EffecterBase effecter : m_EffectersMap)
- {
- effecter.Delete();
- }
-
- #ifdef DEVELOPER
- Print("--- SEffectManager Cleanup dump - End --------------------------");
- #endif
-
- // Now we can clear it
- m_EffectsMap.Clear();
- m_EffectersMap.Clear();
-
- // Reset the state
- m_HighestFreeEffectID = 1;
- Event_OnFrameUpdate.Clear();
- m_IsCleanup = false;
- }
-
- //@}
-
- //! returns unique effecter ID
- static int CreateParticleServer(vector pos, EffecterParameters parameters)
- {
- EffecterBase eff;
- eff = EffecterBase.Cast(GetGame().CreateObjectEx(parameters.m_EffecterType, pos, ECE_PLACE_ON_SURFACE));
-
- if (eff)
- {
- int id = GetFreeEffecterID();
- m_EffectersMap.Insert(id, eff);
- }
-
- eff.Init(id, parameters);
- return id;
- }
-
- //! allows re-initializing existing effecter with new parameters (extept m_EffecterType, obviously)
- static void ReinitParticleServer(int effecterID, EffecterParameters parameters)
- {
- EffecterBase eff = m_EffectersMap.Get(effecterID);
- if (eff)
- {
- eff.Init(effecterID,parameters);
- }
- }
-
- static void ReactivateParticleServer(int effecterID)
- {
- EffecterBase eff = m_EffectersMap.Get(effecterID);
- if (eff)
- {
- eff.Reactivate();
- }
- }
-
- static void StartParticleServer(int effecterID)
- {
- EffecterBase eff = m_EffectersMap.Get(effecterID);
- if (eff)
- {
- eff.Start();
- }
-
- }
-
- static void StopParticleServer(int effecterID)
- {
- EffecterBase eff = m_EffectersMap.Get(effecterID);
- if (eff)
- {
- eff.Stop();
- }
- }
-
- static void DestroyEffecterParticleServer(int effecterID)
- {
- EffecterBase eff = m_EffectersMap.Get(effecterID);
- if (eff)
- {
- m_EffectersMap.Remove(effecterID);
- eff.DeleteSafe();
- }
- }
-
- static void OnUpdate(float timeslice)
- {
- if (m_EffectersMap)
- {
- foreach (int i, EffecterBase effecter : m_EffectersMap)
- {
- effecter.DecreaseLifespan(timeslice);
- }
- }
- }
- }
- enum EffecterCommands
- {
- NONE = -1,
- START,
- STOP,
- REACTIVATE0,
- REACTIVATE1
- }
-
- class EffecterParameters
- {
- string m_EffecterType;
- float m_Lifespan;
- void EffecterParameters(string type, float lifespan)
- {
- m_EffecterType = type;
- m_Lifespan = lifespan;
- }
- }
- class ParticleEffecterParameters : EffecterParameters
- {
- int m_ParticleID;
- void ParticleEffecterParameters(string type, float lifespan, int particleID)
- {
- m_ParticleID = particleID;
- }
- }
- class EffecterBase : EntityAI
- {
- const float NOT_DEFINED_LIFESPAN = -1;
- protected float m_Lifespan;
- protected int m_ID;
- protected int m_Command = EffecterCommands.NONE;
- protected int m_CommandSync = EffecterCommands.NONE;
-
- void EffecterBase()
- {
- RegisterNetSyncVariableInt("m_CommandSync");
- }
-
- void Init(int id, EffecterParameters parameters)
- {
- m_ID = id;
- SetLifespan(parameters.m_Lifespan);
- }
-
- void DecreaseLifespan(float timeSlice)
- {
- if (m_Lifespan == NOT_DEFINED_LIFESPAN)
- return;
-
- m_Lifespan -= timeSlice;
- if (m_Lifespan < 0)
- {
- SEffectManager.DestroyEffecterParticleServer(m_ID);
- }
- }
-
- void SetLifespan(float lifespan)
- {
- m_Lifespan = lifespan;
- }
-
- void Start()
- {
- m_CommandSync = EffecterCommands.START;
- Process();
- }
-
- void Stop()
- {
- m_CommandSync = EffecterCommands.STOP;
- Process();
- }
-
- void Reactivate()
- {
- if (m_CommandSync == EffecterCommands.REACTIVATE0)
- {
- m_CommandSync = EffecterCommands.REACTIVATE1;
- }
- else
- {
- m_CommandSync = EffecterCommands.REACTIVATE0;
- }
- Process();
- }
-
- void Process()
- {
- if (GetGame().IsMultiplayer())
- {
- SetSynchDirty();
- }
- else
- {
- OnVariablesSynchronized();
- }
- }
-
- override int GetHideIconMask()
- {
- return EInventoryIconVisibility.HIDE_VICINITY;
- }
- }
- class ParticleEffecter : EffecterBase
- {
- protected int m_ParticleEffectID = -1;
- protected int m_ParticleEffectIDSync = -1;
- protected ref EffectParticleGeneral m_Effect = null;
- //protected int m_EffectID = -1;
- void ParticleEffecter(int lifespan)
- {
- RegisterNetSyncVariableInt("m_ParticleEffectIDSync");
- }
- override void Init(int id, EffecterParameters parameters)
- {
- super.Init(id, parameters);
-
- ParticleEffecterParameters par = ParticleEffecterParameters.Cast(parameters);
- SetParticle(par.m_ParticleID);
- }
-
- void SetParticle(int particleID)
- {
- m_ParticleEffectIDSync = particleID;
- Process();
- }
- override void OnVariablesSynchronized()
- {
- if (m_ParticleEffectIDSync != m_ParticleEffectID)
- {
- if (m_Effect)
- {
- m_Effect.SetParticle(m_ParticleEffectIDSync);
- }
- else
- {
- m_Effect = new EffectParticleGeneral();
- m_Effect.SetParticle(m_ParticleEffectIDSync);
- SEffectManager.PlayInWorld(m_Effect, GetWorldPosition());
- }
- m_ParticleEffectID = m_ParticleEffectIDSync;
- }
-
- if (m_CommandSync != m_Command)
- {
- switch (m_CommandSync)
- {
- case EffecterCommands.START:
- if (m_Effect && !m_Effect.IsPlaying())
- {
- m_Effect.SetParticle(m_ParticleEffectID);
- m_Effect.Start();
- }
- break;
-
- case EffecterCommands.STOP:
- if (m_Effect && m_Effect.IsPlaying())
- {
- m_Effect.Stop();
- }
- break;
-
- case EffecterCommands.REACTIVATE0:
- case EffecterCommands.REACTIVATE1:
- if (m_Effect)
- {
- m_Effect.SetParticle(m_ParticleEffectID);
- }
- if (!m_Effect.IsPlaying())
- {
- m_Effect.Start();
- }
- break;
-
- default:
- break;
- }
-
- m_Command = m_CommandSync;
- }
- }
-
- void ~ParticleEffecter()
- {
- SEffectManager.DestroyEffect(m_Effect);
- }
- }
- class EffectParticleGeneral : EffectParticle
- {
- int m_LastParticleID;
- void EffectParticleGeneral()
- {
- }
-
- void SetParticle( int particleID )
- {
- bool was_playing = IsPlaying();
-
- Stop();
-
- SetParticleID(particleID);
-
- if (was_playing)
- {
- Start();
- }
- }
-
- override void SetParticleID( int id )
- {
- super.SetParticleID(id);
- m_LastParticleID = id;
- }
- }
|