BindingList problem...

I am trying to use BindingList in Unity3D, because I would like to have the code aware of changes in the list values.
It compiles clean in MonoDevelop, BindingList has been around since 2.0,and it is in the System.dll. Anyone have any ideas?

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;

public class BindingListTest : MonoBehaviour
{
	
	public BindingList<string> ListTest = new BindingList<string>(); 
	
	void Awake ()
	{
		
		ListTest.AllowNew = true;
		ListTest.AllowEdit = true;
		ListTest.AllowRemove = true;
        ListTest.RaiseListChangedEvents = true;
		
        ListTest.ListChanged += new ListChangedEventHandler(ListTests_ListChanged);
	}
	
	void ListTests_ListChanged(object sender, ListChangedEventArgs e)
    {
        Debug.Log(e.ListChangedType.ToString());
    }
	
}

I am getting this error:

Off the top of my head - check your compiler settings inside Unity. BindingList is available in 2.0 but not in 2.0 subset according to the page in the doc.

I checked the settings in unity, and mono just in case.
Unity was 20. Subset, Changed that.
MonoDevelop was 3.5;

Retried. Fail. :frowning:

Found this page: http://docs.unity3d.com/Documentation/ScriptReference/MonoCompatibility.html
Did search for BindingList, and it is red for Net 2.0, 2.0 Subset, WebPlayer, and Micro.

That mean its not going to work? Or is something wrong with my setup.
:frowning: it would have been nice if that would work, finding a reactive way to handle things would be nice instead of a complex double list system and something checking every time Unity’s Update() runs.

Ok I did get something to work, sort of.
Custom list object, problem is doesn’t show up in the inspector. I’ll have to learn how that works. :stuck_out_tongue: Hopefully I can create
an editor “type” for the ObservableList.

But what I do have, throws the proper events.
ObservableList
Basically Use like a list.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

	/// <summary>
	/// List that fires events when items are changed
	/// </summary>
	/// <typeparam name="T">Type of list items</typeparam>
	public class ObservableList<T> : IList<T>
	{
		private IList<T> internalList;

		public class ListChangedEventArgs : System.EventArgs
		{
			public int index;
			public T item;
			public ListChangedEventArgs(int index, T item)
			{
				this.index = index;
				this.item = item;
			}
		}

		public delegate void ItemAddedEventHandler(object source, ListChangedEventArgs e);
		public delegate void ItemRemovedEventHandler(object source, ListChangedEventArgs e);
		public delegate void ListChangedEventHandler(object source, ListChangedEventArgs e);
		public delegate void ListClearedEventHandler(object source, System.EventArgs e);
		/// <summary>
		/// Fired whenever list item has been changed, added or removed or when list has been cleared
		/// </summary>
		public event ListChangedEventHandler ListChanged;
		/// <summary>
		/// Fired when list item has been removed from the list
		/// </summary>
		public event ItemRemovedEventHandler ItemRemoved;
		/// <summary>
		/// Fired when item has been added to the list
		/// </summary>
		public event ItemAddedEventHandler ItemAdded;
		/// <summary>
		/// Fired when list is cleared
		/// </summary>
		public event ListClearedEventHandler ListCleared;

		public ObservableList()
		{
			internalList = new List<T>();
		}

		public ObservableList(IList<T> list)
		{
			internalList = list;
		}

		public ObservableList(IEnumerable<T> collection)
		{
			internalList = new List<T>(collection);
		}

		protected virtual void OnItemAdded(ListChangedEventArgs e)
		{
			if (ItemAdded != null)
				ItemAdded(this, e);
		}

		protected virtual void OnItemRemoved(ListChangedEventArgs e)
		{
			if (ItemRemoved != null)
				ItemRemoved(this, e);
		}

		protected virtual void OnListChanged(ListChangedEventArgs e)
		{
			if (ListChanged != null)
				ListChanged(this, e);
		}

		protected virtual void OnListCleared(System.EventArgs e)
		{
			if (ListCleared != null)
				ListCleared(this, e);
		}

		public int IndexOf(T item)
		{
			return internalList.IndexOf(item);
		}

		public void Insert(int index, T item)
		{
			internalList.Insert(index, item);
			OnListChanged(new ListChangedEventArgs(index, item));
		}

		public void RemoveAt(int index)
		{
			T item = internalList[index];
			internalList.Remove(item);
			OnListChanged(new ListChangedEventArgs(index, item));
			OnItemRemoved(new ListChangedEventArgs(index, item));
		}

		public T this[int index]
		{
			get { return internalList[index]; }
			set
			{
				internalList[index] = value;
				OnListChanged(new ListChangedEventArgs(index, value));
			}
		}

		public void Add(T item)
		{
			internalList.Add(item);
			OnListChanged(new ListChangedEventArgs(internalList.IndexOf(item), item));
			OnItemAdded(new ListChangedEventArgs(internalList.IndexOf(item), item));
		}

		public void Clear()
		{
			internalList.Clear();
			OnListCleared(new EventArgs());
		}

		public bool Contains(T item)
		{
			return internalList.Contains(item);
		}

		public void CopyTo(T[] array, int arrayIndex)
		{
			CopyTo(array, arrayIndex);
		}

		public int Count
		{
			get { return internalList.Count; }
		}

		public bool IsReadOnly
		{
			get { return IsReadOnly; }
		}

		public bool Remove(T item)
		{
			lock (this)
			{
				int index = internalList.IndexOf(item);
				if (internalList.Remove(item))
				{
					OnListChanged(new ListChangedEventArgs(index, item));
					OnItemRemoved(new ListChangedEventArgs(index, item));
					return true;
				}
				else
					return false;
			}
		}

		public IEnumerator<T> GetEnumerator()
		{
			return internalList.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable)internalList).GetEnumerator();
		}
	}

Test Game Script
To Throw on a GameObject

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System;

public class ObservableListTest : MonoBehaviour
{
	private bool bAdded = false;
	private bool bStarted = false;
	private DateTime started;
	
	public ObservableList<string> ListTest = new ObservableList<string>(); 
	
	void Awake ()
	{
		
		ListTest.ListChanged += new ObservableList<string>.ListChangedEventHandler(ListTests_ListChanged);
		ListTest.ItemAdded += new ObservableList<string>.ItemAddedEventHandler(ListTests_ItemAdded);
		ListTest.ItemRemoved += new ObservableList<string>.ItemRemovedEventHandler(ListTests_ItemRemoved);
	}
	
	void Start()
	{
		ListTest.Add ("up");
		ListTest.Add ("down");
		bStarted = true;
		started = DateTime.Now;
	}
	
	void Update()
	{
		if(bStarted)
		{
			if(!bAdded)
			{
				
				TimeSpan ts = DateTime.Now -  started;
				if(ts.Seconds > 25)
				{
					ListTest.Add ("left");
					ListTest.Add ("right");
					bAdded = true;					
				}			
			}				
		}
		
	}
	
	void ListTests_ListChanged(object sender, ObservableList<string>.ListChangedEventArgs e)
    {
        Debug.Log("ListChanged()");
    }
	
	void ListTests_ItemAdded(object sender, ObservableList<string>.ListChangedEventArgs e)
    {
        Debug.Log("ItemAdded()");
    }
	
	void ListTests_ItemRemoved(object sender, ObservableList<string>.ListChangedEventArgs e)
    {
        Debug.Log("ItemRemoved()");
    }
}

That page you linked is the same one I checked but BindingList shows up as green in .NET 2.0 for me. How odd.