Exemple #1
0
    void Update()
    {
        //currentMode.text = "Current Axis"; // TOP FLOATING TEXT
        PlaneAxis = plane.GetAxis();
        //anatomicalPlane.text = plane.CurrentAxis(); //subTOP Floating TEXT
        switch (phase)
        {
        case ("Start"):
        {
            instructionText.text = "Press 'T' on Keyboard to start Tutorial, 'Q' to skip";
            //go to next phase
            if (Input.GetKeyDown(KeyCode.T))
            {
                phase = "Grab";
                Debug.Log("Entering Tutorial!");
            }
            else if (Input.GetKeyDown(KeyCode.Q))
            {
                phase = "Done";
            }
            //render bar
            hideBar();
            break;
        }

        case ("Grab"):
        {
            instructionText.text = "MOVE the model";
            grabLeft.text        = "look at other controller";
            grabRight.text       = "Move";
            triggerLeft.text     = "";
            triggerRight.text    = "";
            menuLeft.text        = "";
            menuRight.text       = "";

            leftWand.TrigDisable();
            rightWand.TrigDisable();
            leftWand.MenuDisable();
            rightWand.MenuDisable();
            //calculate Progress
            if (cube.IsMoving())
            {
                posDelta = cube.transform.position - prePos;

                progress += posDelta.magnitude * Time.deltaTime * 20f;

                prePos = cube.transform.position;
            }
            //go to next phase
            if (progress >= 1)
            {
                progress             = 1;
                instructionText.text = "Great!";
                delay -= Time.deltaTime;
                if (delay <= 0)
                {
                    phase    = "Rotate";
                    progress = 0;
                    delay    = delayTime;
                    unHighlight("grip");
                    Transform trigger = leftWandRenderer.FindComponent("trigger");
                    if (trigger != null)
                    {
                        defaultColor = trigger.GetComponent <MeshRenderer>().material.color;
                    }
                    break;
                }
            }
            //render bar
            updateBar();
            //HighLight
            highlight("rightGrip");

            break;
        }

        case ("Rotate"):
        {
            instructionText.text = "ROTATE";
            grabLeft.text        = "Move";
            grabRight.text       = "Move";
            triggerLeft.text     = "Rotate";
            triggerRight.text    = "Rotate";

            leftWand.TrigEnable();
            rightWand.TrigEnable();
            //calculate Progress
            if (cube.IsTriggering())
            {
                rotDelta = cube.transform.rotation * Quaternion.Inverse(preRot);
                rotDelta.ToAngleAxis(out angle, out axis);
                progress += angle * 0.0005f;
                preRot    = cube.transform.rotation;
            }
            //go to next phase
            if (progress >= 1)
            {
                progress             = 1;
                instructionText.text = "Awesome!";
                delay -= Time.deltaTime;
                if (delay <= 0)
                {
                    phase    = "Zoom";
                    progress = 0;
                    delay    = delayTime;
                    unHighlight("rightPad");
                    unHighlight("leftPad");
                }
            }
            //render bar
            updateBar();
            highlight("rightPad");
            highlight("leftPad");
            break;
        }

        case ("Zoom"):
        {
            instructionText.text = "Hold BOTH the TRIGGER buttons to ZOOM";
            triggerLeft.text     = "Zoom";
            triggerRight.text    = "Zoom";
            //calculate Progress
            if (cube.IsZooming())
            {
                progress += 0.2f * Time.deltaTime;
            }
            //go to next phase
            if (progress >= 1)
            {
                progress             = 1;
                instructionText.text = "Fantastic!";
                delay -= Time.deltaTime;
                if (delay <= 0)
                {
                    phase    = "Change Mode";
                    progress = 0;
                    delay    = delayTime;
                }
            }
            //render bar
            updateBar();
            break;
        }

        case ("Change Mode"):
        {
            instructionText.text = "Press the Menu button to switch to Plane mode";
            grabLeft.text        = "";
            grabRight.text       = "";
            triggerLeft.text     = "";
            triggerRight.text    = "";
            menuLeft.text        = "Change Mode";
            menuRight.text       = "Change Mode";
            leftWand.GripDisable();
            rightWand.GripDisable();
            leftWand.TrigDisable();
            rightWand.TrigDisable();
            leftWand.MenuEnable();
            rightWand.MenuEnable();
            //calculate Progress
            if (leftWand.IsControllingPlane() || rightWand.IsControllingPlane())
            {
                progress            += 3f * Time.deltaTime;
                instructionText.text = "Enter Cutting Mode!";
            }
            //go to next phase
            if (progress >= 1)
            {
                progress = 1;
                delay   -= Time.deltaTime;
                if (delay <= 0)
                {
                    phase    = "RotatePlane";
                    progress = 0;
                    delay    = delayTime;
                    preRot   = plane.transform.rotation;
                    break;
                }
            }
            //render bar
            updateBar();
            break;
        }

        case ("RotatePlane"):
        {
            instructionText.text = "Press the TRIGGER button to ROTATE the Plane";
            grabLeft.text        = "";
            grabRight.text       = "";
            triggerLeft.text     = "Switch Plane Axis";
            triggerRight.text    = "Switch Plane Axis";
            menuLeft.text        = "";
            menuRight.text       = "";

            leftWand.TrigEnable();
            rightWand.TrigEnable();
            leftWand.MenuDisable();
            rightWand.MenuDisable();
            //calculate Progress
            if (leftWand.IsTriggerDown() && !holdingLeftTrigger)
            {
                holdingLeftTrigger = true;
                progress          += 0.25f;
            }
            else if (!leftWand.IsTriggerDown())
            {
                holdingLeftTrigger = false;
            }
            if (rightWand.IsTriggerDown() && !holdingRightTrigger)
            {
                holdingRightTrigger = true;
                progress           += 0.25f;
            }
            else if (!rightWand.IsTriggerDown())
            {
                holdingRightTrigger = false;
            }
            //go to next phase
            if (progress >= 1)
            {
                progress             = 1;
                instructionText.text = "Good Job!";
                delay -= Time.deltaTime;
                if (delay <= 0)
                {
                    phase    = "SlidePlane";
                    progress = 0;
                    delay    = delayTime;
                    prePos   = plane.transform.position;
                    //unHighlightTrig();
                    break;
                }
            }
            //render bar
            updateBar();
            //highlightTrig();
            break;
        }

        case ("SlidePlane"):
        {
            instructionText.text = "Hold the GRIP button to SLIDE the cutting plane";
            triggerLeft.text     = "Switch Plane Axis";
            triggerRight.text    = "Switch Plane Axis";
            grabLeft.text        = "Slide";
            grabRight.text       = "Slide";

            leftWand.GripEnable();
            rightWand.GripEnable();
            //calculate Progress
            if (plane.IsMovingPlane())
            {
                posDelta  = plane.transform.position - prePos;
                progress += posDelta.magnitude * Time.deltaTime * 25f;
                prePos    = plane.transform.position;
            }
            //go to next phase
            if (progress >= 1)
            {
                progress             = 1;
                instructionText.text = "Almost Done!";
                delay -= Time.deltaTime;
                if (delay <= 0)
                {
                    phase    = "Free";
                    progress = 0;
                    delay    = delayTime;
                    //unHighlight("grip");
                    break;
                }
            }
            //render bar
            updateBar();
            //highlight("grip");
            break;
        }

        case ("Free"):
        {
            instructionText.text = "Try out all you have learned!";
            triggerLeft.text     = "Switch Plane Axis";
            triggerRight.text    = "Switch Plane Axis";
            grabLeft.text        = "Slide";
            grabRight.text       = "Slide";
            menuLeft.text        = "Change Mode";
            menuRight.text       = "Change Mode";
            leftWand.MenuEnable();
            rightWand.MenuEnable();
            //calculate Progress
            if (!leftWand.IsControllingPlane())
            {
                phase = "Free2";
            }
            //render bar
            hideBar();
            break;
        }

        case ("Free2"):
        {
            instructionText.text = "Try out all you have learned!";
            triggerLeft.text     = "Rotate";
            triggerRight.text    = "Rotate";
            grabLeft.text        = "Move";
            grabRight.text       = "Move";
            menuLeft.text        = "Change Mode";
            menuRight.text       = "Change Mode";
            if (leftWand.IsControllingPlane())
            {
                phase = "Done";
            }
            //render bar
            hideBar();
            break;
        }

        case ("Done"):
        {
            instructionText.text = "";
            triggerLeft.text     = "";
            triggerRight.text    = "";
            grabLeft.text        = "";
            grabRight.text       = "";
            menuLeft.text        = "";
            menuRight.text       = "";
            //render bar
            hideBar();
            break;
        }
        }
    }