This file contains hidden or 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
| using System; | |
| public static class EventBus<T> | |
| { | |
| private static event Action<T> Delegate; | |
| public static void Subscribe(Action<T> handler) => Delegate += handler; | |
| public static void Unsubscribe(Action<T> handler) => Delegate -= handler; | |
| public static void Publish(T ev) => Delegate?.Invoke(ev); | |
| } |
This file contains hidden or 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
| using System; | |
| namespace Kryz.Tweening | |
| { | |
| // Made with the help of this great post: https://joshondesign.com/2013/03/01/improvedEasingEquations | |
| // --------------------------------- Other Related Links -------------------------------------------------------------------- | |
| // Original equations, bad formulation: https://github.com/danro/jquery-easing/blob/master/jquery.easing.js | |
| // A few equations, very simplified: https://gist.github.com/gre/1650294 | |
| // Easings.net equations, simplified: https://github.com/ai/easings.net/blob/master/src/easings/easingsFunctions.ts |
This file contains hidden or 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
| namespace Kryz.CharacterStats | |
| { | |
| [Serializable] | |
| public class CharacterStat | |
| { | |
| //... | |
| } | |
| } |
This file contains hidden or 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 CharacterStat() | |
| { | |
| statModifiers = new List<StatModifier>(); | |
| StatModifiers = statModifiers.AsReadOnly(); | |
| } | |
| public CharacterStat(float baseValue) : this() | |
| { | |
| BaseValue = baseValue; | |
| } |
This file contains hidden or 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
| [Serializable] | |
| public class CharacterStat |
This file contains hidden or 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
| protected bool isDirty = true; | |
| protected float lastBaseValue; | |
| protected float _value; | |
| public virtual float Value {} | |
| protected readonly List<StatModifier> statModifiers; | |
| public virtual void AddModifier(StatModifier mod); | |
| public virtual bool RemoveModifier(StatModifier mod); | |
| public virtual bool RemoveAllModifiersFromSource(object source); |
This file contains hidden or 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 enum StatModType | |
| { | |
| Flat = 100, | |
| PercentAdd = 200, | |
| PercentMult = 300, | |
| } |
This file contains hidden or 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
| // Add this variable | |
| private float lastBaseValue = float.MinValue; | |
| // Change Value | |
| public float Value { | |
| get { | |
| if(isDirty || lastBaseValue != BaseValue) { | |
| lastBaseValue = BaseValue; | |
| _value = CalculateFinalValue(); | |
| isDirty = false; |
This file contains hidden or 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 readonly ReadOnlyCollection<StatModifier> StatModifiers; // Add this variable | |
| public CharacterStat(float baseValue) | |
| { | |
| BaseValue = baseValue; | |
| statModifiers = new List<StatModifier>(); | |
| StatModifiers = statModifiers.AsReadOnly(); // Add this line to the constructor | |
| } |
This file contains hidden or 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 bool RemoveModifier(StatModifier mod) | |
| { | |
| if (statModifiers.Remove(mod)) | |
| { | |
| isDirty = true; | |
| return true; | |
| } | |
| return false; | |
| } |
NewerOlder