Skip to content

Instantly share code, notes, and snippets.

@wowbroforce
Last active February 16, 2020 21:02
Show Gist options
  • Save wowbroforce/de1374a8355cc542397cc1697c16702a to your computer and use it in GitHub Desktop.
Save wowbroforce/de1374a8355cc542397cc1697c16702a to your computer and use it in GitHub Desktop.
using UnityEngine;
[CreateAssetMenu(fileName = "FloatVariable", menuName = "~/Assets/Scripts/FloatVariable")]
public class FloatVariable : Variable<float> { }
using UnityEngine;
[CreateAssetMenu(fileName = "IntVariable", menuName = "~/Assets/Scripts/IntVariable")]
public class IntVariable : Variable<int> { }
using UnityEngine;
[CreateAssetMenu(fileName = "StringVariable", menuName = "~/Assets/Scripts/StringVariable")]
public class StringVariable : Variable<string> { }
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