Ejemplo n.º 1
0
    public void testMove()
    {
        GameObject tafel  = GameObject.Find("schaal1");
        MoveScript script = (MoveScript)gameObject.GetComponent("MoveScript");

        script.Begin(tafel);
    }
Ejemplo n.º 2
0
    void FixedUpdate()
    {
        wiimoteCount = wiimote_count();
        if (wiimoteCount > 0)
        {
            //Nota: alleen 1 wiimote is rekening mee gehouden, 2x privates nodig voor 2e of afwisselend behandelen
            x     = wiimote_getAccX(0);
            y     = wiimote_getAccY(0);
            z     = wiimote_getAccZ(0);
            roll  = Mathf.Round(wiimote_getRoll(0) + rollFudge);
            pitch = Mathf.Round(wiimote_getPitch(0) + pitchFudge);
            yaw   = Mathf.Round(wiimote_getYaw(0));

            //Orientation vectors
            if (!float.IsNaN(roll) && !float.IsNaN(pitch))
            {
                vec = new Vector3(pitch, 0, -1 * roll);
/*					vec = new Vector3(pitch, yaw , -1 * roll);*/
                vec    = Vector3.Lerp(oldVec, vec, Time.deltaTime * sensitivity);
                oldVec = vec;
            }

            /* ir Gui  */
            ir_x = wiimote_getIrX(0);
            ir_y = wiimote_getIrY(0);
            //F**k off basic zooi die er al was, Jens coming through
            if ((ir_x != -100) && (ir_y != -100))
            {
                temp_x = (ir_x + 1) / 2;
                temp_y = (ir_y + 1) / 2;
                screenpointer.transform.position = new Vector3(temp_x, temp_y, 0);
            }

            //Updaten van muispointers
            selectieScript.updateSelection(temp_x * Screen.width, temp_y * Screen.height);
            smoothCameraScript.UpdateCamera();

            //wanneer we gemerkt hebben dat de gebruiker in topview een vloer heeft geselecteerd, zetten we hem eerst terug op de grond voor iets anders te doen
            //de camera gaat in de smoothcamerascript de gebruiker terug in een draaiende beweging in het midden van de geselecteerde kamer zetten
            if (moveToSelectedRoom)
            {
                smoothCameraScript.goToRoom(selectieScript.lastGameObjectHit.transform.position);
                modus   = Modi.NAV_SEL;
                topview = false;
            }
            //Hier komen alle eigen manipulaties

            /*Klikken op A en B */             //TODO:single - pulse - klik :/
            if (wiimote_getButtonA(0) && wiimote_getButtonB(0) && !buttonpulse)
            {
                buttonpulse = true;
                switch (modus)
                {
                //TOONT HET MENU in selectie of manipulatiemode
                case Modi.NAV_SEL:                         //In selectiemodus: klikken = selecteren
                    if (selectieScript.GUIShown)
                    {
                        selectieScript.hideUI();
                        selectieScript.GUIShown = false;
                        modus = Modi.NAV_SEL;
                    }
                    else
                    {
                        ObjectScript script  = (ObjectScript)selectieScript.lastGameObjectHit.GetComponent("ObjectScript");
                        string[]     choices = { "Geen keuzes" };
                        if (script != null)
                        {
                            choices = script.getObjectPossibilities();
                        }
                        selectieScript.showUi(temp_x * Screen.width, temp_y * Screen.height, choices);
                        selectieScript.GUIShown = true;
                        modus = Modi.CHO_MAN;
                    }
                    break;

                case Modi.CHO_MAN:
                    //Zelfde als selectie -> terug naar nav gaan
                    if (selectieScript.GUIShown)
                    {
                        selectieScript.hideUI();
                        selectieScript.GUIShown = false;
                        modus = Modi.NAV_SEL;
                    }
                    else
                    {
                        ObjectScript script  = (ObjectScript)selectieScript.lastGameObjectHit.GetComponent("ObjectScript");
                        string[]     choices = { "Geen keuzes" };
                        if (script != null)
                        {
                            choices = script.getObjectPossibilities();
                        }
                        selectieScript.showUi(temp_x * Screen.width, temp_y * Screen.height, choices);
                        selectieScript.GUIShown = true;
                        modus = Modi.CHO_MAN;
                    }
                    break;

                case Modi.MOV:
                    GameObject newParent = raycastscript.getTargetObjects(new Vector3(temp_x * Screen.width, temp_y * Screen.height, 0), playerCam.camera);
                    if (newParent != null && newParent != selectieScript.lastGameObjectHit)
                    {
                        moveScript.changeStackParent(selectieScript.lastGameObjectHit, newParent);
                    }
                    break;
                }
            }
            else if (wiimote_getButtonA(0))              //Alleen A ingedrukt = menu kiezen
            {
                //buttonpulse = true;
                if (selectieScript.lastGameObjectHit && modus == Modi.CHO_MAN)
                {
                    //Recalculate the gui pixel values from ir values
                    float realvalX = temp_x * Screen.width;
                    float realvalY = temp_y * Screen.height;
                    Debug.Log(selectieScript.getButtonOnPosition(realvalX, realvalY));
                    if (selectieScript.getButtonOnPosition(realvalX, realvalY) == "Move")
                    {
                        Debug.Log("Move change parent");
                        rotateScript.End();
                        scaleScript.End();
                        stackScript.End();
                        modus = Modi.MOV;
                        moveScript.Begin(selectieScript.lastGameObjectHit);
                    }
                    else if (selectieScript.getButtonOnPosition(realvalX, realvalY) == "Rotate")
                    {
                        Debug.Log("rotate");
                        scaleScript.End();
                        stackScript.End();
                        moveScript.End();
                        smoothCameraScript.GaNaarVorigePositie();
                        modus = Modi.ROT;
                        rotateScript.Begin(selectieScript.lastGameObjectHit);
                    }
                    else if (selectieScript.getButtonOnPosition(realvalX, realvalY) == "Add")
                    {
                        Debug.Log("stack");
                        rotateScript.End();
                        scaleScript.End();
                        moveScript.End();
                        modus = Modi.STA;
                        stackScript.Begin(selectieScript.lastGameObjectHit);
                    }
                    else if (selectieScript.getButtonOnPosition(realvalX, realvalY) == "Delete")
                    {
                        Debug.Log("remove");
                        rotateScript.End();
                        scaleScript.End();
                        stackScript.End();
                        moveScript.End();
                        //modus = Modi.DEL;	//Niet nodig: alles gebeurt hier
                        verwijderScript.DeleteObject(selectieScript.lastGameObjectHit);
                        selectieScript.lastGameObjectHit = null;
                        selectieScript.hideUI();
                        selectieScript.GUIShown = false;
                        modus = Modi.NAV_SEL;
                    }
                    else if (selectieScript.getButtonOnPosition(realvalX, realvalY) == "Scale")
                    {
                        Debug.Log("scale");
                        rotateScript.End();
                        stackScript.End();
                        moveScript.End();
                        smoothCameraScript.GaNaarVorigePositie();
                        modus = Modi.SCA;
                        scaleScript.Begin(selectieScript.lastGameObjectHit);
                    }
                }
            }
            else if (wiimote_getButtonB(0))
            {
                //buttonpulse = true;
                //Alleen knop B: niks in zetten dat al in A+B zit -> conflicten
            }
            else
            {
                //Geen knop ingedrukt
                buttonpulse = false;
            }

            if (wiimote_getButtonMinus(0) && !minbuttonpulse)             //Terug naar vorige modus
            {
                minbuttonpulse = true;
                if (modus == Modi.NAV_SEL)
                {
                    smoothCameraScript.returnFromTopview2();
                    topview = false;
                }
                else if (modus == Modi.MOV)                  //FROM move TO choicemodus
                {
                    moveScript.End();
                    modus = Modi.NAV_SEL;
                }
                else if (modus == Modi.ROT)
                {
                    rotateScript.End();
                    modus = Modi.NAV_SEL;
                }
                else if (modus == Modi.SCA)
                {
                    scaleScript.End();
                    modus = Modi.NAV_SEL;
                }
                else if (modus == Modi.STA)
                {
                    stackScript.End();
                    modus = Modi.NAV_SEL;
                }
            }
            else
            {
                minbuttonpulse = false;
            }

            if (wiimote_getButtonPlus(0))
            {
                if (modus == Modi.NAV_SEL)
                {
                    if (topview)
                    {
                        if (selectieScript.lastGameObjectHit != null && selectieScript.lastGameObjectHit.tag == "vloer")
                        {
                            moveToSelectedRoom = true;
                            returnToCamShowAfterManipulation = false;
                            topview = false;
                        }

                        else if (selectieScript.lastGameObjectHit != null && selectieScript.lastGameObjectHit.tag != "vloer")
                        {
                            moveToSelectedRoom = false;
                            returnToCamShowAfterManipulation = true;
                            topview = true;
                        }

                        else if (selectieScript.lastGameObjectHit == null)
                        {
                            returnToCamShowAfterManipulation = false;
                            moveToSelectedRoom = false;
                            topview            = true;
                        }
                    }
                }
                if (modus == Modi.SCA && !plusbuttonpulse)
                {
                    plusbuttonpulse = true;
                    scaleScript.releaseLock();
                    scaleScript.volgendeAs();
                }
            }
            else
            {
                plusbuttonpulse = false;
            }

            if (wiimote_getButtonHome(0) && !homebuttonpulse)              //Abort all
            {
                homebuttonpulse = true;
                Debug.Log("Abort");
                rotateScript.End();
                scaleScript.End();
                stackScript.Abort();
                moveScript.End();
                smoothCameraScript.GaNaarVorigePositie();
                modus = Modi.NAV_SEL;
                selectieScript.hideUI();
                selectieScript.GUIShown = false;
                topview = false;
            }
            else
            {
                homebuttonpulse = false;
            }

            if (wiimote_getButton1(0) && !button1pulse)              //Wisselen van camhoek
            {
                button1pulse = true;
                if (modus == Modi.NAV_SEL)
                {
                    smoothCameraScript.getNextCameraLokatie();
                }
            }
            else
            {
                button1pulse = false;
            }

            if (wiimote_getButton2(0) && !button1pulse)              //Wisselen van camhoek
            {
                button2pulse = true;
                if (modus == Modi.NAV_SEL)
                {
                    smoothCameraScript.getVorigCameraLokatie();
                }
            }
            else
            {
                button2pulse = false;
            }

            if (wiimote_getButtonLeft(0))
            {
                padbuttonpulse = true;
                if (modus == Modi.NAV_SEL)
                {
                    moveCameraLeft();
                }
                else if (modus == Modi.MOV)
                {
                    if (moveScript.gridModus)
                    {
                        moveScript.goToNextAvailablePositionLeft();
                    }
                    else
                    {
                        moveScript.goToLeft();
                    }
                }
                else if (modus == Modi.ROT)
                {
                    rotateScript.RotateLeft();
                }
                else if (modus == Modi.STA)
                {
                    if (stackScript.isActive)
                    {
                        if (stackScript.gridModus)
                        {
                            stackScript.goToNextAvailablePositionLeft();
                        }
                        else
                        {
                            stackScript.goToLeft();
                        }
                    }
                }
            }
            else if (wiimote_getButtonRight(0))
            {
                padbuttonpulse = true;
                if (modus == Modi.NAV_SEL)
                {
                    moveCameraRight();
                }
                else if (modus == Modi.MOV)
                {
                    if (moveScript.gridModus)
                    {
                        moveScript.goToNextAvailablePositionRight();
                    }
                    else
                    {
                        moveScript.goToRight();
                    }
                }
                else if (modus == Modi.ROT)
                {
                    rotateScript.RotateRight();
                }
                else if (modus == Modi.STA)
                {
                    if (stackScript.isActive)
                    {
                        if (stackScript.gridModus)
                        {
                            stackScript.goToNextAvailablePositionRight();
                        }
                        else
                        {
                            stackScript.goToRight();
                        }
                    }
                }
            }
            else if (wiimote_getButtonUp(0))
            {
                padbuttonpulse = true;
                if (modus == Modi.NAV_SEL && !topview)
                {
                    moveCameraForward();
                }
                else if (modus == Modi.MOV)
                {
                    if (moveScript.gridModus)
                    {
                        moveScript.goToNextAvailablePositionTop();
                    }
                    else
                    {
                        moveScript.goToTop();
                    }
                }
                else if (modus == Modi.STA)
                {
                    if (stackScript.isActive)
                    {
                        if (stackScript.gridModus)
                        {
                            stackScript.goToNextAvailablePositionTop();
                        }
                        else
                        {
                            stackScript.goToTop();
                        }
                    }
                }
            }
            else if (wiimote_getButtonDown(0))
            {
                padbuttonpulse = true;
                if (modus == Modi.NAV_SEL && !topview)
                {
                    moveCameraBackward();
                }
                else if (modus == Modi.MOV)
                {
                    if (moveScript.gridModus)
                    {
                        moveScript.goToNextAvailablePositionDown();
                    }
                    else
                    {
                        moveScript.goToBottom();
                    }
                }
                else if (modus == Modi.STA)
                {
                    if (stackScript.isActive)
                    {
                        if (stackScript.gridModus)
                        {
                            stackScript.goToNextAvailablePositionDown();
                        }
                        else
                        {
                            stackScript.goToBottom();
                        }
                    }
                }
            }
            else
            {
                padbuttonpulse = false;
            }

            //TODO: roll moet 0.5 sec ingehouden worden voordat deze reageert
            //Dus: functie aanroepen die 0.5 sec telt en dan pas bool op false zet
            if (!checkRollOutOfBounds())
            {
                Debug.Log("Roll in bounds");
                if (roll <= -20)                                         //Wiimote links kantelen
                {
                    if (modus == Modi.NAV_SEL && !topview && !rollpulse) //In navigatie
                    {
                        rollpulse = true;
                        rotateCameraLeft90Degrees();
                    }
                    else if (modus == Modi.ROT)
                    {
                        rotateScript.RotateLeft();
                    }
                    else if (modus == Modi.STA && !rollpulse)
                    {
                        rollpulse = true;
                        if (stackScript.isActive)
                        {
                            stackScript.goToNextPossibleStackedObject();
                        }
                    }
                    else if (modus == Modi.CHO_MAN && !rollpulse)
                    {
                        rollpulse = true;
                        selectieScript.getNextChild();
                    }
                }
                else if (roll >= 120)                   //Wiimote rechts kantelen
                {
                    if (modus == Modi.NAV_SEL && !topview && !rollpulse)
                    {
                        rollpulse = true;
                        rotateCameraRight90Degrees();
                    }
                    else if (modus == Modi.ROT)
                    {
                        rotateScript.RotateRight();
                    }
                    else if (modus == Modi.STA && !rollpulse)
                    {
                        rollpulse = true;
                        if (stackScript.isActive)
                        {
                            stackScript.goToNextPossibleStackedObject();
                        }
                    }
                }
                else
                {
                    rollpulse = false;
                }
            }

            //Pitch gebruiken voor schaleren
            if (!checkPitchOutOfBounds())
            {
                Debug.Log("Pitch in bounds");
                if (pitch <= -30)                  //Wiimote licht recht houden
                {
                    if (modus == Modi.SCA)
                    {
                        scaleScript.ScaleGroter();
                    }
                }
                else if (pitch >= 100)                     //TESTEN!
                {
                    if (modus == Modi.SCA)
                    {
                        scaleScript.ScaleKleiner();
                    }
                }

                if (pitch <= -70 && !topview)
                {
                    if (modus == Modi.NAV_SEL && checkRollOutOfBounds())
                    {
                        smoothCameraScript.GaNaarTopView();
                        topview = true;
                    }
                }
            }

            //Laatste check om te zien of selectiemode aan of uit moet (anders ingewikkeld in overzetten)
            //Reden: nu per key -> dan naar navigatie gemapt wegens wiimote - issues
            if (modus == Modi.NAV_SEL || modus == Modi.CHO_MAN)
            {
                selectieScript.setSelectionmodeOn();
            }
            else
            {
                selectieScript.setSelectionmodeOff();
                selectieScript.guiscript.hideGui();
            }
        }

        //Debug
        if (showDebugGUI)
        {
            DoDebugStr(0);
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        //Laat hier temp staan OVERGEZET
        selectieScript.updateSelection(Input.mousePosition.x, Input.mousePosition.y);
        smoothCameraScript.UpdateCamera();

        //check of we een nieuwe kamer geselecteerd hebben vanuit topview en navigeer daarnaar
        /* OVERZETTEN */
        if (moveToSelectedRoom)
        {
            smoothCameraScript.goToRoom(selectieScript.lastGameObjectHit.transform.position);
            modus = Modi.NAV_SEL;
        }

        /*OVERGEZET*/
        // aborting modus
        if (Input.GetKeyUp("q"))
        {
            Debug.Log("Abort");
            rotateScript.End();
            scaleScript.End();
            stackScript.Abort();
            moveScript.End();

            if (returnToCamShowAfterManipulation)
            {
                modus = Modi.CAM_SHO;
            }
            else
            {
                smoothCameraScript.GaNaarVorigePositie();
                modus = Modi.NAV_SEL;
            }

            deselectAll();
        }
        // go to moving/changing parent modus
        else if (selectieScript.lastGameObjectHit && modus == Modi.CHO_MAN && Input.GetButtonUp("Fire1"))
        {
            Debug.Log(selectieScript.getButtonOnPosition(Input.mousePosition.x, Input.mousePosition.y));
            if (selectieScript.getButtonOnPosition(Input.mousePosition.x, Input.mousePosition.y) == "Move")
            {
                Debug.Log("Move change parent");
                rotateScript.End();
                scaleScript.End();
                stackScript.End();

                modus = Modi.MOV;
                moveScript.Begin(selectieScript.lastGameObjectHit);
            }
            else if (selectieScript.getButtonOnPosition(Input.mousePosition.x, Input.mousePosition.y) == "Rotate")
            {
                Debug.Log("rotate");
                scaleScript.End();
                stackScript.End();
                moveScript.End();
                smoothCameraScript.GaNaarVorigePositie();

                modus = Modi.ROT;
                rotateScript.Begin(selectieScript.lastGameObjectHit);
            }
            else if (selectieScript.getButtonOnPosition(Input.mousePosition.x, Input.mousePosition.y) == "Add")
            {
                Debug.Log("stack");
                rotateScript.End();
                scaleScript.End();
                moveScript.End();

                modus = Modi.STA;
                stackScript.Begin(selectieScript.lastGameObjectHit);
            }
            else if (selectieScript.getButtonOnPosition(Input.mousePosition.x, Input.mousePosition.y) == "Delete")
            {
                Debug.Log("remove");
                rotateScript.End();
                scaleScript.End();
                stackScript.End();
                moveScript.End();

                modus = Modi.DEL;
            }
            else if (selectieScript.getButtonOnPosition(Input.mousePosition.x, Input.mousePosition.y) == "Scale")
            {
                Debug.Log("scale");
                rotateScript.End();
                stackScript.End();
                moveScript.End();
                smoothCameraScript.GaNaarVorigePositie();

                modus = Modi.SCA;
                scaleScript.Begin(selectieScript.lastGameObjectHit);
            }
            // go to scale modus
        }
        else if (selectieScript.lastGameObjectHit && modus == Modi.CHO_MAN && Input.GetKeyUp("e"))
        {
            Debug.Log("scale");
            rotateScript.End();
            stackScript.End();
            moveScript.End();
            smoothCameraScript.GaNaarVorigePositie();

            modus = Modi.SCA;
            scaleScript.Begin(selectieScript.lastGameObjectHit);
            // go to rotate modus
        }
        else if (selectieScript.lastGameObjectHit && modus == Modi.CHO_MAN && Input.GetKeyUp("r"))
        {
            Debug.Log("rotate");
            scaleScript.End();
            stackScript.End();
            moveScript.End();
            smoothCameraScript.GaNaarVorigePositie();

            modus = Modi.ROT;
            rotateScript.Begin(selectieScript.lastGameObjectHit);
            // go to stacking modus
        }
        else if (selectieScript.lastGameObjectHit && modus == Modi.CHO_MAN && Input.GetKeyUp("t"))
        {
            Debug.Log("stack");
            rotateScript.End();
            scaleScript.End();
            moveScript.End();

            modus = Modi.STA;
            stackScript.Begin(selectieScript.lastGameObjectHit);
            // go to removing status
        }
        else if (selectieScript.lastGameObjectHit && modus == Modi.CHO_MAN && Input.GetKeyUp("y"))
        {
            Debug.Log("remove");
            rotateScript.End();
            scaleScript.End();
            stackScript.End();
            moveScript.End();

            modus = Modi.DEL;
            // go to slideshow modus
        }
        else if (Input.GetKeyUp("u"))
        {
            Debug.Log("slideshow");
            rotateScript.End();
            scaleScript.End();
            stackScript.End();
            moveScript.End();

            deselectAll();
            smoothCameraScript.getNextCameraLokatie();
            modus = Modi.CAM_SHO;
        }

        //Select an object
        if (modus == Modi.CHO_MAN || modus == Modi.NAV_SEL)
        {
            if (selectieScript.isActive && Input.GetButtonUp("Fire1"))
            {
                if (selectieScript.GUIShown)
                {
                    selectieScript.hideUI();
                    selectieScript.GUIShown = false;
                    modus = Modi.NAV_SEL;
                }
                else
                {
                    ObjectScript script  = (ObjectScript)selectieScript.lastGameObjectHit.GetComponent("ObjectScript");
                    string[]     choices = { "Geen keuzes" };              //wordt overreden indien niet null
                    if (script != null)
                    {
                        choices = script.getObjectPossibilities();
                    }
                    selectieScript.showUi(Input.mousePosition.x, Input.mousePosition.y, choices);
                    selectieScript.GUIShown = true;
                    modus = Modi.CHO_MAN;
                }
            }

            /*
             * selectieScript.fireEvent = true; //Vuur een clickevent af in selectie
             * //TODO: if object selected?
             * if(selectieScript.lastGameObjectHit != null){
             *      Debug.Log("Naar manipulatiemode");
             *      modus = Modi.CHO_MAN;
             *      }*/
        }

        //DEEL PER DEEL DOEN -> KNOP PER KNOP IN WIIMOTE | STAAT "DONE" NA UPDATEFUNCT. INDIEN GEIMPLEMENTEERD
        switch (modus)
        {
        case Modi.NAV_SEL:                 /* DONE  */
            selectieScript.setSelectionmodeOn();
            updateNavigation();
            break;

        case Modi.CHO_MAN:                 /* DONE  */
            selectieScript.setSelectionmodeOn();
            updateManipulationChoosing();
            break;

        case Modi.MOV:                 /* DONE - TOTEST */
            selectieScript.setSelectionmodeOff();
            updateMovingManipulation();
            selectieScript.guiscript.hideGui();
            break;

        case Modi.ROT:                 /* DONE - TOTEST */
            selectieScript.setSelectionmodeOff();
            updateRotatingManipulation();
            selectieScript.guiscript.hideGui();
            break;

        case Modi.SCA:                 /* DONE - TOTEST */
            selectieScript.setSelectionmodeOff();
            updateScalingManipulation();
            selectieScript.guiscript.hideGui();
            break;

        case Modi.STA:                 /* DONE - TOTEST */
            selectieScript.setSelectionmodeOff();
            updateStackingManipulation();
            selectieScript.guiscript.hideGui();
            break;

        case Modi.DEL:                 /* DONE - TOTEST */
            selectieScript.setSelectionmodeOff();
            updateDeletingManipulation();
            selectieScript.guiscript.hideGui();
            break;

        case Modi.CAM_SHO:                 /* DONE |MERGED WITH NAV_SEL | TOTEST */
            //selectieScript.setSelectionmodeOn();
            updateCameraShow();
            //selectieScript.guiscript.hideGui();
            break;
        }

        //Set the gui shizzle
        Vector3 mousePos = Input.mousePosition;
        float   mouseX   = mousePos.x / Screen.width;
        float   mouseY   = mousePos.y / Screen.height;

        screenpointer.transform.position = new Vector3(mouseX, mouseY, 0);
        Rect cursloc = new Rect(mousePos.x, Screen.height - mousePos.y, cursorImage.width, cursorImage.height);
    }