private void SpawnDistractors(TrialVars variables) { float dist = variables.A - ((targetRadius * 2.0f) + targetMargin) * 2.0f - (targetRadius * 0.5f); float spacing = (targetRadius * 2.0f + (targetMargin * 0.5f)); // Distractors in the cone int interDistractors = (variables.D != 0) ? (int)(dist / (spacing / variables.D)) : 0; // Distractors outside the cone int remDistractors = Mathf.FloorToInt(maxTargets * variables.D) - interDistractors; // Spawn intermediate distractors within cone for (int i = 0; i < interDistractors; i++) { GameObject target = InstantiateTarget(distractorPrefab, new Vector2(0.0f, 0.0f), targetRadius); float newSpacing = (spacing / variables.D) * (i + 1); Vector2 perpVec = ((i + 1) % 2 == 0) ? Vector2.Perpendicular(sliceDir) : Vector2.Perpendicular(-sliceDir); Vector2 x = sliceOrigin + (sliceDir * newSpacing); Vector2 y = x + (perpVec.normalized * Random.Range(targetRadius * 0.5f, (newSpacing * Mathf.Tan(Mathf.Deg2Rad * (distractorConeAngle * 0.5f))))); target.transform.localPosition = y; } for (int i = 0; i < remDistractors; i++) { GameObject target = InstantiateTarget(distractorPrefab, new Vector2(0.0f, 0.0f), targetRadius); do { target.transform.localPosition = randomTargetPos(); } while (checkOverlap(target)); } }
private void storeTrial() { TrialVars trialVars = (TrialVars)ICurrentTrial.Current; trialData.amplitude = trialVars.A; trialData.distractorDesnity = trialVars.D; trialData.effectiveWidth = trialVars.W; blockData.trials.Add(trialData); trialData = new TrialData(); }
private void SpawnGoal(TrialVars variables) { GoalObject = InstantiateTarget(goalPrefab, new Vector2(0.0f, 0.0f), targetRadius); Vector2 randomPos; Vector2 distVec; // Set the location of the goal target do { // Generate a random point in the experiment area randomPos = randomTargetPos(); // Get the vector from the last goal position to the random point distVec = lastGoalPos - randomPos; // Adjust the vector to have the correct amplitude distVec = distVec.normalized * variables.A; // Set the new goal position GoalObject.transform.localPosition = lastGoalPos + distVec; } while (!checkInBounds(GoalObject)); // Set the slice origin and direction sliceOrigin = lastGoalPos; sliceDir = distVec.normalized; float randomAngle = Random.Range(0.0f, 90.0f); // Four Distractors to control Goal Target's Effective Width for (int i = 0; i < 4; i++) { GameObject target = InstantiateTarget(distractorPrefab, new Vector2(0.0f, 0.0f), targetRadius); Vector2 dir = lastGoalPos - (Vector2)GoalObject.transform.localPosition; float sign = (GoalObject.transform.localPosition.y < lastGoalPos.y) ? -1.0f : 1.0f; float offset = (targetRadius * 2f) + targetMargin; float angle = Mathf.Deg2Rad * (randomAngle + (90.0f * i)); Vector2 pos2d = new Vector2(Mathf.Sin(angle) * offset, Mathf.Cos(angle) * offset) + (Vector2)GoalObject.transform.localPosition; target.transform.localPosition = pos2d; } lastGoalPos = GoalObject.transform.localPosition; }
private void genCombinations() { // Instantiate an array to contain all the combinations combinations = new TrialVars[numTrials]; int combIndex = 0; // Iterate through each combination and populate the array for (int AIndex = 0; AIndex < A.Length; AIndex++) { for (int DIndex = 0; DIndex < D.Length; DIndex++) { for (int WIndex = 0; WIndex < W.Length; WIndex++) { combinations[combIndex++] = new TrialVars(A[AIndex], D[DIndex], W[WIndex]); } } } }
// Spawn the targets for a trial given a set of variables public void spawnTrialTargets(TrialVars variables) { clearTargets(); SpawnGoal(variables); SpawnDistractors(variables); }