Exemple #1
0
 void TouchUp(ref ArTouch touch)
 {
     // If this is the tracked touch, release that reference
     if (trackedTouchId == touch.id)
     {
         trackedTouchId = ArTouch.NULL_ID;
     }
     ArDebug.Log("Touch " + touch.id + " up at " + touch.position + "!");
 }
Exemple #2
0
    // Draw some debug stuff

    /*void OnGUI()
     * {
     *      GUI.Label(new Rect(50,50, 100, 100),""+ ArTouchInput.GetInstance().GetNumTouches());
     *      if (trackedTouchId != ArTouch.NULL_ID)
     *      {
     *              // Magic numbers are bad, kids.  This is example code.
     *              // Also, the camera's screen space (and thus the touch's) has the origin in the bottom-left,
     *              // but the GUI has it in the top-left, so we've got to do a conversion on the y axis.
     *              GUI.Box(new Rect(drawPosition.x - 25, Screen.height - (drawPosition.y+25), 50, 50), "Butts!");
     *      }
     * }*/

    #region Touch Callbacks
    void TouchDown(ref ArTouch touch)
    {
        // We're not tracking any touches yet, so may as well track this one
        if (trackedTouchId == ArTouch.NULL_ID)
        {
            trackedTouchId = touch.id;
        }
        ArDebug.Log("Touch " + touch.id + " down at " + touch.position + "!");
    }
Exemple #3
0
 void TouchMove(ref ArTouch touch)
 {
     // If this is the tracked touch, update using it
     if (trackedTouchId == touch.id)
     {
         drawPosition = touch.position;
     }
     ArDebug.Log("Touch " + touch.id + " moving at " + touch.position + "!");
 }
Exemple #4
0
    /// <summary>
    /// Makes sure that ArTouchInput and Unity are tracking the
    /// same number of touches and have not got out of sync.
    /// </summary>
    /// <param name='correctTouchNum'>
    /// The correct number of touches ArTouchInput should be tracking.
    /// </param>
    private void CleanupTouches(int correctTouchNum)
    {
        // Make sure that our existing checks to add touches that we've
        // missed their addition touchPhase are working, and we have
        // at least as many touches as Unity is reporting
        ArDebug.Assert(_touches.Count >= correctTouchNum,
                       "We're holding fewer touches than Unity reports... How?");

        // Make sure that we haven't missed the release of the mouse and
        // held onto mouseTouch for too long
        ArDebug.Assert(!(_mouseTouch != null && !Input.GetMouseButton(LEFT_MOUSE)),
                       "We're holding mouseTouch while mouse is up... How?");

        // After processing, we might still be holding onto too many touches
        // if we missed Unity's reported removal touchPhase somehow
        // Remove those extra touches now
        if (_touches.Count > correctTouchNum)
        {
            // Create a list of all the touches to remove
            List <ArTouch> removeTouches = new List <ArTouch>(_touches.Count - correctTouchNum);

            // For each touch we're holding, see if it has a corresponding Unity touch.
            // If not, add it to the list of touches to remove
            foreach (ArTouch touch in _touches)
            {
                foreach (Touch uTouch in Input.touches)
                {
                    if (uTouch.fingerId == touch.id)
                    {
                        continue;
                    }
                }
                ArDebug.Assert(removeTouches.Count != removeTouches.Capacity,
                               "List of touches to remove filled too early... how?");
                removeTouches.Add(touch);
            }

            // Forcibly remove the touches queued for removal
            foreach (ArTouch removeTouch in removeTouches)
            {
                ProcessTouchUp(removeTouch.id, removeTouch.position);
            }

            ArDebug.Assert(_touches.Count == correctTouchNum,
                           "Cleanup did not match our touches to Unity's... why not?");
        }
    }
Exemple #5
0
    /// <summary>
    /// Process just-placed touches and call triggered
    /// event delegates as part of Update.
    /// </summary>
    /// <param name='id'>
    /// The id of the relevant touch
    /// </param>
    /// <param name='position'>
    /// The position of the relevant touch
    /// </param>
    private void ProcessTouchDown(int id, Vector2 position)
    {
        // Update instead of add if this touch has already been added
        ArTouch checkTouch = GetTouch(id);

        if (checkTouch != null)
        {
            ArDebug.LogWarning("Tried to add touch " + id + " multiple times.");
            ProcessTouchUpdate(id, position);
            return;
        }

        // If the mouse is already held down, force it out
        // of touches, because Unity's going to overwrite
        // its data with this new touch anyway
        ArTouch mouse = GetTouch(ArTouch.MOUSE_ID);

        if (mouse != null)
        {
            // NOTE: (jonagill) Don't pass through Input.mousePosition,
            // because the new touch has overwritten the mouse data
            ProcessTouchUp(ArTouch.MOUSE_ID, mouse.position);
        }

        // Create and store new ArTouch from the Unity touch
        ArTouch newTouch = new ArTouch(id, position);

        if (id == ArTouch.MOUSE_ID)
        {
            _mouseTouch = newTouch;
        }
        else
        {
            _touches.Add(newTouch);
        }

        // Call any assigned functions for TouchDown events
        if (OnTouchDown != null && !newTouch.isDead)
        {
            OnTouchDown(ref newTouch);
        }
    }
Exemple #6
0
 void TouchDrag(ref ArTouch touch)
 {
     ArDebug.Log("Touch " + touch.id + " dragging at " + touch.position + "!");
 }
Exemple #7
0
 void TouchPress(ref ArTouch touch)
 {
     ArDebug.Log("Touch " + touch.id + " pressing at " + touch.position + "!");
 }
Exemple #8
0
 void TouchFlick(ref ArTouch touch)
 {
     ArDebug.Log("Touch " + touch.id + " flicked at " + touch.position + "!");
 }
Exemple #9
0
 void TouchDoubleTap(ref ArTouch touch)
 {
     touch.isDead = true;
     ArDebug.Log("Touch " + touch.id + " double tapped at " + touch.position + "!");
 }
Exemple #10
0
 void TouchTap(ref ArTouch touch)
 {
     ArDebug.Log("Touch " + touch.id + " tapped at " + touch.position + "!");
 }