Example #1
0
    public FTouchManager()
    {
        Input.multiTouchEnabled = true;

        //this just makes sure mouse emulation is off on iOS and Android
        //this may eventually cause problems on devices that support both mouse and touch

                #if UNITY_ANDROID
        shouldMouseEmulateTouch = false;
                #endif

                #if UNITY_IPHONE
        shouldMouseEmulateTouch = false;
                #endif

                #if UNITY_EDITOR
        shouldMouseEmulateTouch = true;
                #endif

        _touchSlots = new FTouchSlot[SLOT_COUNT];

        for (int t = 0; t < SLOT_COUNT; t++)
        {
            _touchSlots[t] = new FTouchSlot(t);
        }
    }
Example #2
0
    public SlotList(float width, float height)
    {
        _width  = width;
        _height = height;

        touchableRect = new Rect(-_width / 2, -10000, _width - Config.SLOT_HEIGHT * 2 - Config.PADDING_XS * 2, 20000);//infinite height because thaat's how i doooo

        _scroller = new RXScroller(0, _minScrollY, _maxScrollY);

        _touchSlot = Futile.touchManager.GetTouchSlot(0);

        AddChild(slotContainer = new FContainer());

        List <Player> players = SKDataManager.GetPlayers();

        for (int p = 0; p < players.Count; p++)
        {
            AddSlotForPlayer(players[p], false);
        }

        Reorder(false, false);

        ListenForUpdate(HandleUpdate);

        _isInitializing = false;
    }
Example #3
0
    public SlotList(float width, float height)
    {
        _width = width;
        _height = height;

        touchableRect = new Rect(-_width/2,-10000,_width-Config.SLOT_HEIGHT*2-Config.PADDING_XS*2,20000);//infinite height because thaat's how i doooo

        _scroller = new RXScroller(0,_minScrollY,_maxScrollY);

        _touchSlot = Futile.touchManager.GetTouchSlot(0);

        AddChild(slotContainer = new FContainer());

        List<Player> players = SKDataManager.GetPlayers();

        for(int p = 0; p<players.Count; p++)
        {
            AddSlotForPlayer(players[p], false);
        }

        Reorder(false,false);

        ListenForUpdate(HandleUpdate);

        _isInitializing = false;
    }
    public void CleanUpEndedAndCanceledTouches()    //called by Futile in LateUpdate
    {
        //clean up the touches that have been canceled or ended
        for (int t = 0; t < SLOT_COUNT; t++)
        {
            FTouchSlot slot = _touchSlots[t];
            if (slot.doesHaveTouch)
            {
                if (slot.wasArtificiallyCanceled && slot.touchable != null)
                {
                    slot.touchable = null;
                }

                if (slot.touch.phase == TouchPhase.Moved)
                {
                    slot.didJustMove = false;
                }
                else if (slot.touch.phase == TouchPhase.Began)
                {
                    slot.didJustBegin = false;
                }
                else if (slot.touch.phase == TouchPhase.Ended)
                {
                    slot.doesHaveTouch = false;
                    slot.touchable     = null;
                    slot.didJustEnd    = false;
                }
                else if (slot.touch.phase == TouchPhase.Canceled)
                {
                    slot.doesHaveTouch = false;
                    slot.touchable     = null;
                    slot.didJustCancel = false;
                }
            }
        }
    }
Example #5
0
    public void Update()
    {
        if (!isEnabled)
        {
            return;
        }

        if (_needsPrioritySort)
        {
            UpdatePrioritySorting();
        }

        //create non-changeable temporary copies of the lists
        //this is so that there won't be problems if touchables are removed/added while being iterated through
        FMultiTouchableInterface[]    tempMultiTouchables    = _multiTouchables.ToArray();
        FCapturedTouchableInterface[] tempCapturedTouchables = _capturedTouchables.ToArray();

        float touchScale = 1.0f / Futile.displayScale;

        //the offsets account for the camera's 0,0 point (eg, center, bottom left, etc.)
        float offsetX = -Futile.screen.originX * Futile.screen.pixelWidth;
        float offsetY = -Futile.screen.originY * Futile.screen.pixelHeight;

        //Debug.Log ("Touch offset " + offsetX + " , " + offsetY);

        bool   wasMouseTouch = false;
        FTouch mouseTouch    = new FTouch();

        if (shouldMouseEmulateTouch)
        {
            mouseTouch.position = new Vector2((Input.mousePosition.x + offsetX) * touchScale, (Input.mousePosition.y + offsetY) * touchScale);

            mouseTouch.fingerId  = 0;
            mouseTouch.tapCount  = 1;
            mouseTouch.deltaTime = Time.deltaTime;

            if (Input.GetMouseButtonDown(0))
            {
                mouseTouch.deltaPosition = new Vector2(0, 0);
                _previousMousePosition   = mouseTouch.position;

                mouseTouch.phase = TouchPhase.Began;
                wasMouseTouch    = true;
            }
            else if (Input.GetMouseButtonUp(0))
            {
                mouseTouch.deltaPosition = new Vector2(mouseTouch.position.x - _previousMousePosition.x, mouseTouch.position.y - _previousMousePosition.y);
                _previousMousePosition   = mouseTouch.position;
                mouseTouch.phase         = TouchPhase.Ended;
                wasMouseTouch            = true;
            }
            else if (Input.GetMouseButton(0))
            {
                mouseTouch.deltaPosition = new Vector2(mouseTouch.position.x - _previousMousePosition.x, mouseTouch.position.y - _previousMousePosition.y);
                _previousMousePosition   = mouseTouch.position;

                mouseTouch.phase = TouchPhase.Moved;
                wasMouseTouch    = true;
            }
        }

        int touchCount = Input.touchCount;
        int offset     = 0;

        if (wasMouseTouch)
        {
            touchCount++;
        }

        FTouch[] touches = new FTouch[touchCount];

        if (wasMouseTouch)
        {
            touches[0] = mouseTouch;
            offset     = 1;
        }

        for (int i = 0; i < Input.touchCount; ++i)
        {
            Touch  sourceTouch = Input.GetTouch(i);
            FTouch resultTouch = new FTouch();

            resultTouch.deltaPosition = new Vector2(sourceTouch.deltaPosition.x * touchScale, sourceTouch.deltaPosition.y * touchScale);
            resultTouch.deltaTime     = sourceTouch.deltaTime;
            resultTouch.fingerId      = sourceTouch.fingerId + offset;
            resultTouch.phase         = sourceTouch.phase;
            resultTouch.position      = new Vector2((sourceTouch.position.x + offsetX) * touchScale, (sourceTouch.position.y + offsetY) * touchScale);
            resultTouch.tapCount      = sourceTouch.tapCount;

            touches[i + offset] = resultTouch;
        }

        int capturedTouchableCount = tempCapturedTouchables.Length;

        //reset the touch slotIndexes so that each slot can pick the touch it needs
        for (int t = 0; t < touchCount; t++)
        {
            FTouch touch = touches[t];
            touch.slot = null;
        }

        //match up slots that are currently active with the touches
        for (int s = 0; s < SLOT_COUNT; s++)
        {
            FTouchSlot slot = _touchSlots[s];

            if (slot.doesHaveTouch)
            {
                bool didFindMatchingTouch = false;

                for (int t = 0; t < touchCount; t++)
                {
                    FTouch touch = touches[t];
                    if (slot.touch.fingerId == touch.fingerId)
                    {
                        didFindMatchingTouch = true;
                        slot.touch           = touch;
                        touch.slot           = slot;
                        break;
                    }
                }

                if (!didFindMatchingTouch)
                {
                    slot.doesHaveTouch = false;
                    slot.touchable     = null;
                }
            }
        }

        //fill any blank slots with the unclaimed touches
        for (int s = 0; s < SLOT_COUNT; s++)
        {
            FTouchSlot slot = _touchSlots[s];

            if (!slot.doesHaveTouch)
            {
                for (int t = 0; t < touchCount; t++)
                {
                    FTouch touch = touches[t];
                    if (touch.slot == null)
                    {
                        slot.touch         = touch;
                        slot.doesHaveTouch = true;
                        touch.slot         = slot;
                        break;
                    }
                }
            }

            if (slot.doesHaveTouch)            //send the touch out to the slots that need it
            {
                if (slot.touch.phase == TouchPhase.Began)
                {
                    for (int c = 0; c < capturedTouchableCount; c++)
                    {
                        FCapturedTouchableInterface capturedTouchable = tempCapturedTouchables[c];

                        FSingleTouchableInterface singleTouchable = capturedTouchable as FSingleTouchableInterface;

                        //the first touchable to return true becomes the active one
                        if (slot.index == 0 && singleTouchable != null && singleTouchable.HandleSingleTouchBegan(slot.touch))
                        {
                            slot.isSingleTouchable = true;
                            slot.touchable         = capturedTouchable;
                            break;
                        }
                        else
                        {
                            FSmartTouchableInterface smartTouchable = capturedTouchable as FSmartTouchableInterface;
                            if (smartTouchable != null && smartTouchable.HandleSmartTouchBegan(slot.index, slot.touch))
                            {
                                slot.isSingleTouchable = false;
                                slot.touchable         = capturedTouchable;
                                break;
                            }
                        }
                    }
                }
                else if (slot.touch.phase == TouchPhase.Moved)
                {
                    if (slot.touchable != null)
                    {
                        if (slot.isSingleTouchable)
                        {
                            (slot.touchable as FSingleTouchableInterface).HandleSingleTouchMoved(slot.touch);
                        }
                        else
                        {
                            (slot.touchable as FSmartTouchableInterface).HandleSmartTouchMoved(slot.index, slot.touch);
                        }
                    }
                }
                else if (slot.touch.phase == TouchPhase.Ended)
                {
                    if (slot.touchable != null)
                    {
                        if (slot.isSingleTouchable)
                        {
                            (slot.touchable as FSingleTouchableInterface).HandleSingleTouchEnded(slot.touch);
                        }
                        else
                        {
                            (slot.touchable as FSmartTouchableInterface).HandleSmartTouchEnded(slot.index, slot.touch);
                        }
                    }

                    slot.touchable     = null;
                    slot.doesHaveTouch = false;
                }
                else if (slot.touch.phase == TouchPhase.Canceled)
                {
                    if (slot.touchable != null)
                    {
                        if (slot.isSingleTouchable)
                        {
                            (slot.touchable as FSingleTouchableInterface).HandleSingleTouchCanceled(slot.touch);
                        }
                        else
                        {
                            (slot.touchable as FSmartTouchableInterface).HandleSmartTouchCanceled(slot.index, slot.touch);
                        }
                    }

                    slot.touchable     = null;
                    slot.doesHaveTouch = false;
                }
            }
            else             //clear the slot here
            {
                slot.touchable     = null;
                slot.doesHaveTouch = false;
            }
        }

        if (touchCount > 0)
        {
            int multiTouchableCount = tempMultiTouchables.Length;
            for (int m = 0; m < multiTouchableCount; m++)
            {
                tempMultiTouchables[m].HandleMultiTouch(touches);
            }
        }
    }
	public FTouchManager ()
	{
		Input.multiTouchEnabled = true;
	
		//this just makes sure mouse emulation is off on iOS and Android
		//this may eventually cause problems on devices that support both mouse and touch
		
		#if UNITY_ANDROID
			shouldMouseEmulateTouch = false;
		#endif 
		
		#if UNITY_IPHONE
			shouldMouseEmulateTouch = false;
		#endif
		
		#if UNITY_EDITOR
			shouldMouseEmulateTouch = true;
		#endif

		_touchSlots = new FTouchSlot[SLOT_COUNT];

		for(int t = 0; t<SLOT_COUNT; t++)
		{
			_touchSlots[t] = new FTouchSlot(t);
		}
	}