// Update is called once per frame
    void Update()
    {
        updateNavigation();
        updateStackingManipulation();
        updateMovingManipulation();

        if (Input.GetButton("Fire1"))
        {
            lastGameObjectHit = raycastscript.getTargetObjects(Input.mousePosition, playerCam.camera);
            if (lastGameObjectHit != rotateScript.clone)
            {
                rotateScript.selectedObject = lastGameObjectHit;
                rotateScript.SetDrawFeedback(true);
            }
            //if (lastGameObjectHit != scaleScript.clone){
            //	scaleScript.selectedObject = lastGameObjectHit;
            //	scaleScript.SetDrawFeedback(true, "x");
            //}
        }
        //rotate
        if (Input.GetKey("-"))
        {
            rotateScript.RotateLeft();
        }
        if (Input.GetKey("="))
        {
            rotateScript.RotateRight();
        }
        //scale

        /*if (Input.GetKey("["))
         *      scaleScript.ScaleXSmaller();
         * if (Input.GetKey("]"))
         *      scaleScript.ScaleXBigger();
         * if (Input.GetKey(";"))
         *      scaleScript.ScaleYSmaller();
         * if (Input.GetKey("'"))
         *      scaleScript.ScaleYBigger();
         *      if (Input.GetKey("."))
         *      scaleScript.ScaleZSmaller();
         * if (Input.GetKey("/"))
         *      scaleScript.ScaleZBigger();*/


        //Set the gui shizzle
        Vector3 mousePos = Input.mousePosition;
        float   mouseX   = mousePos.x / Screen.width;
        float   mouseY   = mousePos.y / Screen.height;
        //Debug.Log(mouseX + "\t" + mouseY);
        //screenpointer.transform.position = new Vector3(Screen.width/2, Screen.height/2, 0);
        //screenpointer.transform.position = new Vector3(mouseX, mouseY, 0);
        //screenpointer.transform.position = mouseY;
        //Rect cursloc = new Rect(mousePos.x, Screen.height - mousePos.y, cursorImage.width, cursorImage.height);
        //GUI.Label(cursloc, cursorImage);
    }
Example #2
0
    private void updateRotatingManipulation()
    {
        if (Input.GetKey("left"))
        {
            rotateScript.RotateLeft();
        }
        if (Input.GetKey("right"))
        {
            rotateScript.RotateRight();
        }
        if (Input.GetKeyUp("o"))
        {
            rotateScript.End();             // end this manipulation
            modus = Modi.CHO_MAN;
        }

        checkForNewSelection();
    }
    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);
        }
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        updateNavigation();
        updateStackingManipulation();

        if (Input.GetButton("Fire1"))
        {
            lastGameObjectHit = raycastscript.getTargetObjects(Input.mousePosition, playerCam.camera);
            if (lastGameObjectHit != rotateScript.clone)
            {
                rotateScript.selectedObject = lastGameObjectHit;
                rotateScript.SetDrawFeedback(true);

                scaleScript.selectedObject = lastGameObjectHit;
                scaleScript.SetDrawFeedback(true);
            }
        }
        //rotate
        if (Input.GetKey("-"))
        {
            rotateScript.RotateLeft();
        }
        if (Input.GetKey("="))
        {
            rotateScript.RotateRight();
        }
        //scale
        if (Input.GetKey("["))
        {
            scaleScript.ScaleKleiner();
        }
        if (Input.GetKey("]"))
        {
            scaleScript.ScaleGroter();
        }
        if (Input.GetKey("p"))
        {
            scaleScript.volgendeAs();
        }
        if (Input.GetKeyUp("p"))
        {
            scaleScript.releaseLock();
        }

        //camera
        if (Input.GetKeyUp(";"))
        {
            smoothCameraScript.getNextCameraLokatie();
        }

        if (Input.GetKeyUp("'"))
        {
            smoothCameraScript.getVorigCameraLokatie();
        }

        if (Input.GetKey("/"))
        {
            smoothCameraScript.GaNaarVorigePositie();
        }

        //camera uitzoomen naar top view
        if (Input.GetKey("."))
        {
            smoothCameraScript.GaNaarTopView();
        }


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

        //Debug.Log(mouseX + "\t" + mouseY);
        //screenpointer.transform.position = new Vector3(Screen.width/2, Screen.height/2, 0);
        screenpointer.transform.position = new Vector3(mouseX, mouseY, 0);
        //screenpointer.transform.position = mouseY;
        Rect cursloc = new Rect(mousePos.x, Screen.height - mousePos.y, cursorImage.width, cursorImage.height);
        //GUI.Label(cursloc, cursorImage);
    }