public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jObject = JObject.Load(reader); TaskType taskType = (TaskType)jObject.GetValue("taskTypes").Value <Int64>(); Task task; if (taskType.HasFlag(TaskType.Selection)) { task = new SelectionTask(); } else { task = new ManipulationTask(); } serializer.Populate(jObject.CreateReader(), task); return(task); }
private void FinishTaskActionCallback(SteamVR_Action_Boolean fromaction, SteamVR_Input_Sources fromsource) { if (taskIsFinishing || currentTask == null || currentTask.taskTypes.HasFlag(TaskType.Selection) || currentGameObjects == null || currentGameObjects.Count == 0) { return; } // check whether the objects position, rotation and scale is similar to the end object ManipulationTask manipulationTask = (ManipulationTask)currentTask; Transform startObj = currentGameObjects[0].transform; Transform endObject = currentGameObjects[1].transform; float posDiff = Vector3.Distance(endObject.position, startObj.position); float rotDiff = Quaternion.Angle(endObject.rotation, startObj.rotation); float scaleDiff = Mathf.Abs(endObject.lossyScale.x - startObj.lossyScale.x); Debug.Log(posDiff + " " + rotDiff + " " + scaleDiff); bool isScaled = currentPhase == TaskPhase.Training || Vector3.Distance(manipulationTask.startObject.scale, manipulationTask.endObject.scale) < 0.01f || Vector3.Distance(startObj.localScale, manipulationTask.startObject.scale) > 0.01f; if (posDiff <= manipulationTask.PositioningTolerance && rotDiff <= manipulationTask.RotatingTolerance && scaleDiff <= manipulationTask.ScalingTolerance && isScaled) { taskIsFinishing = true; GetInteractionTechnique().ReleaseObject(); currentTechnique.BroadcastMessage("TaskSolved", startObj.position); if (currentPhase == TaskPhase.Tasks) { MeasurementController.Instance.StopMeasurement(config, currentTechnique.name, (ManipulationTask)currentTask, posDiff, rotDiff, scaleDiff); } FadeOutAndRemoveTaskObjects(FadeInNextTaskObjects); } }
/// <summary> /// Instantiates the next task objects. /// </summary> private void CreateNextTaskObjects() { // remove current task type from the list if all corresponding tasks are solved if (taskTypeOrder.Count > 0 && tasks[taskTypeOrder[0]].Count == 0) { taskTypeOrder.RemoveAt(0); } // fade out and remove all current objects if the last task for the current interaction technique is solved // also remove the current interaction technique from the list to move on to the next technique if (taskTypeOrder.Count == 0) { if (dummyTasks.Count == 0) { FinishTechnique(); RemoveSkipTaskFile(); return; } currentTask = dummyTasks[0]; dummyTasks.RemoveAt(0); } else { currentTask = tasks[taskTypeOrder[0]][0]; } if (currentPhase != TaskPhase.Training) { UpdateSkipTaskFile(); } if (currentTask is SelectionTask selectionTask) { // instantiate pre task object GameObject preTaskObject = Instantiate(preTaskObjectPrefab, taskObjectsParent); preTaskObject.transform.position = preTaskObject.transform.position + userStartPosition; currentGameObjects.Add(preTaskObject); // instantiate task objects foreach (var obj in selectionTask.taskObjects) { InstantiateGameObject(obj); } } else { // instantiate start and end object ManipulationTask manipulationTask = (ManipulationTask)currentTask; GameObject startObject = InstantiateGameObject(manipulationTask.startObject, activeOnStart: true); InstantiateGameObject(manipulationTask.endObject, startObject.transform, true); } // moves current item to the end of the list in task and task type order lists so the training is infinite if (currentPhase == TaskPhase.Training) { tasks[taskTypeOrder[0]].MoveFirstToEnd(); taskTypeOrder.MoveFirstToEnd(); } // otherwise remove the current task from the list else if (taskTypeOrder.Count > 0) { tasks[taskTypeOrder[0]].RemoveAt(0); } // inform technique about the new task objects if needed InformTechnique(); // update status text UpdateStatusText(); }
/// <summary> /// Adds the current task to the json file. /// </summary> void AddCurrentTaskToFile() { currentTasks = File.Exists(targetFile) ? JsonHelper.DeserializeFromFile <List <Task> >(targetFile) : new List <Task>(); if (currentTaskType == TaskType.None) { Debug.Log("Please generate task first!"); return; } // determine the position where the new task should be added (so all tasks are grouped by there task type) int index; TaskType lastTaskType = TaskType.None; for (index = 0; index < currentTasks.Count; index++) { if (currentTaskType == lastTaskType && currentTasks[index].taskTypes != lastTaskType) { break; } lastTaskType = currentTasks[index].taskTypes; } if (currentTaskType.HasFlag(TaskType.Selection)) { SelectionTask taskToAdd = new SelectionTask { id = GetId(), distance = distance, actualDistance = posDistances[distance - 1], radius = radius, taskTypes = currentTaskType, timeLimit = timeLimit, taskObjects = taskObjects, minDensity = density, numberOfObjects = objectCount }; currentTasks.Insert(index, taskToAdd); } else { ManipulationTask taskToAdd = new ManipulationTask { id = GetId(), distance = distance, actualDistance = posDistances[distance - 1], radius = radius, taskTypes = currentTaskType, timeLimit = timeLimit, startObject = taskObjects[0], endObject = taskObjects[1], manipulationAmount = manipulationAmount, neededDoFs = neededDoFs, PositioningTolerance = positioningTolerance, RotatingTolerance = rotatingTolerance, ScalingTolerance = scalingTolerance }; currentTasks.Insert(index, taskToAdd); } JsonHelper.SerializeToFile(targetFile, currentTasks); Debug.Log("Successfully added task to file."); }