示例#1
0
 /// <summary>
 /// Identifies a touch cluster which contains a given touch ID
 /// </summary>
 /// <param name="touchId"></param>
 /// <param name="cluster"></param>
 /// <returns></returns>
 public bool GetTouchClusterForTouchId(int touchId, TouchCluster cluster)
 {
     for (int i = 0; i < _touchTracker.SpanningTreeCount; i++)
     {
         SpanningTree tree = _touchTracker.GetSpanningTree(i);
         if (tree.ContainsTouchId(touchId))
         {
             return(tree.GetTouchCluster(cluster));
         }
     }
     cluster.Clear();
     return(false);
 }
示例#2
0
        // New implementation of PointerInputModule.GetTouchPointerEventData()
        // which takes a TouchPt instead of Touch
        protected MultiTouchPointerEventData GetTouchPointerEventData(TouchPt touch, TouchCluster cluster, out bool pressed, out bool released)
        {
            MultiTouchPointerEventData pointerData;
            var created = GetMultiTouchPointerData(cluster.ClusterId, out pointerData, true);

            pointerData.Reset();

            pressed  = created || (touch.phase == TouchPhase.Began);
            released = (touch.phase == TouchPhase.Canceled) || (touch.phase == TouchPhase.Ended);

            if (created)
            {
                // position information needs to be set first when
                // EventData has just been created
                pointerData.position         = touch.position;
                pointerData.centroidPosition = cluster.Centroid;
                pointerData.touchCluster.CopyFrom(cluster);
            }
            if (pressed)
            {
                pointerData.delta = Vector2.zero;
                pointerData.centroidPressPosition = cluster.Centroid;
                pointerData.centroidDelta         = Vector2.zero;
            }
            else
            {
                pointerData.delta         = touch.position - pointerData.position;
                pointerData.centroidDelta = cluster.Centroid - pointerData.centroidPosition;
            }

            if (!created)
            {
                // position information needs to be set here after deltas
                // are computed when not first created. (time optimization since cluster copy can take time)
                pointerData.position         = touch.position;
                pointerData.centroidPosition = cluster.Centroid;
                pointerData.touchCluster.CopyFrom(cluster);
            }

            pointerData.button = PointerEventData.InputButton.Left;

            eventSystem.RaycastAll(pointerData, m_RaycastResultCache);

            RaycastResult raycast;

            while (true)
            {
                raycast = FindFirstRaycast(m_RaycastResultCache);
                var raycastProxy = raycast.gameObject != null?raycast.gameObject.GetComponent <RaycasterProxy>() : null;

                if (raycastProxy == null || !raycastProxy.IsProxyActive)
                {
                    break;      // found a result that is not an active proxy
                }
                // The proxy is the primary item. Therefore, discard the results to this point and raycast within the
                // proxied camera
                m_RaycastResultCache.Clear();
                //raycastProxy.RcTransform.SetAsLastSibling();
                raycastProxy.ProxyRaycaster.Raycast(pointerData, m_RaycastResultCache);
            }

            pointerData.pointerCurrentRaycast = raycast;

            m_RaycastResultCache.Clear();
            return(pointerData);
        }
示例#3
0
        private bool ProcessTouch(TouchPt touch, TouchCluster cluster)
        {
            bool released;
            bool pressed;
            var  pointer = GetTouchPointerEventData(touch, cluster, out pressed, out released);

            if (pointer.rawPointerPress != null && _usedTargets.Contains(pointer.rawPointerPress))
            {
                return(false);       // Don't send to same object another touch has been sent to
            }
            int oldContext = SetSelectedObjectContext(cluster.ClusterId, false);

            bool processed         = false;
            bool allowNormalEvents = true;

            if (ProcessMultiTouchPress(pointer, pressed, released) || AlwaysProcessGestures)
            {
                // Only do multitouch gesture processing if there is a target found for them
                foreach (IMultiTouchGestureModule module in _multitouchModules)
                {
                    MultiTouchProcessResult result = module.Process(pointer, this);
                    processed |= result != MultiTouchProcessResult.NotProcessed;

                    if (result == MultiTouchProcessResult.Exclusive)
                    {
                        allowNormalEvents = false;
                        break;
                    }
                    if (result == MultiTouchProcessResult.NonExclusiveBlockNormalEvents)
                    {
                        allowNormalEvents = false;
                    }
                }
            }

            if (pointer.singleTouchProcessingEnabled)
            {
                if (allowNormalEvents)
                {
                    ProcessTouchPress(pointer, pressed, released);
                    // May have sent the following events on Pressed:
                    // for these comments, "go" is pointer.pointerCurrentRaycast.gameObject
                    // IPointerEnter/Exit (all up and down the hierarchy, all "entered" objects held in pointer.hovered
                    //   pointer.pointerEnter = go
                    // IPointerDownHandler (to first handler)
                    //   pointer.pointerPress = handler game object OR IPointerClickHandler game object
                    // pointer.rawPointerPress = go
                    // IInitializePotentialDragHandler if IDragHandler is found
                    //   pointer.pointerDrag = Drag Handler

                    if (!released)
                    {
                        ProcessMove(pointer);
                        ProcessDrag(pointer);
                        processed = true;
                    }
                }
                else if (!pressed)
                {
                    CancelSingleTouchProcessing(pointer);
                }
            }

            if (processed)
            {
                _usedTargets.Add(pointer.rawPointerPress);
            }

            if (released)
            {
                RemovePointerData(pointer);
                if (_multiselectEventSystem != null)
                {
                    _multiselectEventSystem.RemoveSelectedObjectContext(touch.fingerId);
                }
            }

            SetSelectedObjectContext(oldContext, !processed);
            return(processed);
        }