Esempio n. 1
0
    void FireAmmo()
    {
        Vector3    mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        GameObject ammo          = SpawnAmmo(transform.position);

        if (ammo != null)
        {
            ArcScript arcScript      = ammo.GetComponent <ArcScript>();
            float     travelDuration = 1.0f / weaponVelocity;
            StartCoroutine(arcScript.Travel(mousePosition, travelDuration));
        }
    }
Esempio n. 2
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;
        }
    }