Skip to content
Snippets Groups Projects
Commit d242fe6c authored by Heine, Eric R's avatar Heine, Eric R
Browse files

Separated out the concrete UnityEvents that get used a bunch when using...

Separated out the concrete UnityEvents that get used a bunch when using ScriptableVariables into separate files and added a bunch of monobehaviours to fire unity events based on variable values.
parent 028870c3
No related branches found
No related tags found
No related merge requests found
Showing
with 353 additions and 11 deletions
fileFormatVersion: 2
guid: dc77771c8116f084f9473a3efaf4040a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie Unity's event system to variable values based on conditions
public class BooleanVariableComparison : MonoBehaviour {
[Tooltip("The variable we are watching value changes to compare against something else")]
public BooleanVariable variable;
[Tooltip("Scriptable Variable to compare, if null then comparison value will be used to compare")]
public BooleanVariable comparisonVariable;
[Tooltip("Hardcoded value to compare against variable if comparisonVariable isn't set")]
public bool comparisonValue;
[Tooltip("Fires if variable changes and its value is equal to the comparison amount")]
public UnityEvent onEqual;
[Tooltip("Fires if variable changes and its value is not equal to the comparison amount")]
public UnityEvent onNotEqual;
[Tooltip("Fires true or false if the values are equal whenever variable's value changes")]
public BooleanUnityEvent onValueChanged;
// --------------------------------------------------------------------------
void OnEnable() {
variable.OnValueChanged += OnValueChanged;
OnValueChanged();
}
// --------------------------------------------------------------------------
void OnDisable() {
variable.OnValueChanged -= OnValueChanged;
}
// --------------------------------------------------------------------------
private void OnValueChanged() {
var equal = variable.Value == (comparisonVariable != null ? comparisonVariable.Value : comparisonValue);
if (equal) {
onEqual?.Invoke();
}
else {
onNotEqual?.Invoke();
}
onValueChanged?.Invoke(equal);
}
}
}
fileFormatVersion: 2
guid: c1d2347ee56ed254ba3177b22be82c89
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie Unity's event system to variable values based on conditions
public class FloatVariableComparison : MonoBehaviour {
[Tooltip("The variable we are watching value changes to compare against something else")]
public FloatVariable variable;
[Tooltip("Scriptable Variable to compare, if null then comparison value will be used to compare")]
public FloatVariable comparisonVariable;
[Tooltip("Hardcoded value to compare against variable if comparisonVariable isn't set")]
public float comparisonValue;
[Tooltip("Fires if variable changes and its value is equal to the comparison amount")]
public UnityEvent onEqual;
[Tooltip("Fires if variable changes and its value is not equal to the comparison amount")]
public UnityEvent onNotEqual;
[Tooltip("Fires if variable changes and its value is less than or equal to the comparison amount")]
public UnityEvent onLessThanEqual;
[Tooltip("Fires if variable changes and its value is greater than or equal to the comparison amount")]
public UnityEvent onGreaterThanEqual;
[Tooltip("Fires if variable changes and its value is less than the comparison amount")]
public UnityEvent onLessThan;
[Tooltip("Fires if variable changes and its value is greater than the comparison amount")]
public UnityEvent onGreaterThan;
// --------------------------------------------------------------------------
void OnEnable() {
variable.OnValueChanged += OnValueChanged;
OnValueChanged();
}
// --------------------------------------------------------------------------
void OnDisable() {
variable.OnValueChanged -= OnValueChanged;
}
// --------------------------------------------------------------------------
private void OnValueChanged() {
var otherValue = comparisonVariable != null ? comparisonVariable.Value : comparisonValue;
if (variable.Value == otherValue) {
onEqual?.Invoke();
onLessThanEqual?.Invoke();
onGreaterThanEqual?.Invoke();
}
else {
onNotEqual?.Invoke();
if (variable.Value < otherValue) {
onLessThan?.Invoke();
}
else {
onGreaterThan?.Invoke();
}
}
}
}
}
fileFormatVersion: 2
guid: 7f697a9fe7ba7dc429450c3388f5889a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie Unity's event system to variable values based on conditions
public class IntVariableComparison : MonoBehaviour {
[Tooltip("The variable we are watching value changes to compare against something else")]
public IntVariable variable;
[Tooltip("Scriptable Variable to compare, if null then comparison value will be used to compare")]
public IntVariable comparisonVariable;
[Tooltip("Hardcoded value to compare against variable if comparisonVariable isn't set")]
public int comparisonValue;
[Tooltip("Fires if variable changes and its value is equal to the comparison amount")]
public UnityEvent onEqual;
[Tooltip("Fires if variable changes and its value is not equal to the comparison amount")]
public UnityEvent onNotEqual;
[Tooltip("Fires if variable changes and its value is less than or equal to the comparison amount")]
public UnityEvent onLessThanEqual;
[Tooltip("Fires if variable changes and its value is greater than or equal to the comparison amount")]
public UnityEvent onGreaterThanEqual;
[Tooltip("Fires if variable changes and its value is less than the comparison amount")]
public UnityEvent onLessThan;
[Tooltip("Fires if variable changes and its value is greater than the comparison amount")]
public UnityEvent onGreaterThan;
// --------------------------------------------------------------------------
void OnEnable() {
variable.OnValueChanged += OnValueChanged;
OnValueChanged();
}
// --------------------------------------------------------------------------
void OnDisable() {
variable.OnValueChanged -= OnValueChanged;
}
// --------------------------------------------------------------------------
private void OnValueChanged() {
var otherValue = comparisonVariable != null ? comparisonVariable.Value : comparisonValue;
if (variable.Value == otherValue) {
onEqual?.Invoke();
onLessThanEqual?.Invoke();
onGreaterThanEqual?.Invoke();
}
else {
onNotEqual?.Invoke();
if (variable.Value < otherValue) {
onLessThan?.Invoke();
}
else {
onGreaterThan?.Invoke();
}
}
}
}
}
fileFormatVersion: 2
guid: 2b00b85392bbb0049aeee6c3171504d3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie Unity's event system to variable values based on conditions
public class StringVariableComparison : MonoBehaviour {
[Tooltip("The variable we are watching value changes to compare against something else")]
public StringVariable variable;
[Tooltip("Scriptable Variable to compare, if null then comparison value will be used to compare")]
public StringVariable comparisonVariable;
[Tooltip("Hardcoded value to compare against variable if comparisonVariable isn't set")]
public string comparisonValue;
[Tooltip("Fires if variable changes and its value is equal to the comparison amount")]
public UnityEvent onEqual;
[Tooltip("Fires if variable changes and its value is not equal to the comparison amount")]
public UnityEvent onNotEqual;
[Tooltip("Fires true or false if the values are equal whenever variable's value changes")]
public BooleanUnityEvent onValueChanged;
// --------------------------------------------------------------------------
void OnEnable() {
variable.OnValueChanged += OnValueChanged;
OnValueChanged();
}
// --------------------------------------------------------------------------
void OnDisable() {
variable.OnValueChanged -= OnValueChanged;
}
// --------------------------------------------------------------------------
private void OnValueChanged() {
var equal = variable.Value == (comparisonVariable != null ? comparisonVariable.Value : comparisonValue);
if (equal) {
onEqual?.Invoke();
}
else {
onNotEqual?.Invoke();
}
onValueChanged?.Invoke(equal);
}
}
}
fileFormatVersion: 2
guid: 35be64c051120874eb5c47f322945176
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
[System.Serializable]
public class BooleanUnityEvent : UnityEvent<bool> {}
}
fileFormatVersion: 2
guid: a7e3943f0af22af4f821b55e69061ef7
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
[System.Serializable]
public class FloatUnityEvent : UnityEvent<float> {}
}
fileFormatVersion: 2
guid: 40b9af2ad860c4f448c6ff48eadfc295
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
[System.Serializable]
public class IntUnityEvent : UnityEvent<int> {}
}
fileFormatVersion: 2
guid: f63cca39c425e0a4e8fa808a634b26d6
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
[System.Serializable]
public class StringUnityEvent : UnityEvent<string> {}
}
fileFormatVersion: 2
guid: 4605ba0718567c14ea2336b605bbff7c
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -4,9 +4,6 @@ using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie BooleanGameEvents to Unity's event system
public class BooleanGameEventListener : GameEventListener<bool> {
[System.Serializable]
public class BooleanUnityEvent : UnityEvent<bool> { }
[Tooltip("The game event to listen to")]
public BooleanGameEvent eventToListenTo;
......
......@@ -2,7 +2,6 @@
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
/// <summary>
/// Used to trigger a UnityEvent in response to changes on a BooleanVariable
/// </summary>
......@@ -10,11 +9,8 @@ namespace Shared.ScriptableVariables {
[Tooltip("The ScriptableVariable to listen for changes")]
public BooleanVariable variable;
[System.Serializable]
public class ChangedUnityEvent : UnityEvent<bool> { }
[Tooltip("The UnityEvent that gets triggered when the variable changes value")]
public ChangedUnityEvent OnValueChangedEvent;
public BooleanUnityEvent OnValueChangedEvent;
//---------------------------------------------------------------------------
protected override ScriptableVariable<bool> GetScriptableVariable() { return variable; }
......
......@@ -4,9 +4,6 @@ using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie FloatGameEvents to Unity's event system
public class FloatGameEventListener : GameEventListener<float> {
[System.Serializable]
public class FloatUnityEvent : UnityEvent<float> { }
[Tooltip("The game event to listen to")]
public FloatGameEvent eventToListenTo;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment