Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in RemoveAt function #1

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3f7d7ae
make UnityDictionary implement System.Collections.Generic.IDictionary
richard-fine Sep 13, 2013
dc4d93b
initial basic implementation of UnityDictionaryDrawer - just display/…
richard-fine Sep 13, 2013
ce7015b
non-explicit indexer for UnityDictionary
richard-fine Sep 13, 2013
7953790
commented UnityDictionary<TKey, TValue>.RemoveAt to clarify what's go…
richard-fine Sep 13, 2013
a4a925c
tabs to spaces
richard-fine Sep 13, 2013
7f38b67
couple more tabs to spaces...
richard-fine Sep 13, 2013
6d44fde
and a few more tabs.
richard-fine Sep 13, 2013
b766f1e
remove UnityEditor usage as editor code is in a separate file now
richard-fine Sep 13, 2013
d4eccf2
add comment about order of operations in Add because it's non-obvious
richard-fine Sep 13, 2013
7c718d5
fix off-by-one error in enumerator object
richard-fine Sep 13, 2013
f6b9aa6
implement older, non-generic interfaces
richard-fine Sep 13, 2013
b5140a4
removed entries weren't being taken out of the cache correctly
richard-fine Sep 13, 2013
b8efb4c
better handling of non-generic usage when key or value objects provid…
richard-fine Sep 13, 2013
1571740
allow CopyTo to emit into an array of object
richard-fine Sep 13, 2013
afeb7fb
version the dictionary, so that enumerators throw exceptions if the d…
richard-fine Sep 13, 2013
a341e27
better handling of nongeneric nulls when the type is supposed to be a…
richard-fine Sep 13, 2013
0800914
enumerator wrapper for old IDictionary clients that provides Dictiona…
richard-fine Sep 13, 2013
71b5678
start over with the PropertyDrawer - basic foldout for now
richard-fine Sep 15, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Editor/UnityDictionaryDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using UnityEditor;
using UnityEngine;

public class UnityDictionaryDrawer<TKey, TValue> : PropertyDrawer
{
override public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var propTitle = EditorGUI.BeginProperty(position, label, property);

// PropertyDrawers don't support GUILayout so we have to construct our own rectangles
var foldoutRect = new Rect(position.left, position.top, position.width, base.GetPropertyHeight(property, label));
bool wasExpanded = property.isExpanded;
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, propTitle);

// Don't use the latest isExpanded value because if it's changed then we're the wrong height
if(wasExpanded)
{

}

EditorGUI.EndProperty();
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var total = base.GetPropertyHeight(property, label);
if(property.isExpanded)
{
total += base.GetPropertyHeight(property, label) * property.FindPropertyRelative("_keys").arraySize;
}

return total;
}
}

//TODO: figure out how to make it so you dont need to have one per dummy subclass.

[CustomPropertyDrawer(typeof(UnityDictionaryIntString))]
public class UnityDictionaryDrawerIntString : UnityDictionaryDrawer<int, string>
{

}
81 changes: 81 additions & 0 deletions ReadOnlyListWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections;
using System.Collections.Generic;

internal class ReadOnlyListWrapper<T> : ICollection<T>, ICollection
{
private readonly List<T> _wrappedList;

public ReadOnlyListWrapper(List<T> listToWrap)
{
_wrappedList = listToWrap;
}

#region Implementation of IEnumerable

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

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

#endregion

#region Implementation of ICollection<T>

public void Add(T item)
{
throw new NotSupportedException("The list is read-only.");
}

public void Clear()
{
throw new NotSupportedException("The list is read-only.");
}

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

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

public bool Remove(T item)
{
throw new NotSupportedException("The list is read-only.");
}

public void CopyTo(Array array, int index)
{
((ICollection)_wrappedList).CopyTo(array, index);
}

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

public object SyncRoot
{
get { return ((ICollection) _wrappedList).SyncRoot; }
}

public bool IsSynchronized
{
get { return ((ICollection) _wrappedList).IsSynchronized; }
}

public bool IsReadOnly
{
get { return true; }
}

#endregion
}
Loading