Example #1
0
 private void Drag(KZTouch t, Camera cam)
 {
     Vector3 current = ScreenToWorld(t.position, cam);
     Vector3 mov = GetMovement(current);
     //Debug.Log("move:" + mov +", current: "+current+", last: "+last);
     transform.position += mov;
     last=current;
 }
Example #2
0
 public KZTouchEvent(KZTouch t, GameObject f, GameObject l, GameObject c, Camera cam, RaycastHit h)
 {
     touch=t;
     first=f;
     current=c;
     last=l;
     camera=cam;
     hit=h;
 }
Example #3
0
 //should be called prior to GetTouches()
 public static void UpdateTouches()
 {
     if(!enabled) return;
     if(Input.touchCount>0) {
         //touches.Length means number of fingers on the screen
         touches=new KZTouch[Input.touchCount];
         for(int i=0; i<touches.Length; i++) {
             touches[i]=new KZTouch(Input.GetTouch(i));
         }
     } else {
         if(enableTouchSimulationWithMouse){
             touches = sim.GetSimulatedTouches();
         } else {
             touches = new KZTouch[0];
         }
     }
 }
Example #4
0
    //should be called prior to GetTouches()
    public static void UpdateTouches()
    {
        if(!enabled) return;

        if (Input.touchCount <= 0)
        {
            UpdateMouseTouches();
        }

        touches = new KZTouch[Input.touchCount + extraTouches.Count];

        int index = 0;

        for (; index < Input.touchCount; index++)
        {
            touches[index] = new KZTouch(Input.GetTouch(index));
        }

        for (int i = 0; i < extraTouches.Count; i++)
        {
            touches[index++] = extraTouches[i];
        }
        extraTouches.Clear();
    }
Example #5
0
        public List<KZTouch> GetSimulatedTouches()
        {
            Vector2 currentMousePosition=Input.mousePosition;
            Vector2 deltaPosition=currentMousePosition-lastMousePosition;
            float currentTime=Time.realtimeSinceStartup; //?
            float deltaTime=currentTime-lastTime;
            bool mouseMoved=(deltaPosition!=Vector2.zero)?true:false;
            List<KZTouch> touches=new List<KZTouch>();

            for(int i=0; i<wasMouseButtonDown.Length; i++) {
                KZTouch touch=null;
                if(Input.GetMouseButton(i)) {
                    if( ! wasMouseButtonDown[i]) {
                        //mouse button was up but is down -> button pressed
                        touch=new KZTouch(
                            i + firstId, currentMousePosition, deltaPosition,
                            deltaTime, 0, TouchPhase.Began);
                        wasMouseButtonDown[i]=true;
                    } else {
                        //mouse button was down and is down -> button still pressed
                        if(mouseMoved) {
                            touch=new KZTouch(
                                i + firstId, currentMousePosition, deltaPosition,
                                deltaTime, 0, TouchPhase.Moved);
                        } else {
                            touch=new KZTouch(
                                i + firstId, currentMousePosition, deltaPosition,
                                deltaTime, 0, TouchPhase.Stationary);
                        }
                    }
                    touches.Add (touch);
                } else {
                    if(wasMouseButtonDown[i]) {
                        //mouse button was down but is up -> button released
                        touch=new KZTouch(
                            i + firstId, currentMousePosition, deltaPosition,
                            deltaTime, 0, TouchPhase.Ended);
                        touches.Add (touch);
                        wasMouseButtonDown[i]=false;
                    } else {
                        //mouse button was up and is still up -> nothing interesting here
                    }
                }
            }

            lastMousePosition=currentMousePosition;
            lastTime=currentTime;
            return touches;
        }
Example #6
0
 public static void GenerateTouch(KZTouch touch)
 {
     extraTouches.Add(touch);
 }
Example #7
0
 private void Drag(KZTouch t, Camera cam)
 {
     Vector3 current = ScreenToWorld(t.position, cam);
     transform.position =
         new Vector3(current.x, current.y, transform.position.z);
 }