public TouchPoint(Vector2 pos, int id){
		position = pos;
		ID = id;
		touchRay = Camera.main.ScreenPointToRay(position);
		gesture = EventBase.Type.Null;
		timeStamp = (long)Time.time;
	}
	public TouchPoint(Vector2 pos, int id){
		position = pos;
		ID = id;
		touchRay = Camera.main.ScreenPointToRay(position);
		gesture = EventBase.Type.Null;
		timeStamp = (long)Time.time;
	}
Exemple #3
0
    public void OnTouch(TouchPoint touch)
    {
        int fingerID = touch.GetID();

        EventBase.Type gesture  = touch.GetGesture();
        Ray            touchRay = touch.GetRay();

        // Check if the ray from the main camera touch intersects with a collider or rigidbody
        // and determine if the ray intersects this object
        RaycastHit rayCast;

        if (Physics.Raycast(touchRay.origin, touchRay.direction, out rayCast) && rayCast.transform.gameObject == gameObject)
        {
            isTouched = true;
        }
        else
        {
            isTouched = false;
        }

        switch (gesture)
        {
        case (EventBase.Type.Down):
            // Add finger to list
            if (isTouched)
            {
                if (touchlist.Contains(fingerID))
                {
                    Debug.Log("Warning: Touch down detected for existing touch - should not happen");
                }
                touchlist[fingerID] = touch;
                OnTouchDown(touch);
            }
            break;

        case (EventBase.Type.Move):
            if (isTouched)
            {
                touchlist[fingerID] = touch;
                OnTouchMove(touch);
            }
            else if (touchlist.Contains(fingerID))
            {
                touchlist.Remove(fingerID);
                OnTouchUp(touch);
            }
            break;

        case (EventBase.Type.Up):
            if (touchlist.Contains(fingerID))
            {
                touchlist.Remove(fingerID);
                OnTouchUp(touch);
            }
            isTouched = false;
            break;
        }
    }
Exemple #4
0
    public TouchPoint(Vector2 pos, int id){
		position = pos;
		ID = id;
		touchRay = Camera.main.ScreenPointToRay(position);
		gesture = EventBase.Type.Null;
		timeStamp = (long)Time.time;

        pointerEvent = new PointerEventData(EventSystem.current);
        pointerEvent.pointerId = ID;
    }
Exemple #5
0
    public TouchPoint(EventData e)
    {
        position = new Vector3(e.posx, e.posy, e.posz);
        ID = (int)e.sourceId;
        touchRay = Camera.main.ScreenPointToRay(position);
        gesture = (EventBase.Type)e.type;
        timeStamp = (long)Time.time;

        pointerEvent = new PointerEventData(EventSystem.current);
        pointerEvent.pointerId = ID;
    }
Exemple #6
0
    public void Update(Vector2 newPosition, EventBase.Type gesture)
    {
        position = newPosition;
        pointerEvent.position = newPosition;

        // Raycast into the Unity Event system
        List<RaycastResult> raycastResults = new List<RaycastResult>();
        EventSystem.current.RaycastAll(pointerEvent, raycastResults);

        if (gesture == EventBase.Type.Down)
        {
            if (raycastResults.Count > 0)
            {
                objectTouched = raycastResults[raycastResults.Count - 1].gameObject;
                Debug.Log(objectTouched);
            }

            pointerEvent.Reset();
            pointerEvent.pointerId = ID;
            pointerEvent.delta = Vector2.zero;
            pointerEvent.position = position;

            ExecuteEvents.ExecuteHierarchy(objectTouched, pointerEvent, ExecuteEvents.pointerDownHandler);
            ExecuteEvents.ExecuteHierarchy(objectTouched, pointerEvent, ExecuteEvents.pointerClickHandler);
            ExecuteEvents.ExecuteHierarchy(objectTouched, pointerEvent, ExecuteEvents.pointerEnterHandler);

            ExecuteEvents.Execute(objectTouched, pointerEvent, ExecuteEvents.beginDragHandler);
            pointerEvent.pointerDrag = objectTouched;
        }
        else if (gesture == EventBase.Type.Move)
        {
            // If pointer has pressed on object, apply drag on all objects hit (initial hit or saved object may not be slider, so hit everything)
            // We prevent further unnecessary processing by only checking while there's an active object that was pressed
            if (pointerEvent.pointerDrag != null)
            { 
                foreach (RaycastResult result in raycastResults)
                {
                    ExecuteEvents.ExecuteHierarchy(result.gameObject, pointerEvent, ExecuteEvents.dragHandler);
                }
            }
        }
        else if (gesture == EventBase.Type.Up)
        {
            ExecuteEvents.ExecuteHierarchy(objectTouched, pointerEvent, ExecuteEvents.dropHandler);
            ExecuteEvents.Execute(objectTouched, pointerEvent, ExecuteEvents.pointerUpHandler);
            ExecuteEvents.ExecuteHierarchy(objectTouched, pointerEvent, ExecuteEvents.pointerExitHandler);

            ExecuteEvents.Execute(objectTouched, pointerEvent, ExecuteEvents.endDragHandler);
            pointerEvent.pointerDrag = null;
        }
    }
