/// <summary> /// Generate task /// </summary> /// <param name="slot">The slot the instrument argument is supposed to go in</param> /// <param name="instrument">The instrument for this task</param> public InstrumentPositionTask(InstrumentPositionTaskSlot slot, Instrument.INSTRUMENT_TAG instrument) { // Hacky: all tasks of this type have the same instruction, which is currently hardcoded // (this feature was requested later in the project and the 'Task' class wasn't very suitable for this particular type) instructions.Add("New task: position the instruments for a <b><u>Spay dog</u></b>"); m_slot = slot; m_instrument = instrument; }
/// <summary> /// Check if the instrument was placed in the right slot /// </summary> /// <param name="list">List of generic arguments. Index 0 must be the instrument selected tag, index 1 must be the slot it was placed in</param> /// <returns>Whether the task was completed successfully</returns> public override STATUS Evaluate(params object[] list) { Instrument.INSTRUMENT_TAG instrumentSelected = (Instrument.INSTRUMENT_TAG)list[0]; InstrumentPositionTaskSlot slotPlacedTo = (InstrumentPositionTaskSlot)list[1]; Session session = (Session)list[2]; if (slotPlacedTo != m_slot) { session.sessionResults.Log_FailedToPositionInstrument(slotPlacedTo.CorrectInstrument, instrumentSelected); return(STATUS.COMPLETED_FAIL); } else { session.sessionResults.Log_CorrectlyPositionedInstrument(instrumentSelected); return(STATUS.COMPLETED_SUCCESS); } }
public InstrumentPositionTaskSlot GetInstrumentPositionTaskSlotRaycastFromCamera(float raycastLength) { InstrumentPositionTaskSlot toReturn = null; if (m_raycastingCamera != null) { RaycastHit hit; Ray ray = new Ray(m_raycastingCamera.transform.position, m_raycastingCamera.transform.forward); if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask("InstrumentPosTaskSlot"))) { Transform objectHit = hit.transform; InstrumentPositionTaskSlot instrument = objectHit.gameObject.GetComponent <InstrumentPositionTaskSlot>(); toReturn = instrument; } } return(toReturn); }
/// <summary> /// Callback invoked when an insturment is placed on a slot /// </summary> /// <param name="instrumentTag">The instrument placed</param> /// <param name="slot">The slot</param> /// <returns></returns> public bool OnInstrumentPlaced(Instrument.INSTRUMENT_TAG instrumentTag, InstrumentPositionTaskSlot slot) { if (m_currentSession != null) { // If current task is to position the instruments, select the chosen instrument. InstrumentPositionTask instrumentPositionTask = null; //Find the task related to slot foreach (InstrumentPositionTask t in m_currentSession.tasks) { if (t.m_instrument == instrumentTag) { instrumentPositionTask = t; } } // Cjeck if the instrument was in the right slot Task.STATUS status = instrumentPositionTask.Evaluate(instrumentTag, slot, m_currentSession); bool success = false; // If training mode, give feedback if (status == Task.STATUS.COMPLETED_SUCCESS && !GameManager.Instance.IsAssessmentMode()) { GUIManager.Instance.GetMainCanvas().DogPopUp(2, "Correct placement"); success = true; } else if (status == Task.STATUS.COMPLETED_FAIL) { if (!GameManager.Instance.IsAssessmentMode()) { GUIManager.Instance.GetMainCanvas().DogPopUp(2, "Wrong placement"); } m_currentSession.sessionResults.errors++; } return(success); } return(false); }
private void UpdatePointingInstrumentPositionTaskSlot() { InstrumentPositionTaskSlot slot = m_instrumentSelector.GetInstrumentPositionTaskSlotRaycastFromCamera(RaycastLength); // If I'm looking at an instrument and it's not the one i was already looking at if (m_selectedInstrumentToPlace != null && slot != null && slot != m_currentlyPointingInstrumentPositionTaskSlot) { if (m_currentlyPointingInstrumentPositionTaskSlot != null) { m_currentlyPointingInstrumentPositionTaskSlot.OnReleasedPointing(); } slot.OnPointing(); m_currentlyPointingInstrumentPositionTaskSlot = slot; } else if (slot == null) // If no hit { if (m_currentlyPointingInstrumentPositionTaskSlot != null) { m_currentlyPointingInstrumentPositionTaskSlot.OnReleasedPointing(); m_currentlyPointingInstrumentPositionTaskSlot = null; } } }