Exemplo n.º 1
0
 public void Close()
 {
     currentAppliance.NewFood();
     currentAppliance = null;
     currentFood      = null;
 }
Exemplo n.º 2
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;
                }
            }
        }
    }