Skip to content
Snippets Groups Projects
Commit e58acc74 authored by Erik Johnson's avatar Erik Johnson
Browse files

Merge branch 'issue/11-list-variables' into 'master'

Merge Request for Issue/11 - list variables

Closes #11

See merge request !6
parents be83bbb6 23e1d193
No related branches found
No related tags found
1 merge request!6Merge Request for Issue/11 - list variables
Showing
with 644 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 ListChangeHandler();
public event ListChangeHandler OnListChanged;
public delegate void ListItemChangeHandler(int index, T item);
public event ListItemChangeHandler OnListItemChanged;
//////////////////////////////// LIST MODIFIERS /////////////////////////////
public T this[int index] {
get { return list[index]; }
set {
list[index] = value;
ListItemChanged(index, value);
}
}
//---------------------------------------------------------------------------
public void Reset() {
list = new List<T>(defaultList);
ListChanged();
}
//---------------------------------------------------------------------------
public void Set(List<T> other) {
list.Clear();
list.AddRange(other);
ListChanged();
}
//---------------------------------------------------------------------------
public void Clear() {
list.Clear();
ListChanged();
}
//---------------------------------------------------------------------------
public void Add(T value) {
list.Add(value);
ListChanged();
}
//---------------------------------------------------------------------------
public void AddRange(List<T> otherList) {
list.AddRange(otherList);
ListChanged();
}
//---------------------------------------------------------------------------
public void Insert(int index, T item) {
list.Insert(index, item);
ListChanged();
}
//---------------------------------------------------------------------------
public void InsertRange(int index, IEnumerable<T> collection) {
list.InsertRange(index, collection);
ListChanged();
}
//---------------------------------------------------------------------------
public void Remove(T value) {
list.Remove(value);
ListChanged();
}
//---------------------------------------------------------------------------
public int RemoveAll(Predicate<T> match) {
var removedCount = list.RemoveAll(match);
ListChanged();
return removedCount;
}
//---------------------------------------------------------------------------
public void RemoveAt(int index) {
list.RemoveAt(index);
ListChanged();
}
//---------------------------------------------------------------------------
public void RemoveRange(int index, int count) {
list.RemoveRange(index, count);
ListChanged();
}
//---------------------------------------------------------------------------
public void Reverse(int index, int count) {
list.Reverse(index, count);
ListChanged();
}
//---------------------------------------------------------------------------
public void Reverse() {
list.Reverse();
ListChanged();
}
//---------------------------------------------------------------------------
public void Sort(Comparison<T> comparison) {
list.Sort(comparison);
ListChanged();
}
//---------------------------------------------------------------------------
public void Sort(int index, int count, IComparer<T> comparer) {
list.Sort(index, count, comparer);
ListChanged();
}
//---------------------------------------------------------------------------
public void Sort() {
list.Sort();
ListChanged();
}
//---------------------------------------------------------------------------
public void Sort(IComparer<T> comparer) {
list.Sort(comparer);
ListChanged();
}
//---------------------------------------------------------------------------
public void TrimExcess() {
list.TrimExcess();
ListChanged();
}
//////////////////////////////// LIST ACCESSORS /////////////////////////////
//---------------------------------------------------------------------------
public ReadOnlyCollection<T> Value {
get { return list.AsReadOnly(); }
}
//---------------------------------------------------------------------------
public int Count { get { return list.Count; } }
//---------------------------------------------------------------------------
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);
}
//---------------------------------------------------------------------------
// This function is public so that users can fire it in the specific cases
// where the ListScriptableVariable has no idea that aspects of an item in the
// list has changed
//
// For example, if the item type is a reference type, then when a field/property
// of an item changes, the list can't know.
//
// list[index].field = value;
//
// So the user of the ListScriptableVariable needs to call this function so
// the anyone who cares can be notified:
//
// list[index].field = value;
// list.ListItemChanged(index, list[index]);
//
// If a user sets the item directly with the index, this function automatically
// gets called
//
// list[index] = value;
public void ListItemChanged(int index, T item) {
OnListItemChanged?.Invoke(index, item);
}
//---------------------------------------------------------------------------
protected void ListChanged() {
OnListChanged?.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>;
scriptableVariable.ListChanged();
}
}
}
#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