Exemple #7
0
    public void SetGesture(EventBase.Type value){
		 gesture = value;
	}
 public void SetGesture(EventBase.Type value)
 {
     gesture = value;
 }
Exemple #9
0
    public override void OnEvent(EventData e)
    {
        if (e.serviceType == EventBase.ServiceType.ServiceTypePointer)
        {
            int             id        = (int)e.sourceId;
            Vector2         pos       = new Vector2(e.posx, e.posy);
            EventBase.Type  eventType = (EventBase.Type)e.type;
            EventBase.Flags flags     = (EventBase.Flags)e.flags;

            pos = TouchPosToScreenPos(pos);

            int touchListSize = (int)e.getExtraDataFloat(4);

            if (eventType == EventBase.Type.Down)
            {
                AddTouchpoint(pos, id);
            }
            else if (eventType == EventBase.Type.Move)
            {
                if (touchPoints.ContainsKey(id))
                {
                    TouchPoint tp          = (TouchPoint)touchPoints[id];
                    GameObject touchObject = ((TouchPoint)touchPoints[id]).GetGameObject();

                    string text = id.ToString();

                    touchObject.GetComponentInChildren <UnityEngine.UI.Text>().text = text;
                    touchObject.transform.localPosition = pos;

                    for (int i = 0; i < touchListSize; i++)
                    {
                        int     sub_id  = (int)e.getExtraDataFloat(5 + i * 3);
                        Vector2 sub_pos = new Vector2(e.getExtraDataFloat(6 + i * 3), e.getExtraDataFloat(7 + i * 3));
                        sub_pos = TouchPosToScreenPos(sub_pos);
                        if (touchPoints.ContainsKey(sub_id))
                        {
                            TouchPoint sub_tp          = (TouchPoint)touchPoints[sub_id];
                            GameObject sub_touchObject = ((TouchPoint)touchPoints[sub_id]).GetGameObject();

                            string sub_text = sub_id.ToString();
                            sub_text += " (" + sub_tp.GetRootID() + ")";

                            sub_touchObject.GetComponentInChildren <UnityEngine.UI.Text>().text = sub_text;
                            sub_touchObject.transform.localPosition = sub_pos;
                        }
                        else
                        {
                            AddTouchpoint(sub_pos, sub_id, id);
                        }
                    }
                }
            }
            else if (eventType == EventBase.Type.Up)
            {
                Debug.Log("Up event for ID: " + id);
                Debug.Log(touchPoints.ContainsKey(id));
                if (touchPoints.ContainsKey(id))
                {
                    GameObject touchObject = ((TouchPoint)touchPoints[id]).GetGameObject();
                    Destroy(touchObject);
                    touchPoints.Remove(id);

                    for (int i = 0; i < touchListSize; i++)
                    {
                        int sub_id = (int)e.getExtraDataFloat(5 + i * 3);
                        if (touchPoints.ContainsKey(sub_id))
                        {
                            GameObject sub_touchObject = ((TouchPoint)touchPoints[sub_id]).GetGameObject();
                            Destroy(sub_touchObject);
                            touchPoints.Remove(sub_id);
                        }
                    }
                }
            }
        }
    }