Example #1
0
    private void NuitrackManager_onHandsTrackerUpdate(nuitrack.HandTrackerData handTrackerData)
    {
        active = false;

        nuitrack.UserHands userHands = handTrackerData.GetUserHandsByID(CurrentUserTracker.CurrentUser);

        if (userHands != null)
        {
            nuitrack.HandContent?handContent = currentHand == Hands.right ? userHands.RightHand : userHands.LeftHand;

            if (handContent != null)
            {
                Vector2 pageSize     = parentRectTransform.rect.size;
                Vector3 lastPosition = baseRect.position;
                baseRect.anchoredPosition = new Vector2(handContent.Value.X * pageSize.x, -handContent.Value.Y * pageSize.y);

                float velocity = (baseRect.position - lastPosition).magnitude / (Time.time - lastTime);

                if (velocity < minVelocityInteractivePoint)
                {
                    Press = handContent.Value.Click;
                }

                active = true;
            }
        }

        Press = Press && active;

        lastTime           = Time.time;
        background.enabled = active;
        background.sprite  = active && Press ? pressSprite : defaultSprite;
    }
Example #2
0
    private void NuitrackManager_onHandsTrackerUpdate(nuitrack.HandTrackerData handTrackerData)
    {
        active = false;
        press  = false;

        if (handTrackerData != null)
        {
            nuitrack.UserHands userHands = handTrackerData.GetUserHandsByID(CurrentUserTracker.CurrentUser);

            if (userHands != null)
            {
                if (userHands.RightHand != null)
                {
                    Vector2 curpos = new Vector2(userHands.RightHand.Value.X * Screen.currentResolution.width, userHands.RightHand.Value.Y * Screen.currentResolution.height);
                    MouseOperations.SetCursorPosition((int)(curpos.x), (int)(curpos.y));
                    active = true;
                    press  = userHands.RightHand.Value.Click;

                    /*if (pressed != press)
                     * {
                     *  pressed = press;
                     *
                     *  if (pressed)
                     *  {
                     *      MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftUp | MouseOperations.MouseEventFlags.LeftDown);
                     *  }
                     * }*/
                }
            }
        }
    }
    void HandleOnHandsUpdateEvent(nuitrack.HandTrackerData _handTrackerData)
    {
        if (handTrackerData != null)
        {
            handTrackerData.Dispose();
        }

        handTrackerData = (nuitrack.HandTrackerData)_handTrackerData.Clone();

        try
        {
            onHandsTrackerUpdate?.Invoke(handTrackerData);
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }

        if (handTrackerData == null)
        {
            return;
        }

        if (Users.CurrentUserID != 0)
        {
            currentHands = handTrackerData.GetUserHandsByID(Users.CurrentUserID);
        }
        else
        {
            currentHands = null;
        }
    }
    private void NuitrackManager_onHandsTrackerUpdate(nuitrack.HandTrackerData handTrackerData)
    {
        active = false;
        press  = false;

        ItemDragHandler drag = GetComponent <ItemDragHandler>();

        if (handTrackerData != null)
        {
            nuitrack.UserHands userHands = handTrackerData.GetUserHandsByID(CurrentUserTracker.CurrentUser);

            if (userHands != null)
            {
                if (userHands.RightHand != null)
                {
                    Vector2 curpos = new Vector2(userHands.RightHand.Value.X * Screen.currentResolution.width, userHands.RightHand.Value.Y * Screen.currentResolution.height);
                    MouseOperations.SetCursorPosition((int)(curpos.x), (int)(curpos.y));
                    active = true;
                    press  = userHands.RightHand.Value.Pressure == 1.0f;

                    if (press)
                    {
                        objectToDrag = drag.GetDraggableTransformUnderMouse();

                        drag.dragObj(objectToDrag);
                        dragging = true;
                    }
                    if (dragging)
                    {
                        drag.dragObj(objectToDrag);
                    }
                    else
                    {
                        drag.endDrag(objectToDrag);
                        dragging = false;
                    }
                }
            }
        }
    }
Example #5
0
    void HandleOnHandsUpdateEvent(nuitrack.HandTrackerData _handTrackerData)
    {
        handTrackerData = _handTrackerData;
        if (onHandsTrackerUpdate != null)
        {
            onHandsTrackerUpdate(handTrackerData);
        }

        //Debug.Log ("Grabbed hands");
        if (handTrackerData == null)
        {
            return;
        }
        if (CurrentUserTracker.CurrentUser != 0)
        {
            currentHands = handTrackerData.GetUserHandsByID(CurrentUserTracker.CurrentUser);
        }
        else
        {
            currentHands = null;
        }
    }
Example #6
0
    void HandleOnHandsUpdateEvent(nuitrack.HandTrackerData _handTrackerData)
    {
        if (handTrackerData != null)
        {
            handTrackerData.Dispose();
        }
        handTrackerData = (nuitrack.HandTrackerData)_handTrackerData.Clone();
        onHandsTrackerUpdate?.Invoke(handTrackerData);

        //Debug.Log ("Grabbed hands");
        if (handTrackerData == null)
        {
            return;
        }
        if (CurrentUserTracker.CurrentUser != 0)
        {
            currentHands = handTrackerData.GetUserHandsByID(CurrentUserTracker.CurrentUser);
        }
        else
        {
            currentHands = null;
        }
    }
Example #7
0
    private void NuitrackManager_onHandsTrackerUpdate(nuitrack.HandTrackerData handTrackerData)
    {
        active = false;

        if (handTrackerData != null)
        {
            nuitrack.UserHands userHands = handTrackerData.GetUserHandsByID(CurrentUserTracker.CurrentUser);

            if (userHands != null)
            {
                // Right hand
                if (userHands.RightHand != null)
                {
                    //baseRect.anchoredPosition = new Vector2(userHands.RightHand.Value.X * Screen.width, -userHands.RightHand.Value.Y * Screen.height);
                    rightHandPos = new Vector3(userHands.RightHand.Value.X * Screen.width, -userHands.RightHand.Value.Y * Screen.height, ZPosition);

                    //Debug.Log("Right: " + rightHandPos);

                    rightHandPic.transform.position = rightHandPos;

                    active = true;
                }
                // Left hand
                if (userHands.LeftHand != null)
                {
                    //baseRect.anchoredPosition = new Vector2(userHands.LeftHand.Value.X * Screen.width, -userHands.LeftHand.Value.Y * Screen.height);
                    leftHandPos = new Vector3(userHands.LeftHand.Value.X * Screen.width, -userHands.LeftHand.Value.Y * Screen.height, ZPosition);

                    leftHandPic.transform.position = leftHandPos;

                    //Debug.Log("Left: " + leftHandPos);

                    active = true;
                }
            }
        }
    }
Example #8
0
    private void NuitrackManager_onHandsTrackerUpdate(nuitrack.HandTrackerData handTrackerData)
    {
        active = false;
        press  = false;

        if (handTrackerData != null)
        {
            nuitrack.UserHands userHands = handTrackerData.GetUserHandsByID(CurrentUserTracker.CurrentUser);

            if (userHands != null)
            {
                if (currentHand == Hands.right && userHands.RightHand != null)
                {
                    baseRect.anchoredPosition = new Vector2(userHands.RightHand.Value.X * Screen.width, -userHands.RightHand.Value.Y * Screen.height);
                    active = true;
                    press  = userHands.RightHand.Value.Click;
                }
                else if (currentHand == Hands.left && userHands.LeftHand != null)
                {
                    baseRect.anchoredPosition = new Vector2(userHands.LeftHand.Value.X * Screen.width, -userHands.LeftHand.Value.Y * Screen.height);
                    active = true;
                    press  = userHands.LeftHand.Value.Click;
                }
            }
        }

        background.enabled = active;
        background.sprite  = active && press ? pressSprite : defaultSprite;

        if (!active)
        {
            return;
        }

        Vector2 pointOnScreenPosition = cam.WorldToScreenPoint(transform.position);

        eventData.delta    = pointOnScreenPosition - eventData.position;
        eventData.position = pointOnScreenPosition;

        raycastResults.Clear();
        EventSystem.current.RaycastAll(eventData, raycastResults);

        //ImageItem newButton = null;

        //for (int i = 0; i < raycastResults.Count && newButton == null; i++)
        //    newButton = raycastResults[i].gameObject.GetComponent<ImageItem>();

        Button newButton = null;

        for (int i = 0; i < raycastResults.Count && newButton == null; i++)
        {
            newButton = raycastResults[i].gameObject.GetComponent <Button>();
        }

        if (newButton != selectedButton)
        {
            if (selectedButton != null)
            {
                selectedButton.OnPointerExit(eventData);
                elapsedTime           = 0;
                timerImage.fillAmount = 0f;

                timerImage2.gameObject.SetActive(false);
                angle = -(timerImage.fillAmount * 360f + 90f) * Mathf.Deg2Rad;
                var offset = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;
                timerImage2.transform.localPosition = new Vector3(offset.x, offset.y, 0f);
            }

            selectedButton = newButton;

            if (selectedButton != null)
            {
                selectedButton.OnPointerEnter(eventData);
            }
        }
        else if (selectedButton != null)
        {
            elapsedTime += Time.deltaTime;

            // Reduce fillAmount of Timer Filler Image(visual feedback) over waitTiming
            timerImage.fillAmount += (1f / endTime) * Time.deltaTime;

            timerImage2.gameObject.SetActive(true);
            angle = -(timerImage.fillAmount * 360f + 90f) * Mathf.Deg2Rad;
            var offset = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;
            timerImage2.transform.localPosition = new Vector3(offset.x, offset.y, 0f);
            //Debug.Log("Fill: " + timerImage.fillAmount + " Angle: " + angle + " Center: " + center + " Offset: " + offset + " Result: " + result + " pos: " + timerImage2.transform.position);

            if (elapsedTime >= endTime)
            {
                elapsedTime           = 0;
                timerImage.fillAmount = 0f;

                timerImage2.gameObject.SetActive(false);
                angle = -(timerImage.fillAmount * 360f + 90f) * Mathf.Deg2Rad;
                var offset1 = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;
                timerImage2.transform.localPosition = new Vector3(offset1.x, offset1.y, 0f);

                selectedButton.OnPointerClick(eventData);

                //Go to Start game from the button check
                if (selectedButton.name == "Start")
                {
                    Menu_Manager.Instance.Tutorial_Mode = false;
                    Menu_Manager.Instance.In_Game();
                }
                //Return to main menu
                else if (selectedButton.name == "Return_MainMenu")
                {
                    Menu_Manager.Instance.OnGameMenu();
                }
                //Go to Tutorial Scene
                else if (selectedButton.name == "Tutorial")
                {
                    Menu_Manager.Instance.Tutorial_Mode = true;
                    Menu_Manager.Instance.In_Game();
                }
                //Go to Options Scene
                else if (selectedButton.name == "Options")
                {
                    Menu_Manager.Instance.OnOptions();
                }
                //Go back to previous gameplay/selections
                else if (selectedButton.name == "Back")
                {
                    Menu_Manager.Instance.Resume();
                }
                //Close applications
                else if (selectedButton.name == "Exit")
                {
                    Menu_Manager.Instance.Exit();
                }
                //Go to HighScore Scene
                else if (selectedButton.name == "HighScore")
                {
                    Menu_Manager.Instance.HighScore();
                }
                //Go to Credits Scene
                else if (selectedButton.name == "Credits")
                {
                    Menu_Manager.Instance.Credits();
                }
                //Open Play section of canvas
                else if (selectedButton.name == "Play")
                {
                    MainMenuSections.SetActive(false);
                    ExtraSections.SetActive(false);
                    PlaySections.SetActive(true);
                }
                //Open MenuSelect section of canvas
                else if (selectedButton.name == "Back_MenuSelect")
                {
                    MainMenuSections.SetActive(true);
                    ExtraSections.SetActive(false);
                    PlaySections.SetActive(false);
                }
                //Open Extras section of canvas
                else if (selectedButton.name == "Extra")
                {
                    MainMenuSections.SetActive(false);
                    ExtraSections.SetActive(true);
                    PlaySections.SetActive(false);
                }
                //Option Menu to check if SFX if mute or unmute
                else if (selectedButton.name == "SFX_Check")
                {
                    //elapsedTime += Time.deltaTime;
                    //if (elapsedTime > endTime)
                    //{
                    if (selectedButton.GetComponentInParent <Toggle>().isOn == true)
                    {
                        selectedButton.GetComponentInParent <Toggle>().isOn = false;
                        if (TemptSFX == 0.0f)
                        {
                            TemptSFX = 0.5f;
                            Audio_Manager.Instance.SFXMaxAudio(TemptSFX);
                        }
                        else
                        {
                            Audio_Manager.Instance.SFXMaxAudio(TemptSFX);
                        }

                        elapsedTime = 0;
                        Debug.Log("Off");
                    }
                    else
                    {
                        selectedButton.GetComponentInParent <Toggle>().isOn = true;
                        Audio_Manager.Instance.SFXMinAudio();
                        elapsedTime = 0;
                        Debug.Log("On");
                    }
                    //}
                    //selectedButton.OnDrag(eventData);
                }
                //Option Menu to check if BGM if mute or unmute
                else if (selectedButton.name == "BGM_Check")
                {
                    //elapsedTime += Time.deltaTime;
                    //if (elapsedTime > endTime)
                    //{
                    if (selectedButton.GetComponentInParent <Toggle>().isOn == true)
                    {
                        selectedButton.GetComponentInParent <Toggle>().isOn = false;
                        if (TemptBGM == 0.0f)
                        {
                            TemptBGM = 0.5f;
                            Audio_Manager.Instance.BGMMaxAudio(TemptBGM);
                        }
                        else
                        {
                            Audio_Manager.Instance.BGMMaxAudio(TemptBGM);
                        }


                        elapsedTime = 0;
                        Debug.Log("Off");
                    }
                    else
                    {
                        selectedButton.GetComponentInParent <Toggle>().isOn = true;
                        Audio_Manager.Instance.BGMMinAudio();
                        elapsedTime = 0;
                        Debug.Log("On");
                    }
                    // }
                }
            }
            //Option Menu to increase sounds
            if (selectedButton.name == "Increase_SFX" || selectedButton.name == "Increase_BGM")
            {
                if (selectedButton.name == "Increase_BGM")
                {
                    TemptBGM = selectedButton.GetComponentInParent <Slider>().value;
                    Audio_Manager.Instance.SetBgmLvl(selectedButton.GetComponentInParent <Slider>().value);
                }
                if (selectedButton.name == "Increase_SFX")
                {
                    TemptSFX = selectedButton.GetComponentInParent <Slider>().value;
                    Audio_Manager.Instance.SetSfxLvl(selectedButton.GetComponentInParent <Slider>().value);
                }

                selectedButton.GetComponentInParent <Slider>().value += 40 * Time.deltaTime;
                if (selectedButton.GetComponentInParent <Slider>().value >= 0)
                {
                    selectedButton.GetComponentInParent <Slider>().value = 0;
                }
            }
            //Option Menu to decrease sounds
            else if (selectedButton.name == "Decrease_SFX" || selectedButton.name == "Decrease_BGM")
            {
                if (selectedButton.name == "Decrease_BGM")
                {
                    TemptBGM = selectedButton.GetComponentInParent <Slider>().value;
                    Audio_Manager.Instance.SetBgmLvl(selectedButton.GetComponentInParent <Slider>().value);
                }
                if (selectedButton.name == "Decrease_SFX")
                {
                    TemptSFX = selectedButton.GetComponentInParent <Slider>().value;
                    Audio_Manager.Instance.SetSfxLvl(selectedButton.GetComponentInParent <Slider>().value);
                }
                selectedButton.GetComponentInParent <Slider>().value -= 40 * Time.deltaTime;
                if (selectedButton.GetComponentInParent <Slider>().value <= -80)
                {
                    selectedButton.GetComponentInParent <Slider>().value = -80;
                }
            }
        }
    }
Example #9
0
    private void NuitrackManager_onHandsTrackerUpdate(nuitrack.HandTrackerData handTrackerData)
    {
        active = false;
        press  = false;

        // Set Hand Pointer Data if can detect hand
        if (handTrackerData != null)
        {
            nuitrack.UserHands userHands = handTrackerData.GetUserHandsByID(CurrentUserTracker.CurrentUser);

            if (userHands != null)
            {
                if (currentHand == Hands.right && userHands.RightHand != null)
                {
                    baseRect.anchoredPosition = new Vector2(userHands.RightHand.Value.X * Screen.width, -userHands.RightHand.Value.Y * Screen.height);
                    active = true;
                    press  = userHands.RightHand.Value.Click;
                }
                else if (currentHand == Hands.left && userHands.LeftHand != null)
                {
                    baseRect.anchoredPosition = new Vector2(userHands.LeftHand.Value.X * Screen.width, -userHands.LeftHand.Value.Y * Screen.height);
                    active = true;
                    press  = userHands.LeftHand.Value.Click;
                }
            }
        }

        // Show Image
        background.enabled = active;

        if (active)
        {
            // Change back to Hand Sprite if not holding food
            if (!foodSO)
            {
                background.sprite = defaultSprite;
            }
        }
        else
        {
            // Do not do anything if not active
            return;
        }

        // Raycast from Screen Space to World Space
        var pointOnScreenPosition = (Vector2)cam.WorldToScreenPoint(transform.position);

        eventData.delta    = pointOnScreenPosition - eventData.position;
        eventData.position = pointOnScreenPosition;

        raycastResults.Clear();
        EventSystem.current.RaycastAll(eventData, raycastResults);

        Button newButton = null;

        for (int i = 0; i < raycastResults.Count && newButton == null; i++)
        {
            newButton = raycastResults[i].gameObject.GetComponent <Button>();
        }

        if (newButton != selectedButton)
        {
            // When current selected button is not previous sselected button
            if (selectedButton != null)
            {
                selectedButton.OnPointerExit(eventData);

                // Reset Hand Timer, Frame and Flower
                handElapsedTime       = 0f;
                timerImage.fillAmount = 0f;
                timerImage2.gameObject.SetActive(false);
                angle = -(timerImage.fillAmount * 360f + 90f) * Mathf.Deg2Rad;
                var offset = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;
                timerImage2.transform.localPosition = new Vector3(offset.x, offset.y, 0f);

                // If previous selected button is Ingredient Panel, stop zooming
                if (selectedButton.GetComponent <IngredientPanel>())
                {
                    selectedButton.GetComponent <IngredientPanel>().Zoomasaurus(false);
                }

                // If any of the cooking appliance's hover hint is active, close it
                if (LevelManager.Instance.cookingAppliances.Any(x => x.hoverHint.activeSelf))
                {
                    foreach (var app in LevelManager.Instance.cookingAppliances)
                    {
                        if (app.hoverHint.activeSelf)
                        {
                            app.OpenCloseHint(false);
                            app.OpenCloseCanvas(false);
                        }
                    }
                }
            }

            // Updates selected buttpon
            selectedButton = newButton;

            if (selectedButton != null)
            {
                selectedButton.OnPointerEnter(eventData);

                // If selected button is Ingredient Panel, start zooming
                if (selectedButton.GetComponent <IngredientPanel>())
                {
                    selectedButton.GetComponent <IngredientPanel>().Zoomasaurus(true);
                }
            }
        }
        else if (selectedButton != null)
        {
            // Runs timer
            handElapsedTime += Time.deltaTime;

            // Reduce fillAmount of Timer Filler Image(visual feedback) over waitTiming
            timerImage.fillAmount += (1f / handTimer) * Time.deltaTime;

            // Shows Flower Image and Move it in a circle
            timerImage2.gameObject.SetActive(true);
            angle = -(timerImage.fillAmount * 360f + 90f) * Mathf.Deg2Rad;
            var offset = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;
            timerImage2.transform.localPosition = new Vector3(offset.x, offset.y, 0f);

            #region Highlight Code
            // If previously got hit other object
            if (hitTransform)
            {
                // Disable highlight for hit object and its children
                var o = hitTransform.GetComponentsInChildren <Outline>();
                foreach (var oL in o)
                {
                    if (!oL.selected)
                    {
                        oL.enabled = false;
                    }
                }
            }

            // When the game is not paused, menus not active and selected button is not pause nor guide image
            if (PauseManager.Instance != null && !PauseManager.Instance.isPaused && !foodListPanel.activeSelf && !ingredientListPanel.activeSelf &&
                selectedButton.name != "Pause" && selectedButton.name != "GuideImage")
            {
                // If selecting Cooking Appliance(Frying Pan, Pot 1, Pot 2)
                if (LevelManager.Instance.cookingAppliances.Any(x => x.gameObject.GetInstanceID() == selectedButton.transform.parent.parent.gameObject.GetInstanceID()))
                {
                    var something = LevelManager.Instance.cookingAppliances.Where(x => x.gameObject.GetInstanceID() == selectedButton.transform.parent.parent.gameObject.GetInstanceID()).ToList();

                    if (something.Count != 1)
                    {
                        return;
                    }

                    var app = something[0].GetComponent <CookingAppliance>();

                    app.OpenCloseHint(true);
                    app.OpenCloseCanvas(true);
                }
                // When Carrying food
                else if (foodSO)
                {
                    // If selecting customer
                    if (CustomerSpawner.Instance.customerDic.Any(x => x.Value.gameObject.GetInstanceID() == selectedButton.transform.parent.parent.gameObject.GetInstanceID()))
                    {
                        var something = CustomerSpawner.Instance.customerDic.Where(x => x.Value.gameObject.GetInstanceID() == selectedButton.transform.parent.parent.gameObject.GetInstanceID()).ToList();

                        if (something.Count != 1)
                        {
                            return;
                        }

                        var customer = something[0].Value.GetComponent <Customer>();

                        hitTransform = customer.transform;
                        ShowOutline(customer.gameObject);
                    }
                }
            }
            #endregion Highlight Code

            // When hand timer reach limit
            if (handElapsedTime >= handTimer)
            {
                // Reset Hand Timer, Frame, and Flower image
                handElapsedTime       = 0f;
                timerImage.fillAmount = 0f;
                timerImage2.gameObject.SetActive(false);
                angle = -(timerImage.fillAmount * 360f + 90f) * Mathf.Deg2Rad;
                var offset1 = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;
                timerImage2.transform.localPosition = new Vector3(offset1.x, offset1.y, 0f);

                selectedButton.OnPointerClick(eventData);

                // When the game is not paused, menus not active and selected button is not pause
                if (PauseManager.Instance != null && !PauseManager.Instance.isPaused && !foodListPanel.activeSelf && !ingredientListPanel.activeSelf &&
                    selectedButton.name != "Pause")
                {
                    // Do not do anything if haven't finish guiding about intro and order
                    if (selectedButton.name == "GuideImage")
                    {
                        if (!selectedButton.GetComponent <Guide>().finishedIntro || !selectedButton.GetComponent <Guide>().finishedOrder)
                        {
                            return;
                        }
                    }

                    // If selecting Cooking Appliance(Frying Pan, Pot 1, Pot 2)
                    else if (LevelManager.Instance.cookingAppliances.Any(x => x.gameObject.GetInstanceID() == selectedButton.transform.parent.parent.gameObject.GetInstanceID()))
                    {
                        var something = LevelManager.Instance.cookingAppliances.Where(x => x.gameObject.GetInstanceID() == selectedButton.transform.parent.parent.gameObject.GetInstanceID()).ToList();

                        if (something.Count != 1)
                        {
                            return;
                        }

                        var app = something[0].GetComponent <CookingAppliance>();

                        // Haven't done cooking food
                        if (!app.isDone)
                        {
                            // Open up Food list to choose "food to cook"
                            app.OpenCloseFoodMenu(true);

                            // If the game is in Tutorial Scene and Guide Image is not active
                            if (Menu_Manager.Instance.Tutorial_Mode && !Guide.Instance.gameObject.activeSelf)
                            {
                                // If haven't guide cook, start guiding
                                if (!Guide.Instance.CheckIfGuidedCook())
                                {
                                    Guide.Instance.Show();
                                }
                            }
                        }
                        // Done cooking food
                        else
                        {
                            // If previously selected another cooking Appliance
                            if (cookingAppliance)
                            {
                                DropItem(cookingAppliance);
                            }

                            // Select food and store it for serving customer
                            cookingAppliance = app.gameObject;
                            foodSO           = app.TakeFood();

                            // Allow interactions with customer when holding food
                            foreach (var pair in CustomerSpawner.Instance.customerDic)
                            {
                                pair.Value.AllowHover(true);
                            }

                            // Change Hand Sprite to Food Sprite
                            background.sprite = foodSO.sprite;
                        }
                    }
                    // When Carrying food
                    else if (foodSO)
                    {
                        // If selecting customer
                        if (CustomerSpawner.Instance.customerDic.Any(x => x.Value.gameObject.GetInstanceID() == selectedButton.transform.parent.parent.gameObject.GetInstanceID()))
                        {
                            var something = CustomerSpawner.Instance.customerDic.Where(x => x.Value.gameObject.GetInstanceID() == selectedButton.transform.parent.parent.gameObject.GetInstanceID()).ToList();

                            if (something.Count != 1)
                            {
                                return;
                            }

                            var customer = something[0].Value.GetComponent <Customer>();

                            // When customer is not fighting
                            if (!customer.fighting)
                            {
                                // Serve Correct
                                if (foodSO == customer.foodOrdered)
                                {
                                    // Set customer's animations and sound effect
                                    customer.SetAnim(customer.idle, false);
                                    customer.SetAnim(customer.happy, true);
                                    customer.SetClip(Audio_Manager.Instance.audioDictionary["Coin Drop"]);

                                    // Served correct food, Add Score
                                    Score.Instance.Profit(customer.foodOrdered, customer.timerImage.fillAmount);

                                    // Customer leaves
                                    customer.Leave();
                                }
                                // Serve Wrong
                                else
                                {
                                    // Set customer's animations
                                    customer.SetAnim(customer.idle, false);
                                    customer.SetAnim(customer.angry, true);

                                    // Served wrong food, Decrease Rate
                                    Score.Instance.rate -= 0.1f;
                                    customer.fighting    = true;

                                    foreach (CookingAppliance appliance in LevelManager.Instance.cookingAppliances)
                                    {
                                        if (!appliance.isDone)
                                        {
                                            appliance.NewFood();
                                        }
                                    }

                                    customer.player = Player.Instance.transform;

                                    // If the game is in Tutorial Scene
                                    if (Guide.Instance != null)
                                    {
                                        Guide.Instance.gameObject.SetActive(true);
                                    }
                                }

                                // Disable interactions with customer
                                foreach (var pair in CustomerSpawner.Instance.customerDic)
                                {
                                    pair.Value.AllowHover(false);
                                }

                                // Reset cooking Appliance status
                                CookingAppliance app = cookingAppliance.GetComponent <CookingAppliance>();
                                app.NewFood();

                                // Drop food
                                DropItem(cookingAppliance);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            // Disable highlight for every objects that have outline
            var ol = FindObjectsOfType <Outline>();
            foreach (var oL in ol)
            {
                if (!oL.selected)
                {
                    oL.enabled = false;
                }
            }
        }

        // If any customer is fighting with player
        if (CustomerSpawner.Instance.customerDic.Any(x => x.Value.fighting == true))
        {
            // If the game is in Pause Status, do not do anything
            if (PauseManager.Instance != null && PauseManager.Instance.isPaused)
            {
                return;
            }

            var something = CustomerSpawner.Instance.customerDic.Where(x => x.Value.fighting == true).ToList();

            foreach (var pair in something)
            {
                var customer = pair.Value.GetComponent <Customer>();

                // Set player transform for customer to have a target to shoot at
                if (!customer.player)
                {
                    customer.player = Player.Instance.transform;
                }
            }

            // If menus are inactive and player is performing Grab Gesture
            if (!foodListPanel.activeSelf && !ingredientListPanel.activeSelf && press)
            {
                // Runs timer
                shootingElapsedTime += Time.deltaTime;

                // When timer reach limit
                if (shootingElapsedTime >= shootingTimer)
                {
                    // Reset timer
                    shootingElapsedTime = 0f;

                    // Shoot bullet towards hand icon
                    GameObject Projectile = ObjectPool.Instance.GetPooledObject(ProjectilePrefab);

                    // If projectile is not Null
                    if (!Projectile)
                    {
                        return;
                    }

                    // Initialise position and direction of projectile
                    Projectile.transform.position = transform.position;
                    Projectile.GetComponent <Projectile>().dir = (transform.position - cam.transform.position).normalized;
                }
            }
        }
    }
    void ProcessHands(nuitrack.HandTrackerData data)
    {
        if (data.NumUsers > 0)
        {
            for (int i = 0; i < data.UsersHands.Length; i++)
            {
                int userId = data.UsersHands[i].UserId;

                if (!hands.ContainsKey(userId))
                {
                    hands.Add(userId, new Image[2]);
                    GameObject leftHand  = (GameObject)Instantiate(handUIPrefab);
                    GameObject rightHand = (GameObject)Instantiate(handUIPrefab);

                    leftHand.transform.SetParent(handsContainer, false);
                    rightHand.transform.SetParent(handsContainer, false);

                    hands[userId][0] = leftHand.GetComponent <Image>();
                    hands[userId][1] = rightHand.GetComponent <Image>();

                    hands[userId][0].enabled = false;
                    hands[userId][1].enabled = false;
                    hands[userId][0].color   = leftColor;
                    hands[userId][1].color   = rightColor;
                }
            }

            foreach (KeyValuePair <int, Image[]> kvp in hands)
            {
                nuitrack.UserHands userHands = data.GetUserHandsByID(kvp.Key);
                if (userHands == null)
                {
                    hands[kvp.Key][0].enabled = false;
                    hands[kvp.Key][1].enabled = false;
                }
                else
                {
                    if ((userHands.LeftHand == null) || (userHands.LeftHand.Value.X == -1f))
                    {
                        hands[kvp.Key][0].enabled = false;
                    }
                    else
                    {
                        hands[kvp.Key][0].enabled = true;
                        Vector2 pos = new Vector2(userHands.LeftHand.Value.X, 1f - userHands.LeftHand.Value.Y);
                        hands[kvp.Key][0].rectTransform.anchorMin = pos;
                        hands[kvp.Key][0].rectTransform.anchorMax = pos;
                        hands[kvp.Key][0].rectTransform.sizeDelta = userHands.LeftHand.Value.Click ? new Vector2(sizeClick, sizeClick) : new Vector2(sizeNormal, sizeNormal);
                    }

                    if ((userHands.RightHand == null) || (userHands.RightHand.Value.X == -1f))
                    {
                        hands[kvp.Key][1].enabled = false;
                    }
                    else
                    {
                        hands[kvp.Key][1].enabled = true;
                        Vector2 pos = new Vector2(userHands.RightHand.Value.X, 1f - userHands.RightHand.Value.Y);
                        hands[kvp.Key][1].rectTransform.anchorMin = pos;
                        hands[kvp.Key][1].rectTransform.anchorMax = pos;
                        hands[kvp.Key][1].rectTransform.sizeDelta = userHands.RightHand.Value.Click ? new Vector2(sizeClick, sizeClick) : new Vector2(sizeNormal, sizeNormal);
                    }
                }
            }
        }
        else
        {
            foreach (KeyValuePair <int, Image[]> kvp in hands)
            {
                kvp.Value[0].enabled = false;
                kvp.Value[1].enabled = false;
            }
        }
    }
    public bool PollBodyFrame(KinectInterop.SensorData sensorData, ref KinectInterop.BodyFrameData bodyFrame,
                              ref Matrix4x4 kinectToWorld, bool bIgnoreJointZ)
    {
        bool bNewFrame = false;

        // look for skeleton frame
        if (skeletonData != null && skeletonDataTimestamp != lastSkeletonFrameTimestamp)
        {
            lastSkeletonFrameTimestamp = skeletonDataTimestamp;
            //long timeNowTicks = DateTime.Now.Ticks;

            bodyFrame.liPreviousTime = bodyFrame.liRelativeTime;
            bodyFrame.liRelativeTime = skeletonDataTimestamp;

            int bodyCount = skeletonData.Skeletons != null ? skeletonData.Skeletons.Length : 0;
            if (lastBodyCount != bodyCount)
            {
                sbDebugBodies.Append(bodyCount).Append(" bodies - ");
            }

            // clear id2index
            //bodyIdToIndex.Clear();

            // create bodyIndexUsed-array on the 1st use
            if (bodyIndexUsed == null)
            {
                bodyIndexUsed = new bool[sensorData.bodyCount];
            }

            // clear the tracked flags and find empty index
            int eIndex = -1;

            for (int i = 0; i < sensorData.bodyCount; i++)
            {
                bodyFrame.bodyData[i].bIsTracked = 0;

                if (eIndex < 0 && !bodyIndexUsed[i])
                {
                    eIndex = i;
                }
            }

            for (int i = 0; i < sensorData.bodyCount; i++)
            {
                // compare to real body count
                if (i >= bodyCount)
                {
                    //bodyFrame.bodyData[i].bIsTracked = 0;
                    continue;
                }

                // get body and joints data
                nuitrack.Skeleton nuiBody = skeletonData.Skeletons[i];
                if (lastBodyCount != bodyCount)
                {
                    sbDebugBodies.Append(nuiBody.ID).Append(":");

                    nuitrack.Joint jUser    = nuiBody.Joints[(int)nuitrack.JointType.Waist];
                    Vector3        vUserPos = new Vector3(dontHFlipBodyFrame ? jUser.Real.X : -jUser.Real.X, jUser.Real.Y, jUser.Real.Z);
                    sbDebugBodies.Append(vUserPos);

                    sbDebugBodies.Append("  ");
                }

                // create the body index if needed
                ushort uBodyId = (ushort)nuiBody.ID;
                if (!bodyIdToIndex.ContainsKey(uBodyId))
                {
                    Debug.Log("  New body ID:" + uBodyId + ", index: " + eIndex);

                    bodyIdToIndex[uBodyId] = (byte)eIndex;
                    bodyIndexUsed[eIndex]  = true;
                }

                // get existing body index
                int bi = bodyIdToIndex[uBodyId];
                bodyIdToTime[uBodyId] = Time.time;

                // set body tracking state
                bodyFrame.bodyData[bi].bIsTracked = 1;

                // transfer body and joints data
                bodyFrame.bodyData[bi].liTrackingID = (long)nuiBody.ID;
                //bodyIdToIndex[(ushort)nuiBody.ID] = (byte)i;

                // z-position of the waist
                float waistPosZ = nuiBody.Joints[(int)nuitrack.JointType.Waist].Real.Z / 1000f;

                for (int j = 0; j < sensorData.jointCount; j++)
                {
                    KinectInterop.JointData jointData = bodyFrame.bodyData[bi].joint[j];

                    int nuiJI = !dontHFlipBodyFrame ? BodyJoint2NormalNuitrackJoint[j] : BodyJoint2MirroredNuitrackJoint[j];

                    if (nuiJI >= 0)
                    {
                        nuitrack.Joint nuiJoint = nuiBody.Joints[nuiJI];

                        if (nuiJoint.Confidence >= 0.5f)
                        {
                            jointData.trackingState = KinectInterop.TrackingState.Tracked;
                        }
                        else if (nuiJoint.Confidence >= 0.1f)
                        {
                            jointData.trackingState = KinectInterop.TrackingState.Inferred;
                        }
                        else
                        {
                            jointData.trackingState = KinectInterop.TrackingState.NotTracked;
                        }

                        Vector3 jointPos = new Vector3((dontHFlipBodyFrame ? nuiJoint.Real.X : -nuiJoint.Real.X) / 1000f, nuiJoint.Real.Y / 1000f, nuiJoint.Real.Z / 1000f);
                        float   jPosZ    = (bIgnoreJointZ && j > 0) ? waistPosZ : jointPos.z;

                        jointData.kinectPos = jointPos;
                        jointData.position  = kinectToWorld.MultiplyPoint3x4(new Vector3(jointPos.x, jointPos.y, jPosZ));

                        jointData.orientation = Quaternion.identity;
                    }
                    else
                    {
                        jointData.trackingState = KinectInterop.TrackingState.NotTracked;
                    }

                    if (j == 0)
                    {
                        bodyFrame.bodyData[bi].position    = jointData.position;
                        bodyFrame.bodyData[bi].orientation = jointData.orientation;
                    }

                    bodyFrame.bodyData[bi].joint[j] = jointData;
                }

                if (handTrackerData != null)
                {
                    nuitrack.UserHands hands = handTrackerData.GetUserHandsByID(nuiBody.ID);

                    if (hands != null)
                    {
                        nuitrack.HandContent?leftHand = !dontHFlipBodyFrame ? hands.LeftHand : hands.RightHand;
                        bodyFrame.bodyData[bi].leftHandState      = leftHand.HasValue && leftHand.Value.Click ? KinectInterop.HandState.Closed : KinectInterop.HandState.Open;
                        bodyFrame.bodyData[bi].leftHandConfidence = leftHand.HasValue ? KinectInterop.TrackingConfidence.High : KinectInterop.TrackingConfidence.Low;

                        nuitrack.HandContent?rightHand = !dontHFlipBodyFrame ? hands.RightHand : hands.LeftHand;
                        bodyFrame.bodyData[bi].rightHandState      = rightHand.HasValue && rightHand.Value.Click ? KinectInterop.HandState.Closed : KinectInterop.HandState.Open;
                        bodyFrame.bodyData[bi].rightHandConfidence = rightHand.HasValue ? KinectInterop.TrackingConfidence.High : KinectInterop.TrackingConfidence.Low;
                    }
                }

                // processes some special joint cases
                ProcessBodyFrameSpecialCases(bi, ref bodyFrame);
            }

            // check for lost users
            List <ushort> lostUsers = new List <ushort>();

            foreach (ushort uBodyId in bodyIdToTime.Keys)
            {
                // prevent user removal upon sporadical tracking failures
                if ((Time.time - bodyIdToTime[uBodyId]) > waitTimeBeforeRemove)
                {
                    lostUsers.Add(uBodyId);
                }
            }

            // remove the lost users
            if (lostUsers.Count > 0)
            {
                foreach (ushort uBodyId in lostUsers)
                {
                    Debug.Log("  Lost body ID:" + uBodyId + ", index: " + bodyIdToIndex[uBodyId]);

                    int bi = bodyIdToIndex[uBodyId];
                    bodyIndexUsed[bi] = false;

                    bodyIdToIndex.Remove(uBodyId);
                    bodyIdToTime.Remove(uBodyId);
                }

                // clean up
                lostUsers.Clear();
            }

            // write bodies-debug info, if needed
            if (sbDebugBodies.Length > 0)
            {
                sbDebugBodies.Append("Time: ").Append(Time.realtimeSinceStartup);
                Debug.Log(sbDebugBodies.ToString());

                sbDebugBodies.Remove(0, sbDebugBodies.Length);
            }

            lastBodyCount = bodyCount;
            bNewFrame     = true;
        }

        return(bNewFrame);
    }
    private void NuitrackManager_onHandsTrackerUpdate(nuitrack.HandTrackerData handTrackerData)
    {
        active = false;
        press  = false;

        if (handTrackerData != null)
        {
            nuitrack.UserHands userHands = handTrackerData.GetUserHandsByID(CurrentUserTracker.CurrentUser);

            if (userHands != null)
            {
                if (currentHand == Hands.right && userHands.RightHand != null)
                {
                    baseRect.anchoredPosition = new Vector2(userHands.RightHand.Value.X * Screen.width, -userHands.RightHand.Value.Y * Screen.height);
                    active = true;
                    press  = userHands.RightHand.Value.Click;
                }
                else if (currentHand == Hands.left && userHands.LeftHand != null)
                {
                    baseRect.anchoredPosition = new Vector2(userHands.LeftHand.Value.X * Screen.width, -userHands.LeftHand.Value.Y * Screen.height);
                    active = true;
                    press  = userHands.LeftHand.Value.Click;
                }
            }
        }

        background.enabled = active;
        background.sprite  = active && press ? pressSprite : defaultSprite;

        if (!active)
        {
            return;
        }

        Vector2 pointOnScreenPosition = cam.WorldToScreenPoint(transform.position);

        eventData.delta    = pointOnScreenPosition - eventData.position;
        eventData.position = pointOnScreenPosition;

        raycastResults.Clear();
        EventSystem.current.RaycastAll(eventData, raycastResults);

        ImageItem newButton = null;

        for (int i = 0; i < raycastResults.Count && newButton == null; i++)
        {
            newButton = raycastResults[i].gameObject.GetComponent <ImageItem>();
        }

        if (newButton != selectedButton)
        {
            if (selectedButton != null)
            {
                selectedButton.OnPointerExit(eventData);
            }

            selectedButton = newButton;

            if (selectedButton != null)
            {
                selectedButton.OnPointerEnter(eventData);
            }
        }
        else if (selectedButton != null)
        {
            if (press)
            {
                if (eventData.delta.sqrMagnitude < dragSensitivity && !eventData.dragging)
                {
                    eventData.dragging = true;
                    selectedButton.OnPointerDown(eventData);
                }
            }
            else if (eventData.dragging)
            {
                eventData.dragging = false;
                selectedButton.OnPointerUp(eventData);
            }

            if (press)
            {
                selectedButton.OnDrag(eventData);
            }
        }
    }