Example #1
0
    // Update is called once per frame
    void Update()
    {
        timeElapsed += Time.deltaTime;

        if (!gameOver && !betweenLevels)
        {
            return;
        }

        if (!FingerInput.GetInputPresent())
        {
            return;
        }

        if (FingerInput.GetFingerPressed())
        {
            waitingForRelease = true;
        }

        if (waitingForRelease && FingerInput.GetFingerReleased())
        {
            /*if ((betweenLevels && levelFinished) || gameOver)
             *  ResetLevel();*/
            if (betweenLevels)
            {
                levelText.text    = "";
                waitingForRelease = false;
                betweenLevels     = false;
                scoreText.text    = "Candies sorted: " + score.ToString() + "/" + GameMetaInfo.Instance.CandiesInLevel;
                Time.timeScale    = 1f;
                AudioManager.menu.Stop();
                AudioManager.gameplay.Play();
            }
        }
    }
Example #2
0
    private void HandleMouseInput()
    {
        Vector2 posRelative = new Vector2((float)Input.mousePosition.x / Screen.width, (float)Input.mousePosition.y / Screen.height);
        Vector3 position    = mainCamera.ScreenToWorldPoint(Input.mousePosition);

        // On mouse primary button click
        if (Input.GetMouseButtonDown(0))
        {
            FingerInput finger = new FingerInput(0, position, posRelative, new Vector2(0, 0), 0f);
            surfaceFingers.Add(0, finger);
            OnFingerAdd(new List <FingerInput>(surfaceFingers.Values));
        }
        // On release
        else if (Input.GetMouseButtonUp(0))
        {
            OnFingerRemove(new List <FingerInput>(surfaceFingers.Values));
            surfaceFingers.Remove(0);
        }
        // If holding mouse button down, update position
        else if (surfaceFingers.Count > 0)
        {
            List <FingerInput> updated = new List <FingerInput>();
            FingerInput        finger  = surfaceFingers[0];
            finger.UpdateProps(position, posRelative, new Vector2(0, 0), 0f);
            updated.Add(finger);
            OnFingerUpdate(updated);
        }
    }
Example #3
0
    /// <summary>
    /// Processes OSC messages of type "/tuio/2Dcur"
    /// </summary>
    private void ProcessCursorMessage(OSCMessage msg)
    {
        string msgType = msg.Values[0].ToString(); //   source / alive / set / fseq

        switch (msgType)
        {
        case "alive":
        {
            //Alive message contains a list of finger IDs that are present on the table.
            //Use it to see which ones are no longer there.
            List <int> ids = new List <int>(surfaceFingers.Keys);
            foreach (int id in ids)
            {
                if (!msg.Values.Contains(id))
                {
                    lastRemovedFingers.Add(surfaceFingers[id]);
                    surfaceFingers.Remove(id);
                }
            }
            break;
        }

        case "set":
        {
            // Set message contains the data for all fingers currently on the table.
            // Use it for update and new finger addition.
            int id = (int)msg.Values[1];

            float x = (float)msg.Values[2];
            float y = 1f - (float)msg.Values[3];              // y axis faces the opposite direction in Unity compared to what the Surface feeds

            Vector2 posRelative = new Vector2(x, y);          // relative positions in [0, 1] range
            Vector2 position    = ComputeWorldPosition(x, y); // absolute pixel positions

            float   xVel     = (float)msg.Values[4];
            float   yVel     = (float)msg.Values[5];
            Vector2 velocity = new Vector2(xVel, yVel);

            float acc = (float)msg.Values[6];

            FingerInput surfaceFinger;
            if (surfaceFingers.TryGetValue(id, out surfaceFinger))
            {
                if (surfaceFinger.posRelative != posRelative)
                {
                    surfaceFinger.UpdateProps(position, posRelative, velocity, acc);
                    lastUpdatedFingers.Add(surfaceFinger);
                }
            }
            else
            {
                surfaceFinger = new FingerInput(id, position, posRelative, velocity, acc);
                surfaceFingers.Add(id, surfaceFinger);
                lastAddedFingers.Add(surfaceFinger);
            }
            break;
        }
        }
    }
Example #4
0
    public Vector3 GetDragPoint()
    {
        if (fingerInputDic.Count == 0)
        {
            return(Define.EXCEPT_POSITION);
        }
        FingerInput fingerInput = GetCurrentInput();

        return(fingerInput.currentTouchORMousePosition);
    }
Example #5
0
 private void OnTouchContinues(Touch touch, TouchPhase phase)
 {
     for (int i = 0; i < Inputs.Count; i++)
     {
         FingerInput input = Inputs[i];
         if (input.FingerID == touch.fingerId)
         {
             SetMousePresse(touch.fingerId, phase != TouchPhase.Ended && phase != TouchPhase.Canceled);
         }
     }
 }
Example #6
0
    // Update is called once per frame
    void Update()
    {
        /*if (FingerInput.GetFingerPressed())
         * {
         *  pressed = true;
         * }*/

        if (!FingerInput.GetInputPresent() || !FingerInput.GetFingerDown())
        {
            swiped       = false;
            needsRelease = false;
            return;
        }

        if (needsRelease)
        {
            return;
        }

        fingerPos = FingerInput.GetFingerPosition();

        /*if (FingerInput.GetFingerDown())
         * {
         *  fingerPos = FingerInput.GetFingerPosition();
         * }*/

        if (FingerInput.GetFingerPressed())
        {
            touchPos = fingerPos;
        }

        //if (Mathf.Abs(touchPos.y - fingerPos.y) >= minSwipeDistance && pressed)
        if (Mathf.Abs(touchPos.y - fingerPos.y) >= minSwipeDistance && !swiped)
        {
            //pressed = false;
            //if(touchPos.y >= Screen.height / 2)
            if (touchPos.y - fingerPos.y < 0)
            {
                handController.slap();
                swiped = true;
            }
            //else if(touchPos.y < Screen.height / 2)
            else
            {
                handController.premiumCandy();
                swiped = true;
            }
            needsRelease = true;
        }
    }
Example #7
0
    public FingerInput GetCurrentInput()
    {
        if (fingerInputDic.Count <= 0)
        {
            return(null);
        }

        var enumerator = fingerInputDic.GetEnumerator();

        enumerator.MoveNext();
        FingerInput current_input = enumerator.Current.Value;

        return(current_input);
    }
Example #8
0
    void TouchEndState(FingerInput input)
    {
        if (this.DragBuilding != null)
        {
            this.DragBuilding.isSelect = false;
        }
        if (this.SelectBuilding != null)
        {
            this.SelectBuilding = null;
        }

        if (CameraManager.Instance.isEnablePan == false)
        {
            CameraManager.Instance.isEnablePan = true;
        }
    }
Example #9
0
    // Start is called before the first frame update
    void Start()
    {
        minSwipeDistance = Screen.width * screenSwipePercentage / 100;
        cam = Camera.main;

        if (FingerInput.GetInputPresent() && FingerInput.GetFingerDown())
        {
            needsRelease = true;
        }

        currentCandy   = GameObject.Find("CurrentCandy");
        candyGenerator = GameObject.Find("CandyGenerator").GetComponent <CandyGenerator>();
        goodEffect     = GameObject.Find("Particle_Good").GetComponent <ParticleSystem>();
        badEffect      = GameObject.Find("Particle_Bad").GetComponent <ParticleSystem>();
        objectPos      = currentCandy.transform.position;
    }
Example #10
0
    private void ProcessCursorMessage(OSCMessage msg)
    {
        string msgType = msg.Values[0].ToString(); //   source / alive / set / fseq

        switch (msgType)
        {
        case "alive": {
            List <int> ids = new List <int>(surfaceFingers.Keys);
            foreach (int id in ids)
            {
                if (!msg.Values.Contains(id))
                {
                    surfaceFingers.Remove(id);
                }
            }
            break;
        }

        case "set": {
            int id = (int)msg.Values[1];

            float   x        = (float)msg.Values[2];
            float   y        = (float)msg.Values[3];
            Vector2 position = new Vector2(x, y);

            float   xVel     = (float)msg.Values[4];
            float   yVel     = (float)msg.Values[5];
            Vector2 velocity = new Vector2(xVel, yVel);

            float acc = (float)msg.Values[6];

            FingerInput surfaceFinger;
            if (surfaceFingers.TryGetValue(id, out surfaceFinger))
            {
                surfaceFinger.UpdateProps(position, velocity, acc);
            }
            else
            {
                surfaceFinger = new FingerInput(id, position, velocity, acc);
                surfaceFingers.Add(id, surfaceFinger);
            }
            break;
        }
        }
    }
Example #11
0
    void TouchBeginState(FingerInput input)
    {
        if (input.currentRayHitLayer == Define.LAYERMASK_BUILDING)
        {
/*            CameraManager.Instance.IsEnablePan = false;*/

            this.SelectBuilding = input.currentRayHitTransform.GetComponent <HeroScript>();
            if (this.DragBuilding == null)
            {
                this.DragBuilding          = this.SelectBuilding;
                this.DragBuilding.IsSelect = true;
            }
            else
            {
                this.DragBuilding.IsSelect = false;
                this.DragBuilding          = this.SelectBuilding;
                this.DragBuilding.IsSelect = true;
            }
        }
    }
Example #12
0
 void TouchPressingState(FingerInput input)
 {
 }
Example #13
0
    public void TouchUpdate()
    {
        FingerInput fingerinput;


        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; i++)
            {
                if (fingerInputDic.TryGetValue(Input.touches[i].fingerId, out fingerinput) == false)
                {
                    if (Input.touches[i].phase == TouchPhase.Began)
                    {
                        fingerinput = new FingerInput(Input.touches[i].fingerId);
                        fingerInputDic.Add(Input.touches[i].fingerId, fingerinput);
                    }
                }

                rayHitLayer = Define.LAYERMASK_ALL_PICKLAYER;

                fingerinput.SetCurrentPoint(Input.touches[i].phase, Input.touches[i].position);

                switch (Input.touches[i].phase)
                {
                case TouchPhase.Moved:
                {
                    fingerinput.pressingAcumTime += Time.deltaTime;
                    float dragDelta = Vector2.Distance(fingerinput.beginPoint, fingerinput.currentPoint);
                    fingerinput.isDragging = (dragDelta > DRAG_THRESHOLD) ? true : false;
                }
                break;

                case TouchPhase.Stationary:
                {
                    fingerinput.pressingAcumTime += Time.deltaTime;
                    fingerinput.isPressed         = true;
                }
                break;

                case TouchPhase.Ended:
                case TouchPhase.Canceled:
                {
                    fingerinput.isPressed        = false;
                    fingerinput.pressingAcumTime = 0.0f;
                    fingerinput.isDragging       = false;
                }
                break;
                }
                fingerinput.prevTouchPhase = fingerinput.currentTouchPhase;
            }
        }
        else
        {
            if (Input.GetMouseButtonDown((int)MouseButton.Left))
            {
                rayHitLayer = Define.LAYERMASK_ALL_PICKLAYER;
                if (fingerInputDic.TryGetValue((int)MouseButton.Left, out fingerinput) == false)
                {
                    fingerinput = new FingerInput((int)MouseButton.Left);
                    fingerinput.SetCurrentPoint(TouchPhase.Began, Input.mousePosition);
                    fingerInputDic.Add((int)MouseButton.Left, fingerinput);
                }
            }
            else if (Input.GetMouseButtonUp((int)MouseButton.Left))
            {
                if (fingerInputDic.TryGetValue((int)MouseButton.Left, out fingerinput) == true)
                {
                    fingerinput.SetCurrentPoint(TouchPhase.Ended, Input.mousePosition);

                    fingerinput.isDragging       = false;
                    fingerinput.isPressed        = false;
                    fingerinput.pressingAcumTime = 0.0f;
                }
            }
            else if (Input.GetMouseButton((int)MouseButton.Left))
            {
                if (fingerInputDic.TryGetValue((int)MouseButton.Left, out fingerinput) == true)
                {
                    fingerinput.SetCurrentPoint(TouchPhase.Moved, Input.mousePosition);
                    float dragDelta = Vector2.Distance(fingerinput.prevPoint, fingerinput.currentPoint);
                    fingerinput.isDragging        = (dragDelta > DRAG_THRESHOLD) ? true : false;
                    fingerinput.isPressed         = true;
                    fingerinput.pressingAcumTime += Time.deltaTime;
                }
            }
            else
            {
                if (fingerInputDic.Count > 0)
                {
                    fingerInputDic.Clear();
                }
            }
        }
    }
Example #14
0
    // Update is called once per frame
    void Update()
    {
        timeElapsed += Time.deltaTime;
        if (timeElapsed > message1Duration && timeElapsed <= message1Duration + message2Duration)
        {
            messageBox.text = message2;
        }
        else if (timeElapsed > message1Duration + message2Duration)
        {
            canvas.enabled = false;
        }

        if (!FingerInput.GetInputPresent() || !FingerInput.GetFingerDown())
        {
            timeHeld = 0f;
            if (heldCandy == null)
            {
                return;
            }

            if (heldCandy.tag == "good")
            {
                goodCandies.Remove(heldCandy);
            }
            else
            {
                badCandies.Remove(heldCandy);
            }

            if ((cam.WorldToScreenPoint(heldCandy.transform.position).y >= cam.pixelHeight / 2 ||
                 badCandies.Count >= 9) && goodCandies.Count < 9)
            {
                goodCandies.Add(heldCandy);
                heldCandy.tag = "good";
            }
            else
            {
                badCandies.Add(heldCandy);
                heldCandy.tag = "bad";
            }

            heldCandy = null;
            ArrangeGoodCandies();
            ArrangeBadCandies();
            return;
        }

        Vector3 fingerPos = cam.ScreenToWorldPoint(FingerInput.GetFingerPosition());

        fingerPos.z = 0;
        if (FingerInput.GetFingerPressed())
        {
            holding = true;
            grabPos = fingerPos;
            Vector2      startPoint = fingerPos;
            RaycastHit2D raycastHit = Physics2D.Raycast(startPoint, Vector2.zero);
            if (raycastHit.collider != null)
            {
                heldCandy = raycastHit.collider.gameObject;
            }
        }

        if (heldCandy != null)
        {
            heldCandy.transform.position = fingerPos;
        }

        if (holding)
        {
            if ((grabPos - fingerPos).magnitude > holdMovementTolerance)
            {
                holding = false;
            }
            else
            {
                timeHeld += Time.deltaTime;
                if ((heldCandy != null && timeHeld >= holdDurationOverCandy) ||
                    heldCandy == null && timeHeld >= holdDuration)
                {
                    GoToNewsScreen();
                }
            }
        }
    }
Example #15
0
    // Update is called once per frame
    void Update()
    {
        if (GameState.Instance.GameOver || GameState.Instance.BetweenLevels || swipeTime >= candyGenerator.number)
        {
            return;
        }

        // If the user isn't touching the screen, the candy should be released
        if (!FingerInput.GetInputPresent() || !FingerInput.GetFingerDown())
        {
            swiped = false;

            // Gradually move the candy to the center of the screen
            currentCandy.transform.position = Vector3.Lerp(currentCandy.transform.position, objectPos, Time.deltaTime * centerSpeed);

            needsRelease = false;
            return;
        }

        if (needsRelease)
        {
            return;
        }

        fingerPos = FingerInput.GetFingerPosition();

        if (FingerInput.GetFingerPressed())
        {
            touchPos    = fingerPos;
            startPosSet = true;
        }

        if (!startPosSet)
        {
            return;
        }

        if (Mathf.Abs(touchPos.x - fingerPos.x) >= minSwipeDistance && !swiped && swipeTime < candyGenerator.number)
        {
            GameObject candyChild = currentCandy.transform.GetChild(0).gameObject;
            // The user swiped left
            if (touchPos.x - fingerPos.x > 0)
            {
                if (candyChild.tag == "bad")
                {
                    // The user correctly disposed of a bad candy
                    badEffect.Play(true);
                    AudioManager.goodSwipe.Play();
                    GameState.Instance.AddToScore(1);
                }
                else if (candyChild.tag == "good")
                {
                    // The user incorrectly disposed of a good candy
                    goodEffect.Play(true);
                    AudioManager.badSwipe.Play();
                    GameState.Instance.DecrementLives();
                }

                // Check if the user disposed of too many good candies
                if (GameState.Instance.GameOver)
                {
                    return;
                }
            }
            else // The user swiped right
            {
                // The user incorrectly saved a bad candy, poisoning their child and triggering a game over
                if (candyChild.tag == "bad")
                {
                    badEffect.Play(true);
                    GameState.Instance.InvokeGameOver();
                    return;
                }

                // The user correctly saved a good candy
                goodEffect.Play(true);
                AudioManager.goodSwipe.Play();
                GameState.Instance.AddToScore(1);
            }

            // Check if the last candy was swiped
            if (swipeTime == candyGenerator.number - 1)
            {
                candyGenerator.RemoveLast();
                swipeTime++;
                swiped = true;
            }
            else
            {
                if (swipeTime == candyGenerator.number - 2)
                {
                    candyGenerator.RemoveLastInBag();
                    swipeTime++;
                    swiped = true;
                }
                if (swipeTime < candyGenerator.number - 2)
                {
                    candyGenerator.RemoveCandyInBag();
                    swipeTime++;
                    swiped = true;
                }

                // Set current candy to be the new candy pulled from the bag
                currentCandy = GameObject.Find("CurrentCandy");
                currentCandy.transform.position = objectPos;
                needsRelease = true;
            }
        }

        // Update the candy position if the user is swiping
        if (swipeTime < candyGenerator.number && !needsRelease)
        {
            currentCandy.transform.position = objectPos + new Vector3(cam.ScreenToWorldPoint(fingerPos).x - cam.ScreenToWorldPoint(touchPos).x, 0f, 0f);
        }
    }