Example #1
0
    public override void Setup()
    {
        ctrler = ExperimentController.Instance();

        //pinballDummy = Instantiate(ctrler.GetPrefab("PinballPrefabDummy"));
        //pinballDummy.transform.SetParent(ctrler.gameObject.transform);
        //pinballDummy.transform.localPosition = new Vector3(0, 0, 0);

        string per_block_ins = ctrler.Session.CurrentTrial.settings.GetString("per_block_instruction");

        ins = ctrler.Session.CurrentTrial.settings.GetString(per_block_ins);

        // Temporarily disable VR Camera
        // TODO: This needs to be changed when we implement instruction task for VR
        //ctrler.CursorController.SetVRCamera(false);

        //Task GameObjects
        instructionPanel = Instantiate(ctrler.GetPrefab("InstructionPanel"), this.transform);

        instruction    = GameObject.Find("Instruction");
        timer          = GameObject.Find("Timer");
        done           = GameObject.Find("Done");
        vrInstructions = GameObject.Find("VRInstructions");
        vrInstructions.transform.localPosition = new Vector3(vrInstructions.transform.localPosition.x, vrInstructionOffset, vrInstructions.transform.localPosition.z);

        instruction.GetComponent <Text>().text        = ins;
        vrInstructions.GetComponent <TextMesh>().text = ins;

        //countdown Timer start
        timer.GetComponent <Text>().text = System.Math.Round(timeRemaining, 0).ToString();

        //add event listener to done button
        done.GetComponent <Button>().onClick.AddListener(() => End());
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        Text target = WorldSpace ? WorldSpaceText : CamSpaceText;

        if (AllowManualSet)
        {
            if (ScorePrefix)
            {
                target.text = "Score: " + ManualScoreText;
            }
            else
            {
                target.text = ManualScoreText;
            }
        }
        else
        {
            if (ScorePrefix)
            {
                target.text = "Score: " + ExperimentController.Instance().Score;
            }
            else
            {
                target.text = "" + ExperimentController.Instance().Score;
            }
        }
    }
Example #3
0
 void FixedUpdate()
 {
     if (ExperimentController.Instance().CurrentTask.GetCurrentStep == 1 &&
         GetComponent <Rigidbody>().velocity.sqrMagnitude > 0.0f)
     {
         ExperimentController.Instance().CurrentTask.IncrementStep();
     }
 }
Example #4
0
 private void Update()
 {
     if (ExperimentController.Instance().CursorController.triggerUp)
     {
         //Debug.Log("Trigger Up");
         Grabbed = false;
     }
 }
Example #5
0
 void OnTriggerEnter(Collider col)
 {
     if ((col.gameObject.name == "ToolBox" || col.gameObject.name == "ToolSphere") &&
         ExperimentController.Instance().CurrentTask.GetCurrentStep == 1)
     {
         //ExperimentController.Instance().CurrentTask.IncrementStep();
         Debug.Log(" you hit me");
     }
 }
Example #6
0
    protected int maxSteps;       // Number of steps this task has

    /// <summary>
    /// Increments the current step in this task
    /// </summary>
    public virtual bool IncrementStep()
    {
        currentStep++;

        // Track the time when a step is incremented
        ExperimentController.Instance().StepTimer.Add(Time.time);

        finished = currentStep == maxSteps;
        return(finished);
    }
Example #7
0
    // Update is called once per frame
    void LateUpdate()
    {
        triggerUp = false;

        if (RightHandDevice.TryGetFeatureValue(CommonUsages.triggerButton, out bool val) && val)
        {
            // if start pressing, trigger event
            if (!IsPressed)
            {
                IsPressed = true;
                Debug.Log("Trig down now");
            }
        }
        else if (IsPressed) // check for button release
        {
            IsPressed = false;
            triggerUp = true;
        }
        // Above code should work for OnTriggerUp (this means clean-up is required on current onTriggerUp method)

        if (ExperimentController.Instance().CurrentTask == null)
        {
            return;
        }

        Vector3 realHandPosition = GetHandPosition();

        // Update the position of the cursor depending on which hand is involved
        transform.position = ConvertPosition(realHandPosition);

        if ((previousPosition - realHandPosition).magnitude > 0.001f)
        {
            PauseTime = 0f;
        }
        else
        {
            PauseTime += Time.deltaTime;
        }

        previousPosition = realHandPosition;

        if (ExperimentController.Instance().CurrentTask.Home != null)
        {
            DistanceFromHome =
                (transform.position - ExperimentController.Instance().CurrentTask.Home.transform.position).magnitude;
        }
        else
        {
            DistanceFromHome = -1f;
        }

        prevLeftTrigger  = IsTriggerDown("l");
        prevRightTrigger = IsTriggerDown("r");
    }
Example #8
0
    public override bool IncrementStep()
    {
        ExperimentController ctrler = ExperimentController.Instance();

        switch (currentStep)
        {
        case 0:     // Enter dock
            targets[0].SetActive(false);
            Home.SetActive(true);
            break;

        case 1:     // Enter home
            Home.SetActive(false);

            ctrler.StartTimer();

            // Create tracker objects
            ctrler.AddTrackedObject("hand_path",
                                    ctrler.Session.CurrentTrial.settings.GetString("per_block_hand") == "l"
                        ? ctrler.CursorController.LeftHand
                        : ctrler.CursorController.RightHand);

            ctrler.AddTrackedObject("cursor_path", ctrler.CursorController.gameObject);

            Target.SetActive(true);

            ExperimentController.Instance().CursorController.SetCursorVisibility(false);

            break;

        case 2:     // Pause in arc
            localizer.SetActive(true);
            Target.GetComponent <ArcScript>().Expand();

            break;

        case 3:     // Select the spot they think their real hand is
            Target.SetActive(false);

            // We use the target variable to store the cursor position
            Target.transform.position =
                ExperimentController.Instance().CursorController.GetHandPosition();

            break;
        }

        base.IncrementStep();
        return(finished);
    }
Example #9
0
    //
    public Vector3 GetHandPosition()
    {
        if (UseVR)
        {
            return(CurrentTaskHand == "l"
            ? leftHandCollider.transform.position
            : rightHandCollider.transform.position);
        }

        if (Camera.main == null)
        {
            Debug.LogWarning("make sure your camera is tagged as the Main camera");
        }

        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        return(new Vector3(mousePos.x, ExperimentController.Instance().transform.position.y, mousePos.z));
    }
Example #10
0
    /// <summary>
    /// Converts the user's hand location into the transformed cursor location
    /// </summary>
    /// <returns></returns>
    private Vector3 ConvertPosition(Vector3 position)
    {
        ExperimentController ctrler = ExperimentController.Instance();

        // Get home position. Returns Vector3.zero when task doesn't use a home position
        Vector3 home = ctrler.CurrentTask.Home != null ?
                       ctrler.CurrentTask.Home.transform.position : Vector3.zero;

        switch (MoveType)
        {
        case MovementType.aligned:
            return(position);

        case MovementType.rotated:
            float angle = ctrler.Session.CurrentTrial.settings
                          .GetFloat("per_block_rotation");

            return(Quaternion.Euler(0, -angle, 0) * (position - home) + home);

        case MovementType.clamped:
            // Get vector between home position and target
            Vector3 target = ctrler.CurrentTask.Target.transform.position;
            Vector3 normal = target - home;

            // Rotate vector by 90 degrees to get plane parallel to the vector
            normal = Quaternion.Euler(0f, -90f, 0f) * normal;

            //  o   < target
            //  |
            // -|   < normal
            //  |
            //  x   < dock / center of experiment

            // Project position using this new vector as the plane normal
            return(Vector3.ProjectOnPlane(position - home, normal.normalized) + home);

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Example #11
0
    // Start is called before the first frame update
    void Start()
    {
        if (WorldSpace)
        {
            CameraSpaceCanvas.SetActive(false);
            WorldSpaceCanvas.SetActive(true);

            TrialTrackText.gameObject.SetActive(TrackTrials);

            TrialTrackText.text = "Trials Remaining: " +
                                  (ExperimentController.Instance().Session.Trials.Count() -
                                   ExperimentController.Instance().Session.currentTrialNum + 1);

            ManualScoreText = ExperimentController.Instance().Score.ToString();
        }
        else
        {
            CameraSpaceCanvas.SetActive(true);
            WorldSpaceCanvas.SetActive(false);

            ManualScoreText = ExperimentController.Instance().Score.ToString();
        }
    }
Example #12
0
    public override void Setup()
    {
        maxSteps = 4;

        ctrler = ExperimentController.Instance();

        toolSpace = Instantiate(ctrler.GetPrefab("ToolPrefab"));

        base.Setup();

        Target     = GameObject.Find("Target");
        toolCamera = GameObject.Find("ToolCamera");
        grid       = GameObject.Find("Grid");
        handL      = GameObject.Find("handL");
        handR      = GameObject.Find("handR");
        XRRig      = GameObject.Find("XR Rig");
        XRPosLock  = GameObject.Find("XRPosLock");

        curlingStone  = GameObject.Find("curlingStone");
        slingShotBall = GameObject.Find("slingShotBall");
        puckobj       = GameObject.Find("impactPuck");
        ballobj       = GameObject.Find("impactBall");
        ray           = GameObject.Find("ray");
        barrier       = GameObject.Find("barrier");

        toolBox      = GameObject.Find("paddle");
        toolCylinder = GameObject.Find("slingshot");
        toolSphere   = GameObject.Find("squeegee");

        toolObjects = GameObject.Find("ToolObjects");

        baseObject = GameObject.Find("BaseObject");

        ballObjects = GameObject.Find("BallObjects");

        // Set up home position
        Home = GameObject.Find("HomePosition");


        timerIndicator.transform.rotation = Quaternion.LookRotation(
            timerIndicator.transform.position - toolCamera.transform.position);
        timerIndicator.Timer = ctrler.Session.CurrentBlock.settings.GetFloat("per_block_timerTime");

        // Set up target
        float targetAngle = Convert.ToSingle(ctrler.PollPseudorandomList("per_block_targetListToUse"));

        SetTargetPosition(targetAngle);

        // Should the tilt be shown to the participant before they release the pinball?
        if (!ctrler.Session.CurrentBlock.settings.GetBool("per_block_tilt_after_fire"))
        {
            SetTilt();
        }

        // Disable all balls/puck (to be enabled in child classes)
        puckobj.SetActive(false);
        curlingStone.SetActive(false);
        slingShotBall.SetActive(false);
        ballobj.SetActive(false);

        switch (ctrler.PollPseudorandomList("per_block_list_tool_type"))
        {
        case "paddle":
            toolCylinder.SetActive(false);
            toolSphere.SetActive(false);
            selectedObject = toolBox;
            sound          = toolBox.GetComponentInChildren <AudioSource>();
            break;

        case "squeegee":
            Home.transform.position = new Vector3(Home.transform.position.x, Home.transform.position.y, -0.2f);
            toolCylinder.SetActive(false);
            toolBox.SetActive(false);
            selectedObject = toolSphere;
            sound          = toolSphere.GetComponentInChildren <AudioSource>();
            break;

        case "slingshot":
            toolSphere.SetActive(false);
            toolBox.SetActive(false);
            selectedObject = toolCylinder;
            sound          = toolCylinder.GetComponentInChildren <AudioSource>();
            elasticL       = toolCylinder.transform.GetChild(4).gameObject.GetComponent <LineRenderer>();
            elasticR       = toolCylinder.transform.GetChild(3).gameObject.GetComponent <LineRenderer>();
            elasticL.SetPosition(0, barrier.transform.GetChild(1).GetChild(0).gameObject.transform.position);
            elasticR.SetPosition(0, barrier.transform.GetChild(0).GetChild(0).gameObject.transform.position);
            break;
        }

        currentHand = ctrler.CursorController.CurrentHand();

        toolBox.GetComponent <Collider>().enabled      = false;
        toolCylinder.GetComponent <Collider>().enabled = false;
        toolSphere.GetComponent <Collider>().enabled   = false;

        baseObject.GetComponent <Rigidbody>().useGravity = false;

        baseObject.transform.position = Home.transform.position;

        baseObject.GetComponent <Rigidbody>().maxAngularVelocity = 240;

        //initial distance between target and ball
        InitialDistanceToTarget  = Vector3.Distance(Target.transform.position, ballObjects.transform.position);
        InitialDistanceToTarget += 0.15f;


        // Set up camera for non VR and VR modes and controller for vr mode
        if (ctrler.Session.settings.GetString("experiment_mode") == "tool")
        {
            ctrler.CursorController.SetVRCamera(false);
        }
        else
        {
            toolCamera.SetActive(false);
            ctrler.CursorController.UseVR = true;
            ctrler.CursorController.SetCursorVisibility(false);

            if (ctrler.Session.CurrentBlock.settings.GetString("per_block_hand") == "l")
            {
                handL.SetActive(true);
            }
            else
            {
                handR.SetActive(true);
            }
        }


        // set up surface materials for the plane
        switch (ctrler.Session.CurrentBlock.settings.GetString("per_block_surface_materials"))
        {
        case "fabric":
            grid.SetActive(false);
            base.SetSurfaceMaterial(ctrler.Materials["GrassMaterial"]);
            break;

        case "ice":
            grid.SetActive(false);
            base.SetSurfaceMaterial(ctrler.Materials["Ice"]);
            break;
        }
    }
Example #13
0
 private void Start()
 {
     ctrler = ExperimentController.Instance();
 }
Example #14
0
    public void LateUpdate()
    {
        ExperimentController ctrler = ExperimentController.Instance();

        switch (currentStep)
        {
        // When the user holds their hand and they are outside the home, begin the next phase of localization
        case 2 when ctrler.CursorController.PauseTime > 0.5f &&
            ctrler.CursorController.DistanceFromHome > 0.03f:
            IncrementStep();
            break;

        case 3:
            // VR: User uses their head to localize their hand
            // Non-VR: User uses horizontal axis to localize their mouse

            if (ctrler.Session.settings.GetString("experiment_mode") == "target")     // if in vr
            {
                // raycasts from camera to set localizer position
                Plane plane = new Plane(Vector3.down, ctrler.transform.position.y);
                Ray   r     = new Ray(Camera.main.transform.position, Camera.main.transform.forward);

                if (plane.Raycast(r, out float hit))
                {
                    localizer.transform.position = r.GetPoint(hit);
                }
            }
            else
            {
                // A/D keys, left/right arrow keys, or gamepad joystick as input
                LocalizerAngle2D += Input.GetAxisRaw("Horizontal") * localizerSpeed2D;
                LocalizerAngle2D  = Mathf.Clamp(LocalizerAngle2D, -90f, 90f);

                float angle = LocalizerAngle2D * Mathf.Deg2Rad;

                // centre == centre of Arc == centre of Home
                Vector3 centre = Target.transform.position;

                // distance from home: copied from ArcTarget script, multiplied by the size of the arc
                float distance = (Target.GetComponent <ArcScript>().TargetDistance + centre.z) * Target.transform.localScale.x;

                // find position along arc
                Vector3 newPos = new Vector3(Mathf.Sin(angle), 0, Mathf.Cos(angle)) * distance;
                newPos += centre;

                localizer.transform.position = newPos;
            }

            // switch from click to enter or something? issue with clicking to refocus window

            // If the user presses the trigger associated with the hand, we end the trial
            if (ctrler.CursorController.IsTriggerDown(ctrler.CursorController.CurrentTaskHand) || Input.GetKeyDown(KeyCode.N) || Input.GetKeyDown(KeyCode.Space))
            {
                IncrementStep();
            }

            break;
        }

        if (Finished)
        {
            ctrler.EndAndPrepare();
        }
    }
Example #15
0
    //void OnCollisionStay(Collision collider)
    //{
    //    {
    //        collider_name = collider.gameObject.name;
    //        Grabbed = ExperimentController.Instance().CursorController.CurrentCollider().name == collider.gameObject.name &&
    //            ExperimentController.Instance().CursorController.IsTriggerDown();

    //        Debug.Log(collider_name);
    //    }

    //}

    void OnTriggerStay(Collider other)
    {
        // set Grabbed to True when trigger is down AND cursor model is inside this collider
        Grabbed = "RightHandCollider" == other.gameObject.name &&
                  ExperimentController.Instance().CursorController.IsTriggerDown();
    }
Example #16
0
    /*
     * Step 0:
     *
     * spawn at startpoint gate
     * mouse move to car point
     *
     * Step 1:
     * let car move
     *
     * Step 2:
     * hit wall or hit finish line gate
     * log parameters
     * end trial
     *
     * Step 3:
     * finished
     *
     */

    public override void Setup()
    {
        maxSteps = 3;
        ctrler   = ExperimentController.Instance();

        trailSpace = Instantiate(ctrler.GetPrefab("TrailPrefab"));

        trailGate1 = GameObject.Find("TrailGate1");
        trailGate2 = GameObject.Find("TrailGate2");

        startCollider  = trailGate1.transform.GetChild(3).GetComponent <BoxCollider>();
        midwayCollider = GameObject.Find("MidwayCollider").GetComponent <BoxCollider>();

        gatePlacement = GameObject.Find("gatePlacement").GetComponent <GatePlacement>();

        roadSegments = GameObject.Find("generated_by_SplineExtrusion");

        scoreboard = GameObject.Find("Scoreboard").GetComponent <Scoreboard>();

        for (int i = 0; i < roadSegments.transform.childCount; i++)
        { // add road segments to gatePlacement list of meshes
            gatePlacement.mesh.Add(roadSegments.transform.GetChild(i).GetComponent <MeshFilter>().mesh);
        }
        gatePlacement.Setup();

        /* TrailGate children:
         * 0: pole1
         * 2: pole2
         * 3: checkered line (line renderer component)
         * 4: trigger (collider component)
         */

        startPoint = ctrler.Session.CurrentBlock.settings.GetFloat("per_block_startPoint");
        gatePlacement.SetGatePosition(trailGate1, trailGate1.transform.GetChild(0).gameObject, trailGate1.transform.GetChild(1).gameObject,
                                      trailGate1.transform.GetChild(2).GetComponent <LineRenderer>(), trailGate1.transform.GetChild(3).GetComponent <BoxCollider>(), startPoint);

        endPoint = ctrler.Session.CurrentBlock.settings.GetFloat("per_block_endPoint");
        gatePlacement.SetGatePosition(trailGate2, trailGate2.transform.GetChild(0).gameObject, trailGate2.transform.GetChild(1).gameObject,
                                      trailGate2.transform.GetChild(2).GetComponent <LineRenderer>(), trailGate2.transform.GetChild(3).GetComponent <BoxCollider>(), endPoint);

        // Place midway triggers throughout the track
        for (int i = 0; i < NUM_MID_TRIGGERS; i++)
        {
            midwayTriggers.Add(Instantiate(midwayCollider.gameObject).GetComponent <BaseTarget>());

            // Start    Mid1     Mid2     End
            // |--------|--------|--------|
            if (endPoint < startPoint)
            {
                // If the end point comes before the start point

                float distance = 1 - startPoint + endPoint;

                midPoint = ((distance) / (NUM_MID_TRIGGERS + 1)) * (i + 1) + startPoint;

                if (midPoint > 1)
                {
                    midPoint -= 1;
                }
            }
            else
            {
                float distance = endPoint - startPoint;

                midPoint = ((distance) / (NUM_MID_TRIGGERS + 1)) * (i + 1) + startPoint;
            }

            gatePlacement.SetColliderPosition(midwayTriggers[i].GetComponent <BoxCollider>(), midPoint);
        }


        railing1 = GameObject.Find("generated_by_SplineMeshTiling");
        foreach (MeshCollider railing in railing1.transform.GetComponentsInChildren <MeshCollider>())
        {
            railing.tag       = "TrailRailing";
            railing.convex    = true;
            railing.isTrigger = true;
            railing.gameObject.SetActive(false);
        }

        railing2 = GameObject.Find("generated_by_SplineMeshTiling_1");
        foreach (MeshCollider railing in railing1.transform.GetComponentsInChildren <MeshCollider>())
        {
            railing.tag       = "TrailRailing";
            railing.convex    = true;
            railing.isTrigger = true;
            railing.gameObject.SetActive(false);
        }

        for (int i = 0; i < railing1.transform.GetChild(0).transform.childCount; i++)
        {
            railing1.transform.GetChild(i).gameObject.AddComponent <BaseTarget>();
        }

        for (int i = 0; i < railing2.transform.childCount; i++)
        {
            railing2.transform.GetChild(i).gameObject.AddComponent <BaseTarget>();
        }

        car = GameObject.Find("Car");

        car.transform.position = trailGate1.transform.position;

        raycastOrigins.AddRange(car.GetComponentsInChildren <Transform>());


        innerTrackColliders.AddRange(GameObject.Find("innertrack").transform.GetComponentsInChildren <BaseTarget>());

        if (ctrler.Session.currentTrialNum > 1)
        {
            trailGate1.GetComponentInChildren <ParticleSystem>().transform.position = trailGate1.transform.position;
            trailGate1.GetComponentInChildren <ParticleSystem>().transform.rotation = trailGate1.transform.rotation;
            trailGate1.GetComponentInChildren <ParticleSystem>().Play();
            trailSpace.GetComponent <AudioSource>().clip = ctrler.AudioClips["correct"];
            trailSpace.GetComponent <AudioSource>().Play();
        }

        // Use static camera for non-vr version of pinball
        if (ctrler.Session.settings.GetString("experiment_mode") == "trail")
        {
            ctrler.CursorController.SetVRCamera(false);
        }
        else
        {
        }
    }
Example #17
0
    public override void Setup()
    {
        ExperimentController ctrler = ExperimentController.Instance();

        maxSteps = 4;

        ctrler.CursorController.SetHandVisibility(false);
        Cursor.visible = false;
        ctrler.CursorController.SetCursorVisibility(true);

        localizationPrefab = Instantiate(ctrler.GetPrefab("LocalizationPrefab"));
        localizationPrefab.transform.SetParent(ctrler.transform);
        localizationPrefab.transform.localPosition = Vector3.zero;

        localizationCam     = GameObject.Find("LocalizationCamera");
        localizationSurface = GameObject.Find("Surface");

        // Set up the dock position
        targets[0] = GameObject.Find("Dock");
        targets[0].transform.position = ctrler.TargetContainer.transform.position;

        // Set up the home position
        targets[1] = GameObject.Find("Home");
        targets[1].transform.position = ctrler.TargetContainer.transform.position + ctrler.transform.forward * 0.05f;
        targets[1].SetActive(false);
        Home = targets[1];

        // Grab an angle from the list and then remove it
        float targetAngle = Convert.ToSingle(ctrler.PollPseudorandomList("per_block_targetListToUse"));

        // Set up the arc object
        targets[2] = GameObject.Find("ArcTarget");
        targets[2].transform.rotation = Quaternion.Euler(
            0f,
            -targetAngle + 90f,
            0f);

        targets[2].transform.position = targets[1].transform.position;

        targets[2].GetComponent <ArcScript>().TargetDistance = ctrler.Session.CurrentTrial.settings.GetFloat("per_block_distance");
        targets[2].GetComponent <ArcScript>().Angle          = targets[2].transform.rotation.eulerAngles.y;
        //targets[2].transform.localScale = Vector3.one;
        Target = targets[2];

        // Set up the GameObject that tracks the user's gaze
        localizer = GameObject.Find("Localizer");
        localizer.GetComponent <SphereCollider>().enabled = false;
        localizer.GetComponent <BaseTarget>().enabled     = false;
        localizer.SetActive(false);

        localizer.transform.SetParent(ctrler.TargetContainer.transform);
        localizer.name = "Localizer";

        Target.SetActive(false);


        // Use static camera for non-vr version of pinball
        if (ctrler.Session.settings.GetString("experiment_mode") == "target")
        {
            localizationSurface.SetActive(false);
            localizationCam.SetActive(false);
            ctrler.CursorController.UseVR = true;
        }
        else
        {
            ctrler.CursorController.SetVRCamera(false);
        }
    }
Example #18
0
    public override void Setup()
    {
        maxSteps = 3;

        ctrler = ExperimentController.Instance();

        pinballSpace = Instantiate(ctrler.GetPrefab("PinballPrefab"));

        base.Setup();

        pinball            = GameObject.Find("Pinball");
        Home               = GameObject.Find("PinballHome");
        Target             = GameObject.Find("PinballTarget");
        pinballCam         = GameObject.Find("PinballCamera");
        directionIndicator = GameObject.Find("PinballSpring");
        directionIndicator.SetActive(false);
        arcIndicator = GameObject.Find("ArcTarget").GetComponent <ArcScript>();
        arcIndicator.gameObject.SetActive(false);
        XRRig       = GameObject.Find("XR Rig");
        pinballWall = GameObject.Find("PinballWall");
        XRPosLock   = GameObject.Find("XRPosLock");
        XRCamOffset = GameObject.Find("Dummy Camera");

        bonusText      = GameObject.Find("BonusText");
        obstacle       = GameObject.Find("Obstacle");
        pinballSurface = GameObject.Find("Surface");
        handL          = GameObject.Find("handL");
        handR          = GameObject.Find("handR");
        handL.SetActive(false);
        handR.SetActive(false);

        float targetAngle = Convert.ToSingle(ctrler.PollPseudorandomList("per_block_targetListToUse"));

        SetTargetPosition(targetAngle);

        // checks if the current trial uses the obstacle and activates it if it does
        if (ctrler.Session.CurrentBlock.settings.GetBool("per_block_obstacle"))
        {
            obstacle.SetActive(true);
            // initializes the position
            obstacle.transform.position = new Vector3(0f, 0.065f, 0f);
            //rotates the object
            obstacle.transform.rotation = Quaternion.Euler(0f, -targetAngle + 90f, 0f);
            //moves object forward towards the direction it is facing
            obstacle.transform.position += Target.transform.forward.normalized * (TARGET_DISTANCE / 2);
        }
        else
        {
            obstacle.SetActive(false);
        }

        // Use static camera for non-vr version of pinball
        if (ctrler.Session.settings.GetString("experiment_mode") == "pinball")
        {
            // Setup Pinball Camera Offset
            pinballCam.transform.position = pinballCamOffset;
            pinballCam.transform.rotation = Quaternion.Euler(pinballAngle, 0f, 0f);

            ctrler.CursorController.SetVRCamera(false);
        }
        else
        {
            ctrler.CursorController.UseVR = true;
            pinballCam.SetActive(false);
            ctrler.CursorController.SetCursorVisibility(false);

            timerIndicator.transform.position = Home.transform.position;
            scoreboard.transform.position    += Vector3.up * 0.33f;

            if (ctrler.Session.CurrentBlock.settings.GetString("per_block_hand") == "l")
            {
                handL.SetActive(true);
            }
            else
            {
                handR.SetActive(true);
            }
        }

        // Cutoff distance is 30cm more than the distance to the target
        cutoffDistance = 0.30f + TARGET_DISTANCE;

        currentHand = ctrler.CursorController.CurrentHand();

        // Parent to experiment controller
        pinballSpace.transform.SetParent(ctrler.transform);
        pinballSpace.transform.localPosition = Vector3.zero;

        // Setup line renderer for pinball path
        pinballSpace.GetComponent <LineRenderer>().startWidth   =
            pinballSpace.GetComponent <LineRenderer>().endWidth = 0.015f;

        // Should the tilt be shown to the participant before they release the pinball?
        if (!ctrler.Session.CurrentBlock.settings.GetBool("per_block_tilt_after_fire"))
        {
            SetTilt();
        }

        if (ctrler.Session.settings.GetString("experiment_mode") != "pinball")
        {
            timerIndicator.transform.rotation = Quaternion.LookRotation(timerIndicator.transform.position - pinballCam.transform.position);
        }

        pinballStartPosition = pinball.transform.position;

        timerIndicator.Timer = ctrler.Session.CurrentBlock.settings.GetFloat("per_block_timerTime");

        timerIndicator.GetComponent <TimerIndicator>().BeginTimer();

        if (ctrler.Session.CurrentBlock.settings.GetString("per_block_indicator_type") == "arc")
        {
            directionIndicator.GetComponent <MeshRenderer>().enabled = false;
        }

        if (ctrler.Session.CurrentBlock.settings.GetString("per_block_fire_mode") == "flick")
        {
            Cursor.visible = false;
        }

        // Start tracking hand pos
        ctrler.AddTrackedObject("hand", ctrler.CursorController.CurrentHand());
        timeHandTrackingStarts = Time.time;

        // set up surface materials for the plane
        switch (Convert.ToString(ctrler.PollPseudorandomList("per_block_surface_materials")))
        {
        case "default":
            // Default material in prefab
            break;

        case "brick":
            base.SetSurfaceMaterial(ctrler.Materials["GrassMaterial"]);
            pinballWall.GetComponent <MeshRenderer>().material = ctrler.Materials["BrickMat"];
            break;
        }
    }
Example #19
0
    public override void Setup()
    {
        ctrler = ExperimentController.Instance();

        trial = ctrler.Session.CurrentTrial;

        Cursor.visible = false;

        reachPrefab = Instantiate(ctrler.GetPrefab("ReachPrefab"));
        reachPrefab.transform.SetParent(ctrler.transform);
        reachPrefab.transform.localPosition = Vector3.zero;

        reachCam       = GameObject.Find("ReachCamera");
        reachSurface   = GameObject.Find("Surface");
        waterBowl      = GameObject.Find("Bowl");
        water          = GameObject.Find("Water");
        timerIndicator = GameObject.Find("TimerIndicator").GetComponent <TimerIndicator>();
        scoreboard     = GameObject.Find("Scoreboard").GetComponent <Scoreboard>();

        timerIndicator.Timer = ctrler.Session.CurrentBlock.settings.GetFloat("per_block_timerTime");

        // Whether or not this is a practice trial
        // replaces scoreboard with 'Practice Round', doesn't record score
        trackScore = (ctrler.Session.CurrentBlock.settings.GetBool("per_block_track_score"));

        if (!trackScore)
        {
            // Scoreboard is now updated by the reach class
            scoreboard.AllowManualSet  = true;
            scoreboard.ScorePrefix     = false;
            scoreboard.ManualScoreText = "Practice Round";
        }

        Enum.TryParse(ctrler.Session.CurrentTrial.settings.GetString("per_block_type"),
                      out MovementType rType);

        reachType    = new MovementType[3];
        reachType[2] = rType;
        maxSteps     = 3;

        // Set up hand and cursor
        ctrler.CursorController.SetHandVisibility(false);
        ctrler.CursorController.SetCursorVisibility(true);

        // Set up the dock position
        targets[0] = GameObject.Find("Dock");
        targets[0].transform.position = ctrler.TargetContainer.transform.position;

        // Set up the home position
        targets[1] = GameObject.Find("Home");
        targets[1].transform.position = ctrler.TargetContainer.transform.position + ctrler.transform.forward * 0.05f;
        targets[1].SetActive(false);
        Home = targets[1];

        // Set up the target

        // Takes a target angle from the list and removes it
        float targetAngle = Convert.ToSingle(ctrler.PollPseudorandomList("per_block_targetListToUse"));

        targets[2] = GameObject.Find("Target");
        targets[2].transform.rotation = Quaternion.Euler(
            0f, -targetAngle + 90f, 0f);

        targets[2].transform.position = targets[1].transform.position +
                                        targets[2].transform.forward.normalized *
                                        (trial.settings.GetFloat("per_block_distance") / 100f);

        // Disable collision detection for nocursor task
        if (trial.settings.GetString("per_block_type") == "nocursor")
        {
            targets[2].GetComponent <BaseTarget>().enabled = false;
        }

        targets[2].SetActive(false);
        Target = targets[2];

        // Use static camera for non-vr version
        if (ctrler.Session.settings.GetString("experiment_mode") == "target")
        {
            reachSurface.SetActive(false);
            reachCam.SetActive(false);
            ctrler.CursorController.UseVR = true;
        }
        else
        {
            ctrler.CursorController.SetVRCamera(false);
        }

        // sets up the water in the level
        if (ctrler.Session.CurrentBlock.settings.GetString("per_block_waterPresent") == "wp1")
        {
            float waterLevel = Convert.ToSingle(ctrler.PollPseudorandomList("per_block_waterPresent"));
            waterBowl.SetActive(true);
            water.SetActive(true);


            // If previous trial had a water level, animate water level rising/falling from that level
            try
            {
                if (ctrler.Session.PrevTrial.result.ContainsKey("per_block_waterPresent"))
                {
                    water.transform.localPosition =
                        new Vector3(water.transform.localPosition.x,
                                    Convert.ToSingle(ctrler.Session.PrevTrial.result["per_block_waterPresent"]) / 10,
                                    water.transform.localPosition.z);

                    id = LeanTween.moveLocalY(water, waterLevel / 10, speed).id;
                    d  = LeanTween.descr(id);
                }
                else
                {
                    water.transform.localPosition = new Vector3(0, -0.03f, 0);
                    id = LeanTween.moveLocalY(water, waterLevel / 10, speed).id;
                    d  = LeanTween.descr(id);
                }
            }
            catch (NoSuchTrialException e)
            {
                water.transform.localPosition = new Vector3(0, -0.03f, 0);
                id = LeanTween.moveLocalY(water, waterLevel / 10, speed).id;
                d  = LeanTween.descr(id);
            }
        }
        else
        {
            waterBowl.SetActive(false);
            water.SetActive(false);
        }
    }
Example #20
0
 public override void LogParameters()
 {
     // Store where they think their hand is
     ExperimentController.Instance().LogObjectPosition("loc", localizer.transform.localPosition);
 }