unity3d - Using C# IComparer in Unity game engine -
unity3d - Using C# IComparer in Unity game engine -
i writing border class graph a* implementation. want later create list of edges , sort them based on border weights using icomparer interface.
below implementation of border class within unity 4.5f
using unityengine; using system.collections; public class border : icomparer { node destination; int weight; public edge(node destinationnode, int cost) { destination = destinationnode; weight = cost; } public node getdestination() { homecoming destination; } public int getcost() { homecoming weight; } int icomparer.compare(system.object a, system.object b) { if (((edge)a).getcost() == ((edge)b).getcost()) homecoming 0; else if (((edge)a).getcost() > ((edge)b).getcost()) homecoming 1; else homecoming -1; } }
but unity throws below error
argumentexception: not implement right interface system.collections.generic.comparer`1+defaultcomparer[edge].compare (.edge x, .edge y) (at /users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/system.collections.generic/comparer.cs:86)
i tried using icomparer<edge>
throws error
the non generic type 'system.collections.icomparer' cannot used type arguments
unity not allow me utilize icomparable not understand when seek utilize :( throws
" type or namespace not found "
i don't know whats wrong. please help me out?
i think unity expects implement icomparable<edge>
(generic version of icomparable, please see http://msdn.microsoft.com/fr-fr/library/4d7sx9hd%28v=vs.110%29.aspx )
this implementation close yours, except doesn't need casts (since input types edge)
c# unity3d
Comments
Post a Comment