Skip to content
Snippets Groups Projects
Commit 5179d881 authored by michael's avatar michael
Browse files

Added scriptable vars shared code and removed meta-less readme.

parent cb0baf02
No related branches found
No related tags found
No related merge requests found
Pipeline #1962 canceled
Showing
with 343 additions and 0 deletions
using UnityEngine;
namespace Shared.ScriptableVariables {
// ScriptableVariable that decouples components firing and listening to game events
[CreateAssetMenu(menuName = "Scriptable Objects/Events/Game Event")]
public class GameEvent : ScriptableVariable {
public delegate void GameEventRaised();
public event GameEventRaised OnRaised;
//---------------------------------------------------------------------------
[ContextMenu("Raise")]
public void Raise() {
if (OnRaised != null) {
OnRaised();
}
}
}
//---------------------------------------------------------------------------
public abstract class GameEvent<T> : ScriptableVariable {
public delegate void GameEventRaised(T value);
public event GameEventRaised OnRaised;
//---------------------------------------------------------------------------
public void Raise(T value) {
if (OnRaised != null) {
OnRaised(value);
}
}
}
}
fileFormatVersion: 2
guid: c1960bdf0074040469b1823b9228ac1b
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// ScriptableVariable that decouples components firing and listening to game events that require an int parameter
[CreateAssetMenu(menuName = "Scriptable Objects/Events/Int Game Event")]
public class IntGameEvent : GameEvent<int> {
}
}
fileFormatVersion: 2
guid: 898f8db1b01f0fa4987a99107325acbf
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// ScriptableVariable that decouples components firing and listening to game events that require a string parameter
[CreateAssetMenu(menuName = "Scriptable Objects/Events/String Game Event")]
public class StringGameEvent : GameEvent<string> {
}
}
fileFormatVersion: 2
guid: d499e67a7f1c28e41b5dc652ff881d53
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 53525e1a16c954f4aa2e57af9f48c661
folderAsset: yes
timeCreated: 1510599567
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
namespace Shared.ScriptableVariables {
// Interface to allow a class to be able to be reset and define what that means
public interface Resettable {
//---------------------------------------------------------------------------
// Define what it means to Reset
void Reset();
}
}
fileFormatVersion: 2
guid: b829c0fd850917d41b53b46459690a17
timeCreated: 1510599574
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 949b447effd31fe47834737e9344d527
folderAsset: yes
timeCreated: 1513206410
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
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;
[Tooltip("The UnityEvent to raise in response to the game event being raised")]
public BooleanUnityEvent response;
//---------------------------------------------------------------------------
protected override GameEvent<bool> GetGameEvent() { return eventToListenTo; }
//---------------------------------------------------------------------------
protected override UnityEvent<bool> GetUnityEvent() { return response; }
}
}
fileFormatVersion: 2
guid: 7f663866ee9d6174199e2824bb53ec3a
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
/// <summary>
/// Used to trigger a UnityEvent in response to changes on a BooleanVariable
/// </summary>
public class BooleanVariableListener : ScriptableVariableListener<bool> {
[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;
//---------------------------------------------------------------------------
protected override ScriptableVariable<bool> GetScriptableVariable() { return variable; }
//---------------------------------------------------------------------------
protected override UnityEvent<bool> GetUnityEvent() { return OnValueChangedEvent; }
}
}
fileFormatVersion: 2
guid: db17a8cbe6e4ff74ebe6f8c252162527
timeCreated: 1513208270
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
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;
[Tooltip("The UnityEvent to raise in response to the game event being raised")]
public FloatUnityEvent response;
//---------------------------------------------------------------------------
protected override GameEvent<float> GetGameEvent() { return eventToListenTo; }
//---------------------------------------------------------------------------
protected override UnityEvent<float> GetUnityEvent() { return response; }
}
}
fileFormatVersion: 2
guid: 1cc863298f8099f4ea1cbb4e0701bf2e
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
/// <summary>
/// Used to trigger a UnityEvent in response to changes on a FloatVariable
/// </summary>
public class FloatVariableListener : ScriptableVariableListener<float> {
[Tooltip("The ScriptableVariable to listen for changes")]
public FloatVariable variable;
[System.Serializable]
public class ChangedUnityEvent : UnityEvent<float> { }
[Tooltip("The UnityEvent that gets triggered when the variable changes value")]
public ChangedUnityEvent OnValueChangedEvent;
//---------------------------------------------------------------------------
protected override ScriptableVariable<float> GetScriptableVariable() { return variable; }
//---------------------------------------------------------------------------
protected override UnityEvent<float> GetUnityEvent() { return OnValueChangedEvent; }
}
}
fileFormatVersion: 2
guid: a8394c2c1178b484db494d974b6096fc
timeCreated: 1513208270
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie GameEvents to Unity's event system
public class GameEventListener : MonoBehaviour {
[Tooltip("The game event to listen to")]
public GameEvent eventToListenTo;
[Tooltip("The UnityEvent to raise in response to the game event being raised")]
public UnityEvent response;
//---------------------------------------------------------------------------
void OnEnable() {
eventToListenTo.OnRaised += OnEventRaised;
}
//---------------------------------------------------------------------------
void OnDisable() {
eventToListenTo.OnRaised -= OnEventRaised;
}
//---------------------------------------------------------------------------
public virtual void OnEventRaised() {
if (response != null) {
response.Invoke();
}
}
}
//---------------------------------------------------------------------------
public abstract class GameEventListener<T> : MonoBehaviour {
//---------------------------------------------------------------------------
protected abstract GameEvent<T> GetGameEvent();
//---------------------------------------------------------------------------
protected abstract UnityEvent<T> GetUnityEvent();
//---------------------------------------------------------------------------
void OnEnable() {
GetGameEvent().OnRaised += OnEventRaised;
}
//---------------------------------------------------------------------------
void OnDisable() {
GetGameEvent().OnRaised -= OnEventRaised;
}
//---------------------------------------------------------------------------
public virtual void OnEventRaised(T value) {
var unityEvent = GetUnityEvent();
if (unityEvent != null) {
unityEvent.Invoke(value);
}
}
}
}
fileFormatVersion: 2
guid: 991b72107ef95af46937ebdd06290da8
timeCreated: 1510599448
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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