Last active
February 16, 2020 21:02
-
-
Save wowbroforce/de1374a8355cc542397cc1697c16702a 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
using UnityEngine; | |
[CreateAssetMenu(fileName = "FloatVariable", menuName = "~/Assets/Scripts/FloatVariable")] | |
public class FloatVariable : Variable<float> { } |
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
using UnityEngine; | |
[CreateAssetMenu(fileName = "IntVariable", menuName = "~/Assets/Scripts/IntVariable")] | |
public class IntVariable : Variable<int> { } |
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
using UnityEngine; | |
[CreateAssetMenu(fileName = "StringVariable", menuName = "~/Assets/Scripts/StringVariable")] | |
public class StringVariable : Variable<string> { } |
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
using UnityEngine; | |
using System; | |
public class Variable<Element> : ScriptableObject, ISerializationCallbackReceiver | |
{ | |
public Element initialValue; | |
public GameEvent onRuntimeValueChanged; | |
[NonSerialized] | |
private Element _runtimeValue; | |
public Element runtimeValue | |
{ | |
get { return _runtimeValue; } | |
set | |
{ | |
_runtimeValue = value; | |
if (onRuntimeValueChanged == null) return; | |
onRuntimeValueChanged.Raise(); | |
} | |
} | |
public void OnAfterDeserialize() | |
{ | |
runtimeValue = initialValue; | |
} | |
public void OnBeforeSerialize() { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment