- Home /
How do you spawn objects from UI ScrollView via drag?
I've been trying to implement this for a while now but with no success.
I have a ScrollView which contains a vertical 1 column GridLayout. Inside the layout is a number of panels that represent spawnable objects.
I need to be able to drag these objects from the ScrollView and into the scene to spawn them.
The Best I can do so far is to drag object into scene using IDragHandler interface, but this overrides the the OnDrag for the scroll view making the scroll view useless.
I'm trying to make this for android/touch devices.
Any suggestions would be a big help. Thank you in advance.
Here is a suggestion but to be honest I'm not sure it would work. Your code needs to capture the drag event so that you can decide if you need to spawn something. Your attempt where you used the IDragHandler sounds like a good start. Once your code deter$$anonymous$$es the player isn't trying to spawn something then send the event to the ScrollView so it can scroll the UI. But, you need something to differentiate a drag from a spawn. I am not familiar with the android/touch interface but perhaps two finger drag? I think that capturing the event and testing it to see if the player intends to spawn is one approach.
Thank you for commenting. I'm currently trying to figure out a way of doing just what you suggested.
I was thinking of having a delay before selecting item, then if the scroll view is scrolling cancel selection else instantiate and drag item. Or, as my list is vertical only, check the horizontal drag is past some threshold then instantiate.
Seems like this is something that not many people have done. I've searched everywhere but can't find a single example of this behavior.
Thank you again for helping!
Your answer
Follow this Question
Related Questions
Question on Tutorial: Panes, Panels, Windows 0 Answers
Instantiate problem with selected objects 0 Answers
Instanciate prefab responsively 1 Answer
OnDrag only called once? 1 Answer
how can i clone ui button ? 2 Answers