예제 #1
0
	private void pcFromTouchData(tTouchData data,out PcTouch touch, PcTouch oldTouch){
						touch=new PcTouch();
						touch.position.x=data.m_x/100;
						touch.position.y=data.m_y/100;
						touch.id=data.m_ID;
			
			if(oldTouch!=null){
						if(Mathf.Abs(data.m_x-oldTouch.position.x)>=c_minDeltaPosToMove || Mathf.Abs(data.m_y-oldTouch.position.y)>=c_minDeltaPosToMove){
							touch.phase=TouchPhase.Moved;
						}
						else{
							touch.phase=TouchPhase.Stationary;
						}
						touch.deltaPosition.x=touch.position.x-oldTouch.position.x;
						touch.deltaPosition.y=touch.position.y-oldTouch.position.y;
			}
			else{
				touch.deltaPosition.x=0;
				touch.deltaPosition.y=0;
				touch.phase=TouchPhase.Began;
			}
						
		}
예제 #2
0
	public void Update(){
		RECT winPos=new RECT();
		GetWindowRect(GetActiveWindow()  , out winPos);	
		int newTouchCount=GetTouchPointCount();
		if(newTouchCount>0){
				m_usingTouch=true;
				m_usingTouchTimer=Time.time;
			}
		else if((Input.GetMouseButtonDown(0)||Input.GetMouseButtonDown(1)||Input.GetMouseButtonDown(2)||Input.GetAxis("Mouse ScrollWheel")!=0)&&(Time.time-m_usingTouchTimer)>0.5f){//||Input.GetAxis("Mouse ScrollWheel")!=0){
				m_usingTouch=false;
				m_usingTouchTimer=Time.time;
			}
	
			
		tTouchData temp=new tTouchData();
		PcTouch[] newTouch;		
		int endedToAdd=0;	
		Hashtable oldIndexPos=new Hashtable();
		
		//On compte les touch qui étaient là a la dernière frame et ne le sont plus
		int tempCount=0;
			for(int i=0;i<m_touchCount;i++){
				if(m_touches[i].phase!=TouchPhase.Ended){
					tempCount++;
				}
			}
		
		//S'il y a moins de touch qu'avant (2touch => 1 touch)	
		if(newTouchCount<tempCount && newTouchCount!=0){		
			newTouch=new PcTouch[tempCount];
			//Pour chaque touch actuelle, on regarde l'ancienne touch la plus proche afin de lui en donner l'index
			for(int i=0;i<newTouchCount;i++){
					GetTouchPoint(i,temp);	
					temp.m_x=temp.m_x/100-(int)winPos.Left;
					temp.m_y=Screen.currentResolution.height-temp.m_y/100-((int)winPos.Bottom-Screen.height);
					//DbgUtils.Log ("testtouch","new touchPoint ("+temp.m_x+","+temp.m_y+")");
					Vector2 pos=new Vector2(temp.m_x,temp.m_y);
					float dist=300000;
					int index=-1;
					for(int j=0;j<m_touchCount;j++){
						if(m_touches[j].phase!=TouchPhase.Ended){
							float d=Vector2.Distance(pos,m_touches[j].position);
							if(d<dist){
								dist=d;
								index=j;
							}
						}
					}
					//Intitialisation nouvelle touch (position, delta, phase)
						newTouch[index]=new PcTouch();
						if(m_touches[index]==null){
							newTouch[index].phase=TouchPhase.Began;
							newTouch[index].deltaPosition.x=0;
							newTouch[index].deltaPosition.y=0;
						}
						else{
							if(Mathf.Abs(temp.m_x-m_touches[index].position.x)>=c_minDeltaPosToMove || Mathf.Abs(temp.m_y-m_touches[index].position.y)>=c_minDeltaPosToMove){
								newTouch[index].phase=TouchPhase.Moved;
							}
							else{
								newTouch[index].phase=TouchPhase.Stationary;
							}
							newTouch[index].deltaPosition.x=temp.m_x-m_touches[index].position.x;
							newTouch[index].deltaPosition.y=temp.m_y-m_touches[index].position.y;
						}
						newTouch[index].position.x=temp.m_x;
						newTouch[index].position.y=temp.m_y;
						newTouch[index].id=temp.m_ID;
					}
				
				
				//On met des touch avec la phase à Ended pour les touch qui ont disparu
				for(int i=0;i<tempCount;i++){
					if(newTouch[i]==null){
						newTouch[i]=m_touches[i];
						newTouch[i].deltaPosition=Vector2.zero;
						newTouch[i].phase=TouchPhase.Ended;
					}
					//DbgUtils.Log ("testtouch","touch "+i+" ("+newTouch[i].position.x+","+newTouch[i].position.y+") phase :"+newTouch[i].phase.ToString()+" delta :"+" ("+newTouch[i].deltaPosition.x+","+newTouch[i].deltaPosition.y+")");
				}
				endedToAdd= tempCount-newTouchCount;
				
		}
		else{
		//Sinon, simple initialisation des touch actuelles	
		newTouch=new PcTouch[newTouchCount];			
			
		for(int i=0;i<newTouchCount;i++){
			try{
				GetTouchPoint(i,temp);
					temp.m_x=temp.m_x/100-(int)winPos.Left;
					temp.m_y=Screen.currentResolution.height-temp.m_y/100-((int)winPos.Bottom-Screen.height);
				//File.WriteAllLines("log.txt",new string[]{"GetouchPoint done"});
					if(i>=m_touchCount){
						newTouch[i]=new PcTouch();
						newTouch[i].position=new Vector2(temp.m_x,temp.m_y);
						newTouch[i].phase=TouchPhase.Began;
						newTouch[i].deltaPosition=Vector2.zero;
						newTouch[i].id=temp.m_ID;
					}
					else{	
						PcTouch oldtouch=m_touches[i];
						if(m_touches[i]==null){
							m_touches[i]=new PcTouch();
						}
						int k=0;
						while(k<m_touchCount&& oldtouch.phase==TouchPhase.Ended){
								oldtouch=m_touches[k];
								k++;
							}
								
						newTouch[i]=new PcTouch();
						if(Mathf.Abs(temp.m_x-oldtouch.position.x)>=c_minDeltaPosToMove || Mathf.Abs(temp.m_y-oldtouch.position.y)>=c_minDeltaPosToMove){
							newTouch[i].phase=TouchPhase.Moved;
						}
						else{
							newTouch[i].phase=TouchPhase.Stationary;
						}
						newTouch[i].position.x=temp.m_x;
						newTouch[i].position.y=temp.m_y;
						newTouch[i].deltaPosition.x=newTouch[i].position.x-oldtouch.position.x;
						newTouch[i].deltaPosition.y=newTouch[i].position.y-oldtouch.position.y;
						newTouch[i].id=temp.m_ID;
					}
				}
				catch (Exception e ){
					DbgUtils.Log("testtouch","error :"+e.ToString());
				}
		}
	}

		m_touches=newTouch;
		m_touchCount=newTouchCount+endedToAdd;
		/*	
		  for (int i = 0; i < m_touchCount; i++)
            {
                PcTouch t = this.m_touches[i];
                DbgUtils.Log("testtouch","touch " + i + "(" + t.position.x + "," + t.position.y + ") phase=" + t.phase.ToString()+" delta :"+"(" + t.deltaPosition.x + "," + t.deltaPosition.y + ")");
            }	
          */

	}
예제 #3
0
        } // Zoom_n_dragV_n_rotate
    #endregion

    #endregion

    #region touch_Util
    private bool EndedOrCanceled(PcTouch t)
    {
       // DbgUtils.Log ("testtouch","EndedOrCancel :"+(t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled));
		return (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled);
    }
예제 #4
0
 public override PcTouch touches(int index)
 {
     PcTouch r=new PcTouch();
         r.position=Input.touches[index].position;
         r.phase=Input.touches[index].phase;
         r.deltaPosition=Input.touches[index].deltaPosition;
         return r;
 }