Ejemplo n.º 1
0
 void OnMouseDown()
 {
     TapArgs args = new TapArgs();
     args.positions.Add(Input.mousePosition);
     if (OnTap != null)
         OnTap(args);
 }
Ejemplo n.º 2
0
    void OnMouseDown()
    {
        TapArgs args = new TapArgs();

        args.positions.Add(Input.mousePosition);
        if (OnTap != null)
        {
            OnTap(args);
        }
    }
Ejemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (Input.touchCount > 0)
     {
         TapArgs args = CalculateTapEventArgs();
         if (OnTap != null)
         {
             OnTap(args);
         }
     }
 }
Ejemplo n.º 4
0
 private void HandleTap(TapArgs args)
 {
     foreach (Vector3 position in args.positions)
     {
         tapUI.DisplayTapValueAt(position, 1);
     }
     if (OnTap != null)
     {
         BigInteger tapValue = CalculateTapValue(args.positions.Count);
         OnTap(tapValue);
     }
 }
Ejemplo n.º 5
0
 private void HandleTap(TapArgs args)
 {
     foreach(Vector3 position in args.positions)
     {
         tapUI.DisplayTapValueAt(position, 1);
     }
     if (OnTap != null)
     {
         BigInteger tapValue = CalculateTapValue(args.positions.Count);
         OnTap(tapValue);
     }
 }
Ejemplo n.º 6
0
    private TapArgs CalculateTapEventArgs()
    {
        TapArgs args = new TapArgs();
        for (var i = 0; i < Input.touchCount; ++i)
        {
            Touch touch = Input.GetTouch(i);
            if (touch.phase == TouchPhase.Began)
            {
                Vector3 wp = Camera.main.ScreenToWorldPoint(touch.position);
                if (_collider == Physics2D.OverlapPoint(wp))
                {
                    args.positions.Add(touch.position);
                }
            }
        }

        return args;
    }
Ejemplo n.º 7
0
    private TapArgs CalculateTapEventArgs()
    {
        TapArgs args = new TapArgs();

        for (var i = 0; i < Input.touchCount; ++i)
        {
            Touch touch = Input.GetTouch(i);
            if (touch.phase == TouchPhase.Began)
            {
                Vector3 wp = Camera.main.ScreenToWorldPoint(touch.position);
                if (_collider == Physics2D.OverlapPoint(wp))
                {
                    args.positions.Add(touch.position);
                }
            }
        }

        return(args);
    }
Ejemplo n.º 8
0
 private void HandleTap(TapArgs args)
 {
     IterateOverPositions(args.positions, false);
     IterateOverPositions(args.spotlightPositions, true);
 }
Ejemplo n.º 9
0
    private TapArgs CalculateTapEventArgs()
    {
        TapArgs args = new TapArgs();

        if (Application.platform == RuntimePlatform.Android ||
            Application.platform == RuntimePlatform.IPhonePlayer)
        {

            for (var i = 0; i < Input.touchCount; ++i)
            {
                Touch touch = Input.GetTouch(i);
                if (touch.phase == TouchPhase.Began)
                {
                    CalculateWithPosition(touch.position, args);
                }
            }
        } else
        {
            if (Input.GetMouseButtonDown(0))
            {
                CalculateWithPosition(Input.mousePosition, args);
            }
        }
        return args;
    }
Ejemplo n.º 10
0
 private void CalculateWithPosition(Vector2 pos, TapArgs args)
 {
     Vector2 wp = Camera.main.ScreenToWorldPoint(pos);
     Collider2D hit = Physics2D.OverlapPoint(wp);
     if (hit)
     {
         if (hit.gameObject.tag == Tags.SPOTLIGHT)
         {
             args.spotlightPositions.Add(pos);
         }
         else if (hit == _collider)
         {
             args.positions.Add(pos);
         }
     }
 }
Ejemplo n.º 11
0
    void Start()
    {
        defaultThreshold = moveThreshold;

        Grouping.GroupManager.main.group["Main Menu"].Add(this, new Grouping.GroupDelegator(null, GameMenuEnter, GameMenuExit));
        Grouping.GroupManager.main.group["Level Select"].Add(this, new Grouping.GroupDelegator(null, GameMenuEnter, GameMenuExit));

        _idle = _activeState = new InputState(this);
        InputState deadState  = new InputState(this);
        InputState downState  = new InputState(this);
        InputState panState   = new InputState(this);
        InputState longState  = new InputState(this);
        InputState slideState = new InputState(this);

        deadState.Up        += Reset;
        deadState.Interrupt += Reset;

        _idle.Down += delegate {
            _startPos = _device.pos1;
            _objects  = GetAllObjects(_device.pos1);
            var args1 = new PressArgs(Gesture.Press, _startPos);
            _target   = DoGesture <IPress, PressArgs>(_objects, (t, a) => t.OnGesturePress(a), args1);
            _prevType = Gesture.Press;
            downState.Activate();
        };

        downState.Up += delegate {
            if (downState.time < longTime)
            {
                TapArgs args = new TapArgs(Gesture.Tap, _startPos);
                if (_target != null)
                {
                    ITap tap = _target as ITap;
                    if (IsEnabled(tap as Behaviour))
                    {
                        _prevType = Gesture.Tap;
                        tap.OnGestureTap(args);
                    }
                }
                else
                {
                    _prevType = Gesture.Tap;
                    DoGesture <ITap, TapArgs>(_objects, (t, a) => t.OnGestureTap(a), args);
                }
            }
            Reset();
        };

        downState.Moved += delegate {
            slideState.Activate();
        };

        downState.Hold += delegate {
            if (downState.time > longTime)
            {
                LongPressArgs largs = new LongPressArgs(Gesture.Press, LongPressArgs.State.Down, downState.startPos);
                PanArgs       pArgs = new PanArgs(Gesture.Press, PanArgs.State.Down, downState.startPos, downState.startPos, Vector2.zero);
                IPan          pan;
                ILongPress    lpress;
                if (_target != null)
                {
                    lpress = _target as ILongPress;
                    bool handled = false;
                    if (IsEnabled(lpress as Behaviour))
                    {
                        lpress.OnGestureLongPress(largs);
                        handled   = largs.handled;
                        _prevType = Gesture.LongPress;
                        longState.Activate();
                    }
                    if (!handled)
                    {
                        pan = _target as IPan;
                        if (IsEnabled(pan as Behaviour))
                        {
                            pan.OnGesturePan(pArgs);
                            if (pArgs.handled)
                            {
                                panState.Activate();
                            }
                            else
                            {
                                deadState.Activate();
                            }
                        }
                    }
                }
                else
                {
                    foreach (var item in _objects)
                    {
                        bool flag     = false;
                        var  lpresses = item.GetComponents(typeof(ILongPress));
                        foreach (var component in lpresses)
                        {
                            lpress = component as ILongPress;
                            if (IsEnabled(lpress as Behaviour))
                            {
                                lpress.OnGestureLongPress(largs);
                                if (largs.handled)
                                {
                                    _target   = lpress;
                                    _prevType = Gesture.LongPress;
                                    longState.Activate();
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        if (flag)
                        {
                            break;
                        }
                        var pans = item.GetComponents(typeof(IPan));
                        foreach (var component in pans)
                        {
                            pan = component as IPan;
                            pan = component as IPan;
                            if (IsEnabled(pan as Behaviour))
                            {
                                pan.OnGesturePan(pArgs);
                                if (pArgs.handled)
                                {
                                    _target   = pan;
                                    _prevType = Gesture.Pan;
                                    panState.Activate();
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        if (flag)
                        {
                            break;
                        }
                    }
                }
                if (_target == null)
                {
                    deadState.Activate();
                }
            }
        };

        slideState.Enter += delegate {
            FlingArgs sArgs = new FlingArgs(Gesture.Press, FlingArgs.State.Start, slideState.startPos, slideState.startPos);
            PanArgs   pArgs = new PanArgs(Gesture.Press, PanArgs.State.Down, slideState.startPos, slideState.startPos, Vector2.zero);
            IPan      pan;
            IFling    fling;
            if (_target != null)
            {
                fling = _target as IFling;
                bool handled = false;
                if (IsEnabled(fling as Behaviour))
                {
                    fling.OnGestureFling(sArgs);
                    handled = sArgs.handled;
                    if (handled)
                    {
                        //Stay in slide state!
                        _prevType = Gesture.Fling;
                    }
                }
                if (!handled)
                {
                    pan = _target as IPan;
                    if (IsEnabled(pan as Behaviour))
                    {
                        pan.OnGesturePan(pArgs);
                        if (pArgs.handled)
                        {
                            _prevType = Gesture.Pan;
                            //Change state!
                            panState.Activate();
                        }
                    }
                }
            }
            else
            {
                foreach (var item in _objects)
                {
                    var  flings = item.GetComponents(typeof(IFling));
                    bool flag   = false;
                    foreach (var component in flings)
                    {
                        fling = component as IFling;
                        if (IsEnabled(fling as Behaviour))
                        {
                            fling.OnGestureFling(sArgs);
                            if (sArgs.handled)
                            {
                                //Stay in slide state!
                                _target   = fling;
                                _prevType = Gesture.Fling;
                                flag      = true;
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    var pans = item.GetComponents(typeof(IPan));
                    foreach (var component in pans)
                    {
                        pan = component as IPan;
                        if (IsEnabled(pan as Behaviour))
                        {
                            pan.OnGesturePan(pArgs);
                            if (pArgs.handled)
                            {
                                //Change state!
                                _target   = pan;
                                _prevType = Gesture.Pan;
                                panState.Activate();
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
            }
            if (_target == null)
            {
                deadState.Activate();
            }
        };

        slideState.Up += delegate {
            if (slideState.time <= flingTime)
            {
                FlingArgs sArgs = new FlingArgs(_prevType, FlingArgs.State.End, slideState.startPos, _device.pos1);
                IFling    f     = _target as IFling;
                if (IsEnabled(f as Behaviour))
                {
                    f.OnGestureFling(sArgs);
                }
            }

            Reset();
        };

        slideState.Hold += delegate {
            if (slideState.time > flingTime)
            {
                FlingArgs sArgs = new FlingArgs(Gesture.Press, FlingArgs.State.Interrupt, slideState.startPos, _device.pos1);
                IFling    f     = _target as IFling;
                if (IsEnabled(f as Behaviour))
                {
                    f.OnGestureFling(sArgs);
                }
                IPan p       = _target as IPan;
                bool handled = false;
                if (IsEnabled(p as Behaviour))
                {
                    PanArgs pArgs = new PanArgs(Gesture.Fling, PanArgs.State.Down, _device.pos1, _device.pos1, Vector2.zero);
                    p.OnGesturePan(pArgs);
                    handled = pArgs.handled;
                }
                if (!handled)
                {
                    deadState.Activate();
                }
                else
                {
                    panState.Activate();
                }
            }
        };

        slideState.Interrupt += delegate {
            if (slideState.time <= flingTime)
            {
                FlingArgs sArgs = new FlingArgs(Gesture.Fling, FlingArgs.State.Interrupt, slideState.startPos, _device.pos1);
                IFling    f     = _target as IFling;
                if (f != null)
                {
                    f.OnGestureFling(sArgs);
                }
            }

            Reset();
        };

        longState.Hold += delegate {
            ILongPress lpress = _target as ILongPress;
            if (IsEnabled(lpress as Behaviour))
            {
                LongPressArgs args = new LongPressArgs(Gesture.Press, LongPressArgs.State.Hold, longState.startPos);
                lpress.OnGestureLongPress(args);
            }
        };

        longState.Up += delegate {
            ILongPress lpress = _target as ILongPress;
            if (IsEnabled(lpress as Behaviour))
            {
                LongPressArgs args = new LongPressArgs(Gesture.Press, LongPressArgs.State.Up, longState.startPos);
                lpress.OnGestureLongPress(args);
            }

            Reset();
        };

        longState.Interrupt += delegate {
            ILongPress lpress = _target as ILongPress;
            if (lpress != null)
            {
                LongPressArgs args = new LongPressArgs(Gesture.Press, LongPressArgs.State.Interrupt, longState.startPos);
                lpress.OnGestureLongPress(args);
            }

            Reset();
        };

        longState.Moved += delegate {
            ILongPress lpress = _target as ILongPress;
            if (lpress != null && IsEnabled(lpress as Behaviour))
            {
                LongPressArgs args = new LongPressArgs(Gesture.Press, LongPressArgs.State.Interrupt, longState.startPos);
                lpress.OnGestureLongPress(args);
                if (!args.handled)
                {
                    deadState.Activate();
                }
                else
                {
                    IPan pan = _target as IPan;
                    if (IsEnabled(pan as Behaviour))
                    {
                        PanArgs pArgs = new PanArgs(Gesture.LongPress, PanArgs.State.Down, _device.pos1, _device.pos1, Vector2.zero);
                        pan.OnGesturePan(pArgs);
                        if (pArgs.handled)
                        {
                            panState.Activate();
                        }
                        else
                        {
                            deadState.Activate();
                        }
                    }
                }
            }
        };

        panState.Hold += delegate {
            if (!moved())
            {
                IPan pan = _target as IPan;
                if (IsEnabled(pan as Behaviour))
                {
                    PanArgs pArgs = new PanArgs(Gesture.Pan, PanArgs.State.Hold, panState.startPos, _device.pos1, Vector2.zero);
                    pan.OnGesturePan(pArgs);
                }
            }
        };

        panState.Moved += delegate {
            IPan pan = _target as IPan;
            if (IsEnabled(pan as Behaviour))
            {
                PanArgs pArgs = new PanArgs(Gesture.Pan, PanArgs.State.Move, panState.startPos, _device.pos1, _deltaMove);
                pan.OnGesturePan(pArgs);
            }
        };

        panState.Up += delegate {
            IPan pan = _target as IPan;
            if (IsEnabled(pan as Behaviour))
            {
                PanArgs pArgs = new PanArgs(Gesture.Pan, PanArgs.State.Up, panState.startPos, _device.pos1, Vector2.zero);
                pan.OnGesturePan(pArgs);
            }
            Reset();
        };

        panState.Interrupt += delegate {
            IPan pan = _target as IPan;
            if (pan != null)
            {
                PanArgs pArgs = new PanArgs(Gesture.Pan, PanArgs.State.Interrupt, panState.startPos, _device.pos1, Vector2.zero);
                pan.OnGesturePan(pArgs);
            }

            Reset();
        };
        Reset();
    }