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

Added a new type of scriptable variable that handles lists of values. The...

Added a new type of scriptable variable that handles lists of values.  The list itself is not accessible externally and any function that modifies it fires an event that the value has been changed.
parent 3e3fddb9
No related branches found
No related tags found
1 merge request!6Merge Request for Issue/11 - list variables
Showing
with 610 additions and 0 deletions
using UnityEngine;
namespace Shared.ScriptableVariables {
// A list of bool values to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Boolean List")]
public class BooleanListVariable : ListScriptableVariable<bool> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(BooleanListVariable))]
[UnityEditor.CanEditMultipleObjects]
public class BooleanListScriptableVariableEditor : BooleanListVariable.BaseListScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: 15f3837928781de49893cf8afbf3cf74
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A list of float values to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Float List")]
public class FloatListVariable : ListScriptableVariable<float> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(FloatListVariable))]
[UnityEditor.CanEditMultipleObjects]
public class FloatListScriptableVariableEditor : FloatListVariable.BaseListScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: b5347f0cb64d988408fcfe1328b71147
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A list GameObject values to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/GameObject List")]
public class GameObjectListVariable : ListScriptableVariable<GameObject> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(GameObjectListVariable))]
[UnityEditor.CanEditMultipleObjects]
public class GameObjectListScriptableVariableEditor : GameObjectListVariable.BaseListScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: a5d3621783bd7b44586a6798709e9fb6
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A list of int values to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Int List")]
public class IntListVariable : ListScriptableVariable<int> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(IntListVariable))]
[UnityEditor.CanEditMultipleObjects]
public class IntListScriptableVariableEditor : IntListVariable.BaseListScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: 95da63b0a149f85498e00f302dced403
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
namespace Shared.ScriptableVariables {
//---------------------------------------------------------------------------
// Base class for Scriptable Objects to share across components, scenes, and prefabs
public abstract class ListScriptableVariable<T> : ScriptableVariable, Resettable {
[Tooltip("The value of the variable")]
[SerializeField]
private List<T> list = new List<T>();
[Tooltip("The default value of the variable to go back to on Reset")]
public List<T> defaultList = new List<T>();
public delegate void ValueChangeHandler();
public event ValueChangeHandler OnValueChanged;
//////////////////////////////// LIST MODIFIERS /////////////////////////////
//---------------------------------------------------------------------------
public void Reset() {
list = new List<T>(defaultList);
ValueChanged();
}
//---------------------------------------------------------------------------
public void Set(List<T> other) {
list.Clear();
list.AddRange(other);
ValueChanged();
}
//---------------------------------------------------------------------------
public void Clear() {
list.Clear();
ValueChanged();
}
//---------------------------------------------------------------------------
public void Add(T value) {
list.Add(value);
ValueChanged();
}
//---------------------------------------------------------------------------
public void AddRange(List<T> otherList) {
list.AddRange(otherList);
ValueChanged();
}
//---------------------------------------------------------------------------
public void Insert(int index, T item) {
list.Insert(index, item);
ValueChanged();
}
//---------------------------------------------------------------------------
public void InsertRange(int index, IEnumerable<T> collection) {
list.InsertRange(index, collection);
ValueChanged();
}
//---------------------------------------------------------------------------
public void Remove(T value) {
list.Remove(value);
ValueChanged();
}
//---------------------------------------------------------------------------
public int RemoveAll(Predicate<T> match) {
var removedCount = list.RemoveAll(match);
ValueChanged();
return removedCount;
}
//---------------------------------------------------------------------------
public void RemoveAt(int index) {
list.RemoveAt(index);
ValueChanged();
}
//---------------------------------------------------------------------------
public void RemoveRange(int index, int count) {
list.RemoveRange(index, count);
ValueChanged();
}
//---------------------------------------------------------------------------
public void Reverse(int index, int count) {
list.Reverse(index, count);
ValueChanged();
}
//---------------------------------------------------------------------------
public void Reverse() {
list.Reverse();
ValueChanged();
}
//---------------------------------------------------------------------------
public void Sort(Comparison<T> comparison) {
list.Sort(comparison);
ValueChanged();
}
//---------------------------------------------------------------------------
public void Sort(int index, int count, IComparer<T> comparer) {
list.Sort(index, count, comparer);
ValueChanged();
}
//---------------------------------------------------------------------------
public void Sort() {
list.Sort();
ValueChanged();
}
//---------------------------------------------------------------------------
public void Sort(IComparer<T> comparer) {
list.Sort(comparer);
ValueChanged();
}
//---------------------------------------------------------------------------
public void TrimExcess() {
list.TrimExcess();
ValueChanged();
}
//////////////////////////////// LIST ACCESSORS /////////////////////////////
//---------------------------------------------------------------------------
public ReadOnlyCollection<T> Value {
get { return list.AsReadOnly(); }
}
//---------------------------------------------------------------------------
public int BinarySearch(T item) {
return list.BinarySearch(item);
}
//---------------------------------------------------------------------------
public int BinarySearch(T item, IComparer<T> comparer) {
return list.BinarySearch(item, comparer);
}
//---------------------------------------------------------------------------
public int BinarySearch(int index, int count, T item, IComparer<T> comparer) {
return list.BinarySearch(index, count, item, comparer);
}
//---------------------------------------------------------------------------
public bool Contains(T item) {
return list.Contains(item);
}
//---------------------------------------------------------------------------
public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter) {
return list.ConvertAll(converter);
}
//---------------------------------------------------------------------------
public void CopyTo(int index, T[] array, int arrayIndex, int count) {
list.CopyTo(index, array, arrayIndex, count);
}
//---------------------------------------------------------------------------
public void CopyTo(T[] array, int arrayIndex) {
list.CopyTo(array, arrayIndex);
}
//---------------------------------------------------------------------------
public void CopyTo(T[] array) {
list.CopyTo(array);
}
//---------------------------------------------------------------------------
public bool Exists(Predicate<T> match) {
return list.Exists(match);
}
//---------------------------------------------------------------------------
public T Find(Predicate<T> match) {
return list.Find(match);
}
//---------------------------------------------------------------------------
public List<T> FindAll(Predicate<T> match) {
return list.FindAll(match);
}
//---------------------------------------------------------------------------
public int FindIndex(int startIndex, int count, Predicate<T> match) {
return list.FindIndex(startIndex, count, match);
}
//---------------------------------------------------------------------------
public int FindIndex(int startIndex, Predicate<T> match) {
return list.FindIndex(startIndex, match);
}
//---------------------------------------------------------------------------
public int FindIndex(Predicate<T> match) {
return list.FindIndex(match);
}
//---------------------------------------------------------------------------
public T FindLast(Predicate<T> match) {
return list.FindLast(match);
}
//---------------------------------------------------------------------------
public int FindLastIndex(int startIndex, int count, Predicate<T> match) {
return list.FindLastIndex(startIndex, count, match);
}
//---------------------------------------------------------------------------
public int FindLastIndex(int startIndex, Predicate<T> match) {
return list.FindLastIndex(startIndex, match);
}
//---------------------------------------------------------------------------
public int FindLastIndex(Predicate<T> match) {
return list.FindLastIndex(match);
}
//---------------------------------------------------------------------------
public void ForEach(Action<T> action) {
list.ForEach(action);
}
//---------------------------------------------------------------------------
public int IndexOf(T item, int index, int count) {
return list.IndexOf(item, index, count);
}
//---------------------------------------------------------------------------
public int IndexOf(T item, int index) {
return list.IndexOf(item, index);
}
//---------------------------------------------------------------------------
public int IndexOf(T item) {
return list.IndexOf(item);
}
//---------------------------------------------------------------------------
public int LastIndexOf(T item) {
return list.LastIndexOf(item);
}
//---------------------------------------------------------------------------
public int LastIndexOf(T item, int index) {
return list.LastIndexOf(item, index);
}
//---------------------------------------------------------------------------
public int LastIndexOf(T item, int index, int count) {
return list.LastIndexOf(item, index, count);
}
//---------------------------------------------------------------------------
public bool TrueForAll(Predicate<T> match) {
return list.TrueForAll(match);
}
//---------------------------------------------------------------------------
protected void ValueChanged() {
if (OnValueChanged != null) {
OnValueChanged.Invoke();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
//Base class for custom editors which expose the Property of ScriptableVariables
public class BaseListScriptableVariableEditor : UnityEditor.Editor {
public override void OnInspectorGUI() {
UnityEditor.EditorGUI.BeginChangeCheck();
base.OnInspectorGUI();
if (UnityEditor.EditorGUI.EndChangeCheck()) {
var scriptableVariable = target as ListScriptableVariable<T>;
if (scriptableVariable.OnValueChanged != null) {
scriptableVariable.OnValueChanged.Invoke();
}
}
}
}
#endif
}
}
fileFormatVersion: 2
guid: 2c46b23b3dbebc24b87594a6e5512b91
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A list of string values to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/String List")]
public class StringListVariable : ListScriptableVariable<string> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(StringListVariable))]
[UnityEditor.CanEditMultipleObjects]
public class StringListScriptableVariableEditor : StringListVariable.BaseListScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: ac8c63c807dbd474ab89665284db53a2
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A list of Transform values to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Transform List")]
public class TransformListVariable : ListScriptableVariable<Transform> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(TransformListVariable))]
[UnityEditor.CanEditMultipleObjects]
public class TransformListScriptableVariableEditor : TransformListVariable.BaseListScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: cb949882da42d66418ff2ad4b175bf68
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A list of Vector2 values to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Vector2 List")]
public class Vector2ListVariable : ListScriptableVariable<Vector2> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(Vector2ListVariable))]
[UnityEditor.CanEditMultipleObjects]
public class Vector2ListScriptableVariableEditor : Vector2ListVariable.BaseListScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: 48bb1201e64b01348a9c2430cdb2e2b0
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A list of Vector3 values to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Vector3 List")]
public class Vector3ListVariable : ListScriptableVariable<Vector3> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(Vector3ListVariable))]
[UnityEditor.CanEditMultipleObjects]
public class Vector3ListScriptableVariableEditor : Vector3ListVariable.BaseListScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: c1dc4fd277987534faa8414e8bc6637f
timeCreated: 1510599427
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Shared.ScriptableVariables {
// A list of Vector4 values to share across components, scenes, and prefabs
[CreateAssetMenu(menuName = "Scriptable Objects/Variables/Vector4 List")]
public class Vector4ListVariable : ListScriptableVariable<Vector4> {
//---------------------------------------------------------------------------
[ContextMenu("Reset To Default Value")]
public void ContextMenuReset() {
Reset();
}
}
#if UNITY_EDITOR
//-----------------------------------------------------------------------------
[UnityEditor.CustomEditor(typeof(Vector4ListVariable))]
[UnityEditor.CanEditMultipleObjects]
public class Vector4ListScriptableVariableEditor : Vector4ListVariable.BaseListScriptableVariableEditor {
}
#endif
}
fileFormatVersion: 2
guid: c163b272645f15349ab7c12571922835
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