android - how to create dynamic sidebar ( menu ) for unity app -
i want create sidebar (like nav drawer in android) ar unity app, when touch left border of screen , drag right, sidebar should appear list of buttons such (settings, us..).
just quick whipped up. should started.
using unityengine; using system.collections; using unityengine.ui; public class slidepanel : monobehaviour { //process touch panel display on if touch less threshold. private float leftedge = screen.width * 0.25f; //minimum swipe distance showing/hiding panel. float swipedistance = 10f; float startxpos; bool processtouch = false; bool isexpanded = false; public animation panelanimation; void update(){ if(input.touches.length>0) panel(input.gettouch(0)); } void panel (touch touch) { switch (touch.phase) { case touchphase.began: //get start position of touch. startxpos = touch.position.x; debug.log(startxpos); //check if need process touch showing panel. if (startxpos < leftedge) { processtouch = true; } break; case touchphase.ended: if (processtouch) { //determine how far finger swiped. float deltax = touch.position.x - startxpos; if(isexpanded && deltax < (-swipedistance)) { panelanimation.crossfade("slideout"); isexpanded = false; } else if(!isexpanded && deltax > swipedistance) { panelanimation.crossfade("slidein"); isexpanded = true; } startxpos = 0f; processtouch = false; } break; default: return; } } }
Comments
Post a Comment