Exemplo n.º 1
0
        // This is the collision system.
        private void OnTriggerEnter(Collider other)
        {
            if (!other.gameObject.CompareTag("Pickup"))
            {
                return;
            }

            GetComponent <AudioSource>().PlayOneShot(other.gameObject.GetComponent <PickupSound>().Sound, 10);
            Destroy(other.gameObject);

            // Tally the number collected per current block
            int BlockID = TrialProgress.GetCurrTrial().BlockID;

            TrialProgress.GetCurrTrial().TrialProgress.NumCollectedPerBlock[BlockID]++;

            TrialProgress.GetCurrTrial().NumCollected++;
            E.LogData(
                TrialProgress.GetCurrTrial().TrialProgress,
                TrialProgress.GetCurrTrial().TrialStartTime,
                transform,
                1
                );

            if (--localQuota > 0)
            {
                return;
            }

            E.Get().CurrTrial.Notify();

            _playingSound = true;
        }
Exemplo n.º 2
0
        // ReSharper disable once UnusedMember.Global
        // Called with reflection
        public static bool SuccessesCriterion(TrialProgress tp)
        {
            var curr = TrialProgress.GetCurrTrial();

            var blockId = curr.BlockID;
            var bd      = DS.GetData().Blocks[blockId];
            var goal    = bd.BlockGoal ?? bd.TrialGoal;
            var numSuccessfulInPrevious = goal.Split(' ');
            var numSuccessfulRequired   = float.Parse(numSuccessfulInPrevious[0]);

            var successCount = 0;

            if (numSuccessfulInPrevious.Length == 0)
            {
                Debug.LogError("Missing arguments for threshold function in config");
            }

            // User has both values set in the config
            if (numSuccessfulInPrevious.Length == 2)
            {
                int previousTrialsToCheck = int.Parse(numSuccessfulInPrevious[1]);
                // Continue if we haven't reached the required run length
                if (tp.successes.Count < previousTrialsToCheck)
                {
                    return(true);
                }

                for (int i = tp.successes.Count - previousTrialsToCheck; i < tp.successes.Count; i++)
                {
                    if (tp.successes[i] == 1)
                    {
                        successCount++;
                    }
                }

                Debug.Log(string.Format(
                              "Number of Successes required: {0}, Actual: {1}, Previous trials to check: {2}",
                              numSuccessfulRequired, successCount, previousTrialsToCheck));
            }
            else
            {
                for (int i = 0; i < tp.successes.Count; i++)
                {
                    if (tp.successes[i] == 1)
                    {
                        successCount++;
                    }
                }

                Debug.Log(string.Format(
                              "Number of Successes required: {0}, Actual: {1}, Previous trials to check: ALL",
                              numSuccessfulRequired, successCount));
            }

            return(successCount < numSuccessfulRequired);
        }
Exemplo n.º 3
0
        // Start the character. If init from enclosure, this allows "s" to determine the start position
        public void ExternalStart(float pickX, float pickY, bool useEnclosure = false)
        {
            while (!_isStarted)
            {
                Thread.Sleep(20);
            }

            TrialProgress.GetCurrTrial().TrialProgress.TargetX = pickX;
            TrialProgress.GetCurrTrial().TrialProgress.TargetY = pickY;

            // No start pos specified so make it random.
            if (E.Get().CurrTrial.trialData.StartPosition.Count == 0)
            {
                // Try to randomly place the character, checking for proximity
                // to the pickup location
                var i = 0;
                while (i++ < 100)
                {
                    var CurrentTrialRadius = DS.GetData().Enclosures[E.Get().CurrTrial.TrialProgress.CurrentEnclosureIndex].Radius;
                    var v   = Random.insideUnitCircle * CurrentTrialRadius * 0.9f;
                    var mag = Vector3.Distance(v, new Vector2(pickX, pickY));
                    if (mag > DS.GetData().CharacterData.DistancePickup)
                    {
                        transform.position = new Vector3(v.x, 0.5f, v.y);
                        var camPos = Cam.transform.position;
                        camPos.y = DS.GetData().CharacterData.Height;
                        Cam.transform.position = camPos;
                        return;
                    }
                }
                Debug.LogError("Could not randomly place player. Probably due to" +
                               " a pick up location setting");
            }
            else
            {
                var p = E.Get().CurrTrial.trialData.StartPosition;

                if (useEnclosure)
                {
                    p = new List <float>()
                    {
                        pickX, pickY
                    };
                }

                transform.position = new Vector3(p[0], 0.5f, p[1]);
                var camPos = Cam.transform.position;
                camPos.y = DS.GetData().CharacterData.Height;
                Cam.transform.position = camPos;
            }
        }
Exemplo n.º 4
0
        private void Update()
        {
            E.LogData(TrialProgress.GetCurrTrial().TrialProgress, TrialProgress.GetCurrTrial().TrialStartTime, transform);

            // Wait for the sound to finish playing before ending the trial
            if (_playingSound)
            {
                if (!GetComponent <AudioSource>().isPlaying)
                {
                    TrialProgress.GetCurrTrial().Progress();
                    _playingSound = false;
                }
            }

            // This first block is for the initial rotation of the character
            if (_currDelay < _waitTime)
            {
                doInitialRotation();
            }
            else
            {
                // This section rotates the camera (potentiall up 15 degrees), basically deprecated code.
                if (!_reset)
                {
                    Cam.transform.Rotate(0, 0, 0);
                    _reset = true;
                    TrialProgress.GetCurrTrial().ResetTime();
                }

                // Move the character.
                try
                {
                    ComputeMovement();
                }
                catch (MissingComponentException e)
                {
                    Debug.LogWarning("Skipping movement calc: instructional trial");
                }
            }

            _currDelay += Time.deltaTime;
        }
Exemplo n.º 5
0
        public static void LogData(TrialProgress s, long trialStartTime, Transform t, int targetFound = 0)
        {
            // Don't output anything if the Y position is at default (avoids incorrect output data)
            if (t.position.y != -1000 && (targetFound == 1 || _timer > 1f / (DS.GetData().OutputTimesPerSecond == 0 ? 1000 : DS.GetData().OutputTimesPerSecond)))
            {
                using (var writer = new StreamWriter("Assets/OutputFiles~/" + DS.GetData().OutputFile, true))
                {
                    var PositionX = t.position.x.ToString();
                    var PositionZ = t.position.z.ToString();
                    var PositionY = t.position.y.ToString();
                    var RotationY = t.eulerAngles.y.ToString();

                    var timeSinceExperimentStart = DateTimeOffset.Now.ToUnixTimeMilliseconds() - DataSingleton.GetData().ExperimentStartTime;
                    var timeSinceTrialStart      = DateTimeOffset.Now.ToUnixTimeMilliseconds() - trialStartTime;

                    if (s.Instructional == 1)
                    {
                        PositionX = "NA";
                        PositionZ = "NA";
                        PositionY = "NA";
                        RotationY = "NA";
                    }

                    var str = string.Format(
                        "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, " +
                        "{12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}",
                        s.Field1, s.Field2, s.Field3, s.Field4, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), s.BlockID + 1, s.TrialID + 1, s.TrialNumber + 1, s.Instructional, s.TwoDim, s.EnvironmentType, s.CurrentEnclosureIndex + 1, PositionX, PositionY, PositionZ, RotationY,
                        targetFound, s.TargetX, s.TargetY, s.LastX, s.LastY,
                        Input.GetKey(KeyCode.UpArrow) ? 1 : 0,
                        Input.GetKey(KeyCode.DownArrow) ? 1 : 0, Input.GetKey(KeyCode.LeftArrow) ? 1 : 0,
                        Input.GetKey(KeyCode.RightArrow) ? 1 : 0,
                        Input.GetKey(KeyCode.Space) ? 1 : 0);
                    writer.Write(str + "\n");
                    writer.Flush();
                    writer.Close();
                }
                _timer = 0;
            }
            _timer += Time.deltaTime;
        }
Exemplo n.º 6
0
        private void Start()
        {
            try
            {
                var trialText   = GameObject.Find("TrialText").GetComponent <Text>();
                var blockText   = GameObject.Find("BlockText").GetComponent <Text>();
                var currBlockId = E.Get().CurrTrial.BlockID;
                // This section sets the text
                trialText.text = E.Get().CurrTrial.trialData.DisplayText;
                blockText.text = DS.GetData().Blocks[currBlockId].DisplayText;

                if (!string.IsNullOrEmpty(E.Get().CurrTrial.trialData.DisplayImage))
                {
                    var filePath     = DS.GetData().SpritesPath + E.Get().CurrTrial.trialData.DisplayImage;
                    var displayImage = GameObject.Find("DisplayImage").GetComponent <RawImage>();
                    displayImage.enabled = true;
                    displayImage.texture = Img2Sprite.LoadTexture(filePath);
                }
            }
            catch (NullReferenceException e)
            {
                Debug.LogWarning("Goal object not set: running an instructional trial");
            }

            Random.InitState(DateTime.Now.Millisecond);

            _currDelay = 0;

            // Choose a random starting angle if the value is not set in config
            if (E.Get().CurrTrial.trialData.StartFacing == -1)
            {
                _iniRotation = Random.Range(0, 360);
            }
            else
            {
                _iniRotation = E.Get().CurrTrial.trialData.StartFacing;
            }



            transform.Rotate(0, _iniRotation, 0);

            try
            {
                _controller = GetComponent <CharacterController>();
                _gen        = GameObject.Find("WallCreator").GetComponent <GenerateGenerateWall>();
                Cam.transform.Rotate(0, 0, 0);
            }
            catch (NullReferenceException e)
            {
                Debug.LogWarning("Can't set controller object: running an instructional trial");
            }
            _waitTime  = E.Get().CurrTrial.trialData.Rotate;
            _reset     = false;
            localQuota = E.Get().CurrTrial.trialData.Quota;

            // This has to happen here for output to be aligned properly
            TrialProgress.GetCurrTrial().TrialProgress.TrialNumber++;
            TrialProgress.GetCurrTrial().TrialProgress.Instructional = TrialProgress.GetCurrTrial().trialData.Instructional;
            TrialProgress.GetCurrTrial().TrialProgress.EnvironmentType = TrialProgress.GetCurrTrial().trialData.Scene;
            TrialProgress.GetCurrTrial().TrialProgress.CurrentEnclosureIndex = TrialProgress.GetCurrTrial().trialData.Enclosure - 1;
            TrialProgress.GetCurrTrial().TrialProgress.BlockID = TrialProgress.GetCurrTrial().BlockID;
            TrialProgress.GetCurrTrial().TrialProgress.TrialID = TrialProgress.GetCurrTrial().TrialID;
            TrialProgress.GetCurrTrial().TrialProgress.TwoDim = TrialProgress.GetCurrTrial().trialData.TwoDimensional;
            TrialProgress.GetCurrTrial().TrialProgress.LastX = TrialProgress.GetCurrTrial().TrialProgress.TargetX;
            TrialProgress.GetCurrTrial().TrialProgress.LastY = TrialProgress.GetCurrTrial().TrialProgress.TargetY;
            TrialProgress.GetCurrTrial().TrialProgress.TargetX = 0;
            TrialProgress.GetCurrTrial().TrialProgress.TargetY = 0;

            _isStarted = true;
        }