- Home /
Other
Does Unity3d Have an Existing Binary Search Class For KeyValuePairs
Hello
In my Unity3d application, I need to detect a polyline that has been selected by a user. The easy way to determine this is to add a collider component to each GameObject (polyline) then I'll know whenever the user clicks a polyline. But this is incredibly inefficient because I will have thousands of polylines.
So my more efficient method is to store each polylines distance from the point (0,0,0) in a List >. This list will be ordered from lowest distance to highest. When the user selects a point in the game, I will determine this points' distance (D) from (0,0,0) then use a 'Upper Bounds' Binary Search
to find the polyline closest to this point (ie, with a similar distance to (0,0,0)).
My Question: Before I go and reinvent the wheel and code my own 'Upper Bounds' Binary Search algorithm, element sorting and etc, is there a Unity3d/C#.NET class for Upper Bounds Binary Search that will sort and search for me?
I am aware of the method List(T).BinarySearch()
but is it up to me to ensure that the List
is sorted correctly? If my list isn't sorted, and the method needs to sort the list each method call then that could be rather inefficient.
It would be helpful if you read the documentation before asking questions.
This seems like a purely C# (or really, general algorithm) question.
In general, special Unity builtins are only things you need, which interact with unity-specific objects, doing the least amount of work to return a C# data structure. Or else are standard convenience funcs.
But, I wonder if you can't just get the same thing with raycasting onto a single flat collider, converting the distance into the bucket#?
Follow this Question
Related Questions
Tone down physics/collisions 2 Answers
Pixel Perfect Collision Possible? 3 Answers
Activate a GUI Text on Collision? 3 Answers
Objects 'Clumping' problem 1 Answer
Collisions layer is not appearing. 1 Answer