Esempio n. 1
0
 // This is a controller event subscription.  It executes when the event takes place.
 private void PadClicked(object sender, ClickedEventArgs e)
 {
     if (hit.transform.tag == "Button")
     {
         Button            menuButton          = eventController.button;
         GameObject        contextMenuSystemGO = GameObject.FindGameObjectWithTag("ContextMenuSystem");
         ContextMenuSystem contextMenuSystem   = contextMenuSystemGO.GetComponent <ContextMenuSystem>();
         if (menuButton)
         {
             if (menuButton.name == "EXIT")
             {
                 eventController.DestroyContextMenu();
             }
             else
             {
                 eventController.buttonClicked     = menuButton;
                 contextMenuSystem.IsButtonClicked = true;
             }
         }
     }
     if (hit.transform.tag != "Button")
     {
         eventController.DestroyContextMenu();
     }
 }
    private void Update()
    {
        if (menuOpen)
        {
            myState = States.menuActive;
        }

        if (!menuOpen)
        {
            //IF there is no colliding object in any instance of the ControllerGrabObject script (on either controller)
            //  THEN -> turn the freeRoam state back on.
            GameObject[] controllers = GameObject.FindGameObjectsWithTag("Controllers");
            objectInEitherHand = false;

            foreach (GameObject obj in controllers)
            {
                // IF there is a colliding object
                if (collidingObject)
                {
                    objectInEitherHand = true;
                    //print(collidingObject);
                }
            }
            if (!objectInEitherHand)
            {
                myState = States.freeRoam;
            }
        }

        if (myState == States.freeRoam)
        {
            if (!parabolicPointerOn)
            {
                if (!menuOpen)
                {
                    TurnOnParabolicPointer();
                }
            }
        }
        else if (myState == States.objectHighlighted)
        {
            if (parabolicPointerOn)
            {
                TurnOffParabolicPointer();
            }

            if (touchpadPressed)
            {
                touchpadPressed = false;
                if ((collidingObject.tag == "Untagged") || (collidingObject.tag == "Button") || (collidingObject.tag == "CleanButton"))
                {
                    return;
                }
                if (!menuOpen && !objectInHand)
                {
                    GameObject menuInScene = GameObject.FindGameObjectWithTag("ContextMenuSystem");
                    //If there is not menuInScene already, go ahead and create teh contextMenu gameobject.
                    if (menuInScene == null)
                    {
                        contextMenu = Instantiate(contextMenuSystem) as GameObject;
                        Vector3 offsetPos = new Vector3(0, 0.25f, 0.25f);
                        Vector3 newPos    = collidingObject.transform.position + offsetPos;
                        contextMenu.transform.position = newPos;

                        contextMenuScript           = contextMenu.GetComponent <ContextMenuSystem>();
                        contextMenuScript.menuState = ContextMenuSystem.SelectionStates.level_1;
                        TurnOffControllerBalls();

                        ResetShelfProductsList();
                        shelfProducts.Add(collidingObject);

                        contextMenuScript.contextMenuObjHighlighted = collidingObject;
                        objectSelected  = collidingObject;
                        collidingObject = null;
                        myState         = States.menuActive;
                        menuOpen        = true;
                    }
                }
                #region TURN ON MATERIAL PANELS
                if (!objectInHand)
                {
                    if (objectSelected.tag == "PasteBox_4.2oz_Horizontal")
                    {
                        // NOTE:  When you search using TAG it will search all project folders (including prefabs!!!).
                        // This is why it could find it using the TAG and not the name.  I wasn't grabbing the instance!!!!
                        GameObject  contextMenuTemp = GameObject.Find("UIContextMenuSystem(Clone)");
                        Transform[] transforms      = contextMenuTemp.GetComponentsInChildren <Transform>();
                        for (int i = 0; i < transforms.Length; i++)
                        {
                            if (transforms[i].gameObject.tag == "Menu_4.2oz_PasteBox_Horizontal")
                            {
                                //print("I found: "+ transforms[i].gameObject.name);
                                transforms[i].gameObject.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f);
                                //print("The " + transforms[i].gameObject.name + " localScale is: " + transforms[i].gameObject.GetComponent<RectTransform>().localScale);
                            }
                        }
                    }
                    else if (objectSelected.tag == "PasteBox_4.1oz_Vertical")
                    {
                        GameObject  contextMenuTemp = GameObject.Find("UIContextMenuSystem(Clone)");
                        Transform[] transforms      = contextMenuTemp.GetComponentsInChildren <Transform>();
                        foreach (Transform trans in transforms)
                        {
                            if (trans.gameObject.tag == "Menu_4.1oz_PasteBox_Vertical")
                            {
                                trans.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f);
                            }
                        }
                    }
                    else if (objectSelected.tag == "Rinse_16oz")
                    {
                        GameObject  contextMenuTemp = GameObject.Find("UIContextMenuSystem(Clone)");
                        Transform[] transforms      = contextMenuTemp.GetComponentsInChildren <Transform>();
                        foreach (Transform trans in transforms)
                        {
                            if (trans.gameObject.tag == "Menu_16oz_Rinse")
                            {
                                trans.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f);
                            }
                        }
                    }
                    else if (objectSelected.tag == "Fixodent_2.4oz")
                    {
                        GameObject  contextMenuTemp = GameObject.Find("UIContextMenuSystem(Clone)");
                        Transform[] transforms      = contextMenuTemp.GetComponentsInChildren <Transform>();
                        foreach (Transform trans in transforms)
                        {
                            if (trans.gameObject.tag == "Menu_Fixodent")
                            {
                                trans.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f);
                            }
                        }
                    }
                    else if (objectSelected.tag == "Toms_4.7oz")
                    {
                        GameObject  contextMenuTemp = GameObject.Find("UIContextMenuSystem(Clone)");
                        Transform[] transforms      = contextMenuTemp.GetComponentsInChildren <Transform>();
                        foreach (Transform trans in transforms)
                        {
                            if (trans.gameObject.tag == "Menu_4.7oz_PasteBox")
                            {
                                trans.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f);
                            }
                        }
                    }
                }
                #endregion
            }
        }
        else if (myState == States.objectInHand)
        {
            if (parabolicPointerOn)
            {
                TurnOffParabolicPointer();
            }
        }
        else if (myState == States.menuActive)
        {
            if (parabolicPointerOn)
            {
                TurnOffParabolicPointer();
            }
            if (!laserPointerOn)
            {
                TurnOnLaserPointer();
            }
            MenuExitingCheck();
        }
    }