Created
January 24, 2023 22:23
-
-
Save xjjon/33def9a56c3a319fd22f685db906a284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BuffableEntity: MonoBehaviour | |
{ | |
private readonly Dictionary<ScriptableBuff, TimedBuff> _buffs = new Dictionary<ScriptableBuff, TimedBuff>(); | |
void Update() | |
{ | |
//OPTIONAL, return before updating each buff if game is paused | |
//if (Game.isPaused) | |
// return; | |
foreach (var buff in _buffs.Values.ToList()) | |
{ | |
buff.Tick(Time.deltaTime); | |
if (buff.IsFinished) | |
{ | |
_buffs.Remove(buff.Buff); | |
} | |
} | |
} | |
public void AddBuff(TimedBuff buff) | |
{ | |
if (_buffs.ContainsKey(buff.Buff)) | |
{ | |
_buffs[buff.Buff].Activate(); | |
} | |
else | |
{ | |
_buffs.Add(buff.Buff, buff); | |
buff.Activate(); | |
} | |
} | |
public void RemoveBuff(ScriptableBuff buff) { | |
if (_buffs.ContainsKey(buff)) { | |
_buffs.Remove(buff); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment