コード例 #1
0
    private void OnTriggerStay(Collider other)
    {
        //Detectamos los paneles que hemos soltado y aún no hemos colocado
        //if (other.tag == "panel" && !other.gameObject.transform.GetComponent<OVRGrabbable>().isGrabbed)
        //{

        if (other.tag == "panel" && !other.GetComponent <OVRGrabbable>().isGrabbed&& !other.GetComponent <panelScript>().getIsInPanel())
        {
            AudioSource.PlayClipAtPoint(Resources.Load <AudioClip>("Audio/panelSound"), other.transform.position, 1.0f);
            //Queremos la posicion encima del panel y debajo de la ultima instruccion que se ha añadido.
            //Si no hemos puesto ninguna instrucción, simplemente lo posicionamos arriba de todo del panel

            if (currentHamburguer.getInstructions().Count == 0)
            {
                other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, this.transform.position.y + 0.9f, this.transform.position.z);
                other.gameObject.transform.rotation = Quaternion.Euler(180, 180, 90);

                currentHamburguer.addInstruction(other.gameObject);

                //New
                if (other.GetComponent <panelScript>().getIsFor() || other.GetComponent <panelScript>().getIsIf())
                {
                    //Añadimos como instruccion el closing
                    currentHamburguer.addInstruction(other.gameObject.transform.GetChild(2).gameObject);
                }

                other.gameObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                other.gameObject.GetComponent <panelScript>().setIsInPanel(true);
                //New
                if (other.GetComponent <panelScript>().getIsIfElse())
                {
                    //Añadimos como instruccion el else y el closing
                    currentHamburguer.addInstruction(other.gameObject.transform.GetChild(2).gameObject);
                    currentHamburguer.addInstruction(other.gameObject.transform.GetChild(4).gameObject);
                }
                if (!other.gameObject.GetComponent <panelScript>().getItWasInPanel())
                {
                    GameControllerWaiter.current.createPanel(other.name);
                }

                //Si el freeze no está dentro se caen los paneles
            }

            //Si el panel que estoy poniendo no lo coloco entre ninguna de los paneles ya existentes, se coloca justo debajo.
            else if (other.gameObject.transform.position.y < currentHamburguer.getLastInstruction().transform.position.y)
            {
                other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, currentHamburguer.getLastInstruction().transform.position.y - conditionalSeparationAxisY, this.transform.position.z);

                other.gameObject.transform.rotation = Quaternion.Euler(180, 180, 90);
                currentHamburguer.addInstruction(other.gameObject);

                //Congelamos la posición del panel. Si el freeze no está dentro del if/else se caen los paneles.
                other.gameObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;

                //New. Añadimos el ClosingPanel como ingrediente
                if (other.GetComponent <panelScript>().getIsFor() || other.GetComponent <panelScript>().getIsIf())
                {
                    currentHamburguer.addInstruction(other.gameObject.transform.GetChild(2).gameObject);
                }

                //New
                if (other.GetComponent <panelScript>().getIsIfElse())
                {
                    //Añadimos como instruccion el else y el closing
                    currentHamburguer.addInstruction(other.gameObject.transform.GetChild(2).gameObject);
                    currentHamburguer.addInstruction(other.gameObject.transform.GetChild(4).gameObject);
                }
                other.gameObject.GetComponent <panelScript>().setIsInPanel(true);

                if (other.gameObject.GetComponent <panelScript>().getItWasInPanel())
                {
                    reOrderFunction(other);
                }

                //Volvemos a crear los paneles que se añaden al panel principal.
                //Sólo lo hacemos para los paneles que aún no han sido utilizados.
                else
                {
                    GameControllerWaiter.current.createPanel(other.name);
                }

                UndoManager.current.addCurrentObject(other.gameObject);
            }


            //En cualquier otro caso la instrucción estará entre otras dos ya existentes.
            else
            {
                int i = 0;

                //Recorremos los ingredientes hasta que encontremos entre que dos paneles hemos puesto el nuevo panel
                while (!other.gameObject.GetComponent <panelScript>().getIsInPanel() || i == currentHamburguer.getInstructions().Count - 1)
                {
                    if (other.gameObject.transform.position.y < ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y && other.gameObject.transform.position.y > ((GameObject)currentHamburguer.getInstructions()[i + 1]).transform.position.y)
                    {
                        //Este debería ser parte del else, pero si no lo pongo, se buguea cuando intento colocar entre el closingPanel y otro panel
                        if (((GameObject)currentHamburguer.getInstructions()[i]).name == "ClosingPanel")
                        {
                            //Colocamos entre dos paneles básicos
                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);

                            //Colocamos la nueva instruccion entre los dos paneles
                            other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - other.transform.localScale.x, this.transform.position.z);
                        }
                        else if (((GameObject)currentHamburguer.getInstructions()[i]).name == "ElsePanel")
                        {
                            //Colocamos entre el else y closing panel
                            GameObject ifElsePanel = ((GameObject)currentHamburguer.getInstructions()[i]).transform.parent.gameObject;

                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);
                            //other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - conditionalSeparationAxisY, this.transform.position.z + conditionalSeparationAxisZ);
                            other.gameObject.transform.position = new Vector3(1, 1, 1);

                            other.gameObject.GetComponent <panelScript>().setIsInElse(true);
                            other.gameObject.GetComponent <panelScript>().setIsInIfElse(true);
                            other.gameObject.GetComponent <panelScript>().setIsInside(ifElsePanel);
                            ifElsePanel.GetComponent <panelScript>().setPanelsInsideElse(ifElsePanel.GetComponent <panelScript>().getPanelsInsideElse() + 1);
                            //Congelamos la posición del panel. Si el freeze no está dentro del if/else se caen los paneles.
                        }

                        else if (((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsInElse())
                        {
                            //Colocamos entre dos paneles de dentro del if
                            GameObject IfElsePanel = ((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsInside();

                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);
                            other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - other.transform.localScale.x, this.transform.position.z + conditionalSeparationAxisZ);
                            other.gameObject.GetComponent <panelScript>().setIsInElse(true);
                            other.gameObject.GetComponent <panelScript>().setIsInIfElse(true);

                            other.gameObject.GetComponent <panelScript>().setIsInside(IfElsePanel);

                            IfElsePanel.GetComponent <panelScript>().setPanelsInsideElse(IfElsePanel.GetComponent <panelScript>().getPanelsInsideElse() + 1);
                        }


                        else if (((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsIfElse())
                        {
                            //Colocamos entre el If y closing panel
                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);
                            other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - conditionalSeparationAxisY, this.transform.position.z + conditionalSeparationAxisZ);
                            other.gameObject.GetComponent <panelScript>().setIsInIf(true);

                            other.gameObject.GetComponent <panelScript>().setIsInIfElse(true);
                            other.gameObject.GetComponent <panelScript>().setIsInside((GameObject)currentHamburguer.getInstructions()[i]);
                            ((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().setPanelsInsideIf(((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getPanelsInsideIf() + 1);
                            //Congelamos la posición del panel. Si el freeze no está dentro del if/else se caen los paneles.
                        }

                        else if (((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsInIf() && ((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsInIfElse())
                        {
                            //Colocamos entre dos paneles de dentro del if
                            GameObject IfElsePanel = ((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsInside();

                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);
                            other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - other.transform.localScale.x, this.transform.position.z + conditionalSeparationAxisZ);
                            other.gameObject.GetComponent <panelScript>().setIsInIf(true);
                            other.gameObject.GetComponent <panelScript>().setIsInIfElse(true);

                            IfElsePanel.GetComponent <panelScript>().setPanelsInsideIf(IfElsePanel.GetComponent <panelScript>().getPanelsInsideIf() + 1);

                            other.gameObject.GetComponent <panelScript>().setIsInside(IfElsePanel);
                        }

                        else if (((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsFor())
                        {
                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);
                            other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - conditionalSeparationAxisY, this.transform.position.z + conditionalSeparationAxisZ);
                            other.gameObject.GetComponent <panelScript>().setIsInFor(true);
                            other.gameObject.GetComponent <panelScript>().setIsInside((GameObject)currentHamburguer.getInstructions()[i]);
                            ((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().setPanelsInside(((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getPanelsInside() + 1);
                            //Congelamos la posición del panel. Si el freeze no está dentro del if/else se caen los paneles.
                        }
                        else if (((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsInFor())
                        {
                            //Colocamos entre dos paneles for
                            GameObject forTwoPanel = ((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsInside();

                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);
                            other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - other.transform.localScale.x, this.transform.position.z + conditionalSeparationAxisZ);
                            other.gameObject.GetComponent <panelScript>().setIsInFor(true);

                            forTwoPanel.GetComponent <panelScript>().setPanelsInside(forTwoPanel.GetComponent <panelScript>().getPanelsInside() + 1);

                            other.gameObject.GetComponent <panelScript>().setIsInside(forTwoPanel);
                        }

                        else if (((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsIf())
                        {
                            //Colocamos entre el If y closing panel
                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);
                            other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - conditionalSeparationAxisY, this.transform.position.z + conditionalSeparationAxisZ);
                            other.gameObject.GetComponent <panelScript>().setIsInIf(true);
                            other.gameObject.GetComponent <panelScript>().setIsInside((GameObject)currentHamburguer.getInstructions()[i]);
                            ((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().setPanelsInside(((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getPanelsInside() + 1);
                            //Congelamos la posición del panel. Si el freeze no está dentro del if/else se caen los paneles.
                        }

                        else if (((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsInIf())
                        {
                            //Colocamos entre dos paneles de dentro del if
                            GameObject IfPanel = ((GameObject)currentHamburguer.getInstructions()[i]).GetComponent <panelScript>().getIsInside();

                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);
                            other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - other.transform.localScale.x, this.transform.position.z + conditionalSeparationAxisZ);
                            other.gameObject.GetComponent <panelScript>().setIsInIf(true);

                            IfPanel.GetComponent <panelScript>().setPanelsInside(IfPanel.GetComponent <panelScript>().getPanelsInside() + 1);

                            other.gameObject.GetComponent <panelScript>().setIsInside(IfPanel);
                        }

                        //Aquí no entra cuando sacamos una instrucción de un panel especial y lo ponemos debajo del closing
                        else
                        {
                            //Colocamos entre dos paneles básicos
                            other.gameObject.GetComponent <panelScript>().setIsInPanel(true);

                            //Colocamos la nueva instruccion entre los dos paneles
                            other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)currentHamburguer.getInstructions()[i]).transform.position.y - other.transform.localScale.x, this.transform.position.z);
                        }

                        //Insertamos la instrucción a la lista justo delante de la que estamos obeservando en ese momento
                        currentHamburguer.insertInstruction(i + 1, other.gameObject);

                        other.gameObject.transform.rotation = Quaternion.Euler(180, 180, 90);
                        other.gameObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                        //New
                        if (other.GetComponent <panelScript>().getIsFor() || other.GetComponent <panelScript>().getIsIf())
                        {
                            currentHamburguer.insertInstruction(i + 2, other.gameObject.transform.GetChild(2).gameObject);
                        }

                        //Si no ha estado en el panel creamos otro panel encima de la mesa cuando lo pongamos
                        if (!other.gameObject.GetComponent <panelScript>().getItWasInPanel())
                        {
                            GameControllerWaiter.current.createPanel(other.name);
                        }

                        //Cuando acabmos de colocar el panel entre otros dos paneles, recolocamos los paneles. Cambiar el método y sacar el for del metodo
                        reOrderFunction(other);
                    }
                    else
                    {
                        i++;
                    }
                }
            }
        }
    }
コード例 #2
0
    private void OnTriggerStay(Collider other)
    {
        //Detectamos los paneles que hemos soltado y aún no hemos colocado

        if (other.tag == "panel" && !other.GetComponent <OVRGrabbable>().isGrabbed&& !other.GetComponent <panelScriptTutorial>().getIsInPanel())
        {
            if (current_hamburguer.getInstructions().Count == 0)
            {
                //Queremos la posicion encima del panel y debajo de la ultima instruccion que se ha añadido.
                //Si no hemos puesto ninguna instrucción, simplemente lo posicionamos arriba de todo del panel
                other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, this.transform.position.y + 0.9f, this.transform.position.z);
                other.gameObject.transform.rotation = Quaternion.Euler(180, 180, 90);

                other.gameObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                other.gameObject.GetComponent <panelScriptTutorial>().setIsInPanel(true);
                current_hamburguer.addInstruction(other.gameObject);
            }


            //Si el panel que estoy poniendo no lo coloco entre ninguna de los paneles ya existentes, se coloca justo debajo.
            else if (other.gameObject.transform.position.y < current_hamburguer.getLastInstruction().transform.position.y)
            {
                other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, current_hamburguer.getLastInstruction().transform.position.y - conditionalSeparationAxisY, this.transform.position.z);

                other.gameObject.transform.rotation = Quaternion.Euler(180, 180, 90);

                //Congelamos la posición del panel. Si el freeze no está dentro del if/else se caen los paneles.
                other.gameObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                other.gameObject.GetComponent <panelScriptTutorial>().setIsInPanel(true);

                current_hamburguer.addInstruction(other.gameObject);
                if (other.gameObject.GetComponent <panelScriptTutorial>().getItWasInPanel())
                {
                    reOrderFunction(other);
                }

                else
                {
                    if (controladorTutorialWaiter.current.getIterTutorial() > 6)
                    {
                        controladorTutorialWaiter.current.createPanel();
                    }
                }
            }

            //En cualquier otro caso la instrucción estará entre otras dos ya existentes.
            else
            {
                int i = 0;

                //Recorremos los ingredientes hasta que encontremos entre que dos paneles hemos puesto el nuevo panel
                while (!other.gameObject.GetComponent <panelScriptTutorial>().getIsInPanel() || i == current_hamburguer.getInstructions().Count - 1)
                {
                    if (other.gameObject.transform.position.y < ((GameObject)current_hamburguer.getInstructions()[i]).transform.position.y && other.gameObject.transform.position.y > ((GameObject)current_hamburguer.getInstructions()[i + 1]).transform.position.y)
                    {
                        other.gameObject.GetComponent <panelScriptTutorial>().setIsInPanel(true);

                        //Colocamos la nueva instruccion entre los dos paneles
                        other.gameObject.transform.position = new Vector3(this.transform.position.x + other.transform.localScale.y, ((GameObject)current_hamburguer.getInstructions()[i]).transform.position.y - other.transform.localScale.x, this.transform.position.z);

                        //Insertamos la instrucción a la lista justo delante de la que estamos obeservando en ese momento
                        current_hamburguer.insertInstruction(i + 1, other.gameObject);

                        other.gameObject.transform.rotation = Quaternion.Euler(180, 180, 90);
                        other.gameObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                        reOrderFunction(other);
                        if (!other.gameObject.GetComponent <panelScriptTutorial>().getItWasInPanel() && controladorTutorialWaiter.current.getIterTutorial() > 4)
                        {
                            controladorTutorialWaiter.current.createPanel();
                        }
                    }
                    else
                    {
                        i++;
                    }
                }
            }
        }
    }