protected virtual void OnEnable() { builder = (BaseBuilder)target; refreshTimer = new CoroutineTimer(8.0f); refreshTimer.StartCoroutine(); refreshTimer.TimerStoped += delegate { AssetDatabase.Refresh(); }; builder.DataChanged += delegate { refreshTimer.ResetTimer(); }; }
public void TrialUpdate() { if (!SpeechTrainingController.IsActive) { this.Started = false; return; } if (SpeechTrainingController.Verbose) { UnityEngine.Debug.Log("timer called, in state = " + CurrentTrialState.TrialState.ToString() + "..."); } switch (this.CurrentTrialState.TrialState) { case TrainingStates.STARTUP: if (SpeechTrainingController.Verbose) { UnityEngine.Debug.Log("startup..."); } this.HandPoseController.resetInitialPoseChecks(); this.HandPoseController.setControllerMode(PoseController.PoseControllerMode.CHECK); this.FeedbackDisplay.text = ""; if (SpeechTrainingController.Verbose) { UnityEngine.Debug.Log("startup done..."); } break; case TrainingStates.INIT: this.CurrentCongruencyCondition = ""; this.CorrectResponse = false; this.StimulationOnset = -1L; this.VerbalResponseTime = -1L; this.CurrentTrialState.TrialState = TrainingStates.FIXATION; this.FixationObject.transform.position = this.InitialTargetPosition; if (SpeechTrainingController.Verbose) { UnityEngine.Debug.Log("dummy fixation interval"); } StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate)); break; case TrainingStates.FIXATION: this.CurrentTrialState.TrialState = TrainingStates.SOA; this.FixationObject.transform.position = new Vector3(0, -10, 0); StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate)); // stimulation int stimulationTime = UnityEngine.Random.Range(-150, 150); float timeout = (CurrentTrialState.getSleepInterval() + stimulationTime) * .001f; StartCoroutine(this.TimeBasedStimulation(timeout)); break; case TrainingStates.SOA: this.messageObtained = false; if (this.Target.GetComponent <GraspableObject>().IsGrabbed()) { GraspController[] hands = GameObject.FindObjectsOfType <GraspController>(); foreach (GraspController hand in hands) { hand.requestRelease(); } } this.HandPoseController.setControllerMode(PoseController.PoseControllerMode.IDLE); GraspableObject graspable = this.Target.GetComponent <GraspableObject>(); graspable.ResetVariables(); bool rotate = UnityEngine.Random.value > .5f; graspable.ResetPositionAndOrientation(rotate ? 180.0f : 0.0f, this.InitialTargetPosition); if (rotate) { if (SpeechTrainingController.Verbose) { Debug.Log("rotated target..."); } // this.Target.transform.Rotate(new Vector3(180.0f, 0.0f, 0.0f)); // this.Target.transform.position = this.InitialTargetPosition; } else { if (SpeechTrainingController.Verbose) { Debug.Log("upright target..."); } // this.Target.transform.Rotate(new Vector3(0.0f, 0.0f, 0.0f)); // this.Target.transform.position = this.InitialTargetPosition; } this.Target.GetComponent <Rigidbody>().isKinematic = false; // edit JL this.Target.GetComponent <Rigidbody>().useGravity = true; this.CurrentTrialState.TrialState = TrainingStates.RESPONSE; // enable range check this.InteractionState = SampleTrialController.InteractionStates.NONE; this.CheckInteractionState = true; if (SpeechTrainingController.Verbose) { Debug.Log("Current Trial State: " + CurrentTrialState.TrialState); } break; case TrainingStates.RESPONSE: if (SpeechTrainingController.Verbose) { Debug.Log("response state..."); } this.CheckInteractionState = false; //method that saves the interaction in the TrialData // no verbal reponse... if (this.VerbalResponseTime == -1L) { this.InteractionState = SampleTrialController.InteractionStates.VERBAL_TIME_OUT; } if (this.VerbalResponseTime != -1L && !this.CorrectResponse) { this.InteractionState = SampleTrialController.InteractionStates.VERBAL_WRONG_RESPONSE; } if (this.InteractionState != SampleTrialController.InteractionStates.IN_BOX) { this.cancelTrial(); } else { this.FeedbackDisplay.text = this.positiveFeedbackTemplates[UnityEngine.Random.Range(0, this.positiveFeedbackTemplates.Length - 1)]; this.deactivateTarget(); this.InteractionState = SampleTrialController.InteractionStates.NONE; // clear monitor this.messageObtained = false; this.PoseCheckTimeStamp = -1L; } this.CurrentCongruencyCondition = ""; this.CorrectResponse = false; this.StimulationOnset = -1L; this.VerbalResponseTime = -1L; this.LastErrorCode = "none"; this.CurrentTrialState.TrialState = TrainingStates.WAITING; StartCoroutine(this.FeedbackInterval()); break; } }
// timer with possible repetition public static IEnumerator Start(float waitingIntervalInSeconds, bool repeatTimer, Action callback) { CoroutineTimer timer = new CoroutineTimer(waitingIntervalInSeconds, repeatTimer, callback); return(timer.Start()); }
public void TrialUpdate() { if (!GraspTrainingController.IsActive) { this.Started = false; return; } if (this.CurrentTrialState.TrialState == TrainingStates.RESPONSE && SampleTrialController.Millis - this.TargetOnsetTime < 1000L) { return; } if (GraspTrainingController.Verbose) { UnityEngine.Debug.Log("timer called, in state = " + CurrentTrialState.TrialState.ToString() + "..."); } switch (this.CurrentTrialState.TrialState) { case TrainingStates.STARTUP: if (GraspTrainingController.Verbose) { UnityEngine.Debug.Log("startup..."); } this.HandPoseController.resetInitialPoseChecks(); this.HandPoseController.setControllerMode(PoseController.PoseControllerMode.CHECK); this.FeedbackDisplay.text = ""; if (this.variableMapping) { this.OffsetController.DriftFactor = this.master.visualOffsets[UnityEngine.Random.Range(0, this.master.visualOffsets.Length)]; } else { this.OffsetController.DriftFactor = 0.0f; } if (GraspTrainingController.Verbose) { UnityEngine.Debug.Log("startup done..."); } break; case TrainingStates.INIT: this.CurrentTrialState.TrialState = TrainingStates.FIXATION; this.FixationObject.transform.position = this.InitialTargetPosition; this.master.GraspTrainingTrialStart(); if (GraspTrainingController.Verbose) { UnityEngine.Debug.Log("dummy fixation interval"); } StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate)); break; case TrainingStates.FIXATION: this.CurrentTrialState.TrialState = TrainingStates.SOA; this.FixationObject.transform.position = new Vector3(0, -10, 0); if (this.variableMapping) { this.OffsetController.ApplyDrift = true; } else { this.OffsetController.ApplyDrift = false; } StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate)); break; case TrainingStates.SOA: if (this.Target.GetComponent <GraspableObject>().IsGrabbed()) { GraspController[] hands = GameObject.FindObjectsOfType <GraspController>(); foreach (GraspController hand in hands) { hand.requestRelease(); } } this.HandPoseController.setControllerMode(PoseController.PoseControllerMode.IDLE); GraspableObject graspable = this.Target.GetComponent <GraspableObject>(); graspable.ResetVariables(); if (this.bottleOrientationMode == "upright") { graspable.ResetPositionAndOrientation(0.0f, this.InitialTargetPosition); if (GraspTrainingController.Verbose) { Debug.Log("upright target..."); } // this.Target.transform.Rotate(new Vector3(0.0f, 0.0f, 0.0f)); // this.Target.transform.position = this.InitialTargetPosition; } else if (this.bottleOrientationMode == "upsidedown") { graspable.ResetPositionAndOrientation(180.0f, this.InitialTargetPosition); if (GraspTrainingController.Verbose) { Debug.Log("rotated target..."); } // this.Target.transform.Rotate(new Vector3(180.0f, 0.0f, 0.0f)); // this.Target.transform.position = this.InitialTargetPosition; } else if (this.bottleOrientationMode == "random") { if (UnityEngine.Random.value > .5f) { graspable.ResetPositionAndOrientation(180.0f, this.InitialTargetPosition); if (GraspTrainingController.Verbose) { Debug.Log("rotated target..."); } // this.Target.transform.Rotate(new Vector3(180.0f, 0.0f, 0.0f)); // this.Target.transform.position = this.InitialTargetPosition; } else { graspable.ResetPositionAndOrientation(0.0f, this.InitialTargetPosition); if (GraspTrainingController.Verbose) { Debug.Log("upright target..."); } // this.Target.transform.Rotate(new Vector3(0.0f, 0.0f, 0.0f)); // this.Target.transform.position = this.InitialTargetPosition; } } else { UnityEngine.Debug.Log("unknown orientation mode: " + this.bottleOrientationMode + "..."); } this.Target.GetComponent <Rigidbody>().isKinematic = false; // edit JL this.Target.GetComponent <Rigidbody>().useGravity = true; this.CurrentTrialState.TrialState = TrainingStates.RESPONSE; // enable range check this.InteractionState = SampleTrialController.InteractionStates.NONE; this.CheckInteractionState = true; this.RangeCheck.clearMonitor(); this.RangeCheck.monitorObject(this.Target); this.TargetOnsetTime = SampleTrialController.Millis; if (Verbose) { Debug.Log("Current Trial State: " + CurrentTrialState.TrialState); } break; case TrainingStates.RESPONSE: if (GraspTrainingController.Verbose) { Debug.Log("response state..."); } this.CheckInteractionState = false; this.OffsetController.ApplyDrift = false; if (this.InteractionState != SampleTrialController.InteractionStates.IN_BOX) { this.cancelTrial(); // reset trial state... //this.CurrentTrialState.TrialState = TrainingStates.STARTUP; //StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate)); } else { this.FeedbackDisplay.text = this.positiveFeedbackTemplates[UnityEngine.Random.Range(0, this.positiveFeedbackTemplates.Length - 1)]; this.deactivateTarget(); this.InteractionState = SampleTrialController.InteractionStates.NONE; // clear monitor this.RangeCheck.clearMonitor(); this.PoseCheckTimeStamp = -1L; //this.CurrentTrialState.TrialState = TrainingStates.STARTUP; //StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate)); } this.CurrentTrialState.TrialState = TrainingStates.WAITING; StartCoroutine(this.FeedbackInterval()); break; } }