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 390 additions and 0 deletions
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie IntGameEvents to Unity's event system
public class IntGameEventListener : GameEventListener<int> {
[System.Serializable]
public class IntUnityEvent : UnityEvent<int> { }
[Tooltip("The game event to listen to")]
public IntGameEvent eventToListenTo;
[Tooltip("The UnityEvent to raise in response to the game event being raised")]
public IntUnityEvent response;
//---------------------------------------------------------------------------
protected override GameEvent<int> GetGameEvent() { return eventToListenTo; }
//---------------------------------------------------------------------------
protected override UnityEvent<int> GetUnityEvent() { return response; }
}
}
fileFormatVersion: 2
guid: 75a82ff72a4ae704e9821e1403841b7c
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 IntVariable
/// </summary>
public class IntVariableListener : ScriptableVariableListener<int> {
[Tooltip("The ScriptableVariable to listen for changes")]
public IntVariable variable;
[System.Serializable]
public class ChangedUnityEvent : UnityEvent<int> { }
[Tooltip("The UnityEvent that gets triggered when the variable changes value")]
public ChangedUnityEvent OnValueChangedEvent;
//---------------------------------------------------------------------------
protected override ScriptableVariable<int> GetScriptableVariable() { return variable; }
//---------------------------------------------------------------------------
protected override UnityEvent<int> GetUnityEvent() { return OnValueChangedEvent; }
}
}
fileFormatVersion: 2
guid: ab4732b165c21ea45ae84bebc9d81f4a
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 {
/// <summary>
/// Used to trigger a UnityEvent in response to changes on a ScriptableVariable.
/// </summary>
//---------------------------------------------------------------------------
public abstract class ScriptableVariableListener<T> : MonoBehaviour {
//---------------------------------------------------------------------------
protected abstract ScriptableVariable<T> GetScriptableVariable();
//---------------------------------------------------------------------------
protected abstract UnityEvent<T> GetUnityEvent();
//---------------------------------------------------------------------------
void OnEnable() {
GetScriptableVariable().OnValueChanged += OnValueChanged;
}
//---------------------------------------------------------------------------
void OnDisable() {
GetScriptableVariable().OnValueChanged -= OnValueChanged;
}
//---------------------------------------------------------------------------
private void OnValueChanged() {
var unityEvent = GetUnityEvent();
var scriptableVariable = GetScriptableVariable();
if (unityEvent != null) {
unityEvent.Invoke(scriptableVariable.Value);
}
}
}
}
fileFormatVersion: 2
guid: ded5f8a11a2a71441b9961190e69544f
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 StringGameEvents to Unity's event system
public class StringGameEventListener : GameEventListener<string> {
[System.Serializable]
public class StringUnityEvent : UnityEvent<string> { }
[Tooltip("The game event to listen to")]
public StringGameEvent eventToListenTo;
[Tooltip("The UnityEvent to raise in response to the game event being raised")]
public StringUnityEvent response;
//---------------------------------------------------------------------------
protected override GameEvent<string> GetGameEvent() { return eventToListenTo; }
//---------------------------------------------------------------------------
protected override UnityEvent<string> GetUnityEvent() { return response; }
}
}
fileFormatVersion: 2
guid: ace966faabda0734887c2cb816d27c30
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 StringVariable
/// </summary>
public class StringVariableListener : ScriptableVariableListener<string> {
[Tooltip("The ScriptableVariable to listen for changes")]
public StringVariable variable;
[System.Serializable]
public class ChangedUnityEvent : UnityEvent<string> { }
[Tooltip("The UnityEvent that gets triggered when the variable changes value")]
public ChangedUnityEvent OnValueChangedEvent;
//---------------------------------------------------------------------------
protected override ScriptableVariable<string> GetScriptableVariable() { return variable; }
//---------------------------------------------------------------------------
protected override UnityEvent<string> GetUnityEvent() { return OnValueChangedEvent; }
}
}
fileFormatVersion: 2
guid: e6c4b70e919c94147b49f020dd8baa4f
timeCreated: 1513208270
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 199e8033ab0036d4094976417900bbd0
folderAsset: yes
timeCreated: 1510599420
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 3aa26c94f73caf643b84e8e086b5be8a
folderAsset: yes
timeCreated: 1510599712
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A boolean value to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Boolean")]
public class BooleanVariable : ScriptableVariable<bool> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(BooleanVariable))]
[UnityEditor.CanEditMultipleObjects]
public class BooleanScriptableVariableEditor : BooleanVariable.BaseScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: 6174914c1d2a75f44afcf16722f7ddbb
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A float value to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Float")]
public class FloatVariable : ScriptableVariable<float> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(FloatVariable))]
[UnityEditor.CanEditMultipleObjects]
public class FloatScriptableVariableEditor : FloatVariable.BaseScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: 7d7e88b3e41ece54596c648435a09398
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// An int value to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Int")]
public class IntVariable : ScriptableVariable<int> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(IntVariable))]
[UnityEditor.CanEditMultipleObjects]
public class IntScriptableVariableEditor : IntVariable.BaseScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: 77b835ad455148249a89aef1915debf4
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
//---------------------------------------------------------------------------
// Base class for Scriptable Objects to share across components, scenes, and prefabs
public abstract class ScriptableVariable : ScriptableObject {
[TextArea]
public string description;
}
//---------------------------------------------------------------------------
// Base class for Scriptable Objects that represent a single variable to share across components, scenes, and prefabs
public abstract class ScriptableVariable<T> : ScriptableVariable, Resettable {
[Tooltip("The value of the variable")]
[SerializeField]
private T value;
[Tooltip("The default value of the variable to go back to on Reset")]
public T defaultValue;
public delegate void ValueChangeHandler();
public event ValueChangeHandler OnValueChanged;
//---------------------------------------------------------------------------
public T Value {
get { return value; }
set {
if ((value == null && this.value != null) || (value != null && !value.Equals(this.value))) {
this.value = value;
if (OnValueChanged != null) {
OnValueChanged.Invoke();
}
}
}
}
//---------------------------------------------------------------------------
public void Reset() {
Value = defaultValue;
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
//Base class for custom editors which expose the Property of ScriptableVariables
public class BaseScriptableVariableEditor : UnityEditor.Editor {
public override void OnInspectorGUI() {
UnityEditor.EditorGUI.BeginChangeCheck();
base.OnInspectorGUI();
if (UnityEditor.EditorGUI.EndChangeCheck()) {
var scriptableVariable = target as ScriptableVariable<T>;
if (scriptableVariable.OnValueChanged != null) {
scriptableVariable.OnValueChanged.Invoke();
}
}
}
}
#endif
}
}
fileFormatVersion: 2
guid: 046df9445da2fda48b3d1f8d84047b14
timeCreated: 1510599427
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