I have this code:
[System.Serializable]
public class ExclusiveList<T> : List<T>
{
public int this[T item]
{
get
{
for(int i = 0; i < Count; i++)
{
if(this[i].Equals(item))
{
return i;
}
}
return -1;
}
}
new public void Add(T item)
{
if (!Contains(item))
{
base.Add(item);
}
}
}
[CustomPropertyDrawer(typeof(ExclusiveList<>),true)]
public class ExclusiveListPropertyDrawer<T> : PropertyDrawer where T:Object
{
private int length;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position,label,property);
ExclusiveList<T> xList = property.FindPropertyRelative("this") as ExclusiveList<T>;
length = EditorGUI.IntField(position,length);
for (int i = 0; i < xList.Count; i++)
{
if(xList[xList[i]] != -1)
{
xList.RemoveAt(i);
i--;
}
xList[i] = (T)EditorGUI.ObjectField(position,xList[i],typeof(T),true);
}
EditorGUI.EndProperty();
}
}
But it does not work.How can I solve this ? Thanks in advance!