The development of the Unity game on Android, and the same on iOS, but there are many subtle differences, this may be due to the system or hardware problems caused by the difference it, more typical is-touch screen to achieve the difference between double-click.
Unity3d Official API documentation tells us one thing, http://docs.unity3d.com/Manual/MobileInput.html,
You see, he says, iOS devices can use Tapcontrol to determine whether a double-click is generated, but the Android device does not have this feature. Regardless, see here we know, in order to judge the double-click event, but also rely on their own manual code implementation. In fact, imitate the Windows mouse double-click Mechanism, we can fully use the existing API to identify the double-click, such as after clicking, do not click the operation, but double-click monitoring, Monitor for 0.1 seconds if a new touch finger touches the screen, if there is, the whole time is considered to be a double-click, and ignore the previous clicks, if 0.1 seconds past, no new response, we continue to process 0.1 seconds before the click Time, remember to double-click monitoring before the original frame of the data saved, otherwise, 0.1 seconds later, When you deal with the Click event, it's changed.
Nonsense not much to say directly on the core code map
if(Touchcount = = 0)//fingers not pressing the screen or releasing{resetcontrolstate (); if(typeofoperation = = E_operationtype.waitfordoubletouch)//within 0.1 seconds of waiting for the double-click state, and no finger pressed, it was thought that the just click{Timeintervaloftouch= Time.time-Fisrttouchleavetime; if(Timeintervaloftouch >0.1) {typeofoperation=E_operationtype.nocommand; Stateofmoving= e_movingstate.continuous;//Start continuous Walk modeSwitchflag =1; Moving=true; }} totalcount=0; } Else { if(Input.gettouch (0). Phase = = Touchphase.stationary)//hold it down, it's not counted.TotalCount + = Touchcount;//If you keep holding the hold, then accumulate, according to experience, 1 seconds can accumulate 50 times varIint; varTouch:touch; varThesetouches =input.touches; varTouch0:touch; varTouch1:touch; varGotTouch0 =false; varGotTouch1 =false; //Check If we got the first finger down if(state = = E_controlstate.waitingforfirsttouch)//the moment the finger presses { for(i = 0; i < Touchcount; i++) {Touch=thesetouches[i]; if(Touch.phase! =touchphase.ended&& Touch.phase! =touchphase.canceled) { state=E_controlstate.handlefirsttouch; Firsttouchtime=Time.time; fingerdown[0] =Touch.fingerid; fingerdownposition[0] =touch.position; fingerdownframe[0] =Time.framecount; Break; } } } //Wait to see if a second finger touches down. Otherwise, we 'll //register this as a character move if(state = = E_controlstate.handlefirsttouch)//You 've been in this state since you pressed your finger. { for(i = 0; i < Touchcount; i++) {Touch=thesetouches[i]; if(Touch.phase! =touchphase.canceled) {if(Touchcount = = 1)//is still a finger { //var deltasincedown = touch.position-fingerdownposition[0]; //either the finger is held down long enough to count //as a move or it is lifted, which is also a move. if(Touch.fingerid = = fingerdown[0 ] ) { if(Touch.phase = = touchphase.ended)//the moment the finger leaves starts { if(Maxmovecount >5) {typeofoperation= E_operationtype.slidingtouch;//swipe touch to clickState =E_controlstate.waitingforfirsttouch; Maxmovecount=0; } Else{Timeoffingerstay=time.time-firsttouchtime;//calculate the time the finger stays if(Timeoffingerstay > Doubletouchtimelimit)//finger dwell time is greater than double click time limit Count once { if(Typeofoperation! =e_operationtype.singletouched) typeofoperation=e_operationtype.singletouched; State=E_controlstate.movingcharacter; } Else{//finger dwell time is less than double-click, it is considered possible to double-click, at this time to detect whether there is a number of times a finger press, no finger press, click to handle if(typeofoperation!=e_operationtype.waitfordoubletouch && typeofoperation! =e_operationtype.doubletouched) {typeofoperation=E_operationtype.waitfordoubletouch; Fisrttouchleavetime= Time.time;//Note the time that your finger left to calculate the time interval for the next time you pressState =E_controlstate.waitingforfirsttouch; } } } //responding based on statusOnsingletouchend (); } if(touch.phase ==touchphase.began && typeofoperation = =E_operationtype.waitfordoubletouch) {Timeintervaloftouch= Time.time-fisrttouchleavetime;//The interval between two touch is calculated, and the interval is less than 0.2 seconds, which is considered double-click if(Timeintervaloftouch < 0.2) Typeofoperation=e_operationtype.doubletouched; State=E_controlstate.waitingforfirsttouch; } if(Touch.phase = =touchphase.moved) {Maxmovecount+=1; } if(Touch.phase = =touchphase.stationary) {Timeoffingerstay=time.time-firsttouchtime;//calculate the time the finger stays if(Timeoffingerstay >0.3 && (stateofmoving = = e_movingstate.continuous))//if the finger stays for 0.3 seconds and is in a continuous walking state, it is immediately stationary{stateofmoving=E_movingstate.suddenlystop; Moving=false; } } Break; } } } } } }View Code
After the double-click, let's say that the sliding processing, in fact, the sliding processing is very good to handle, is to read touch.phase just, but, to know that the user's operation is a certain noise, such as some jitter, the underlying physical layer to help us deal with the micro-vibration noise and thermal noise, and our upper application developers need to deal with, that is, people operating noise, for example, I hold the time, hand shake, it is slippery Move or hold the action? Perhaps you think this is an obscure detail, but the user experience demands more and more high now, the details of the operation actually decided the success or failure of a game, your fault tolerance is better, the details are handled very well, then the game is done, the player will be more comfortable to play. If you think the user is going to adapt to your application, I think it's time to wait till your platform is big enough.
Unity3d Android Development Touch Operation identification-double click, swipe to remove noise processing