override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (hasEnteredBefore == false) { hasEnteredBefore = true; clockBehaviour = new ClockBehaviour(); clockBehaviour.executionTimerFinish += executionTimerFinish; clockBehaviour.executionTimerStart += executionTimerStart; clockBehaviour.pauseBetweenRepetitionsStart += pauseBetweenRepetitionsStart; clockBehaviour.pauseBetweenRepetitionsFinish += pauseBetweenRepetitionsFinish; } if (this._BehaviourState == AnimationBehaviourState.INITIAL_POSE) { return; } defaultAnimationLength = stateInfo.length; //Está la animación en caché if (PreparedExercises.tryGetPreparedExercise(new Exercise(movement, limb), out this._timeAndAngles, stateInfo.length)) { //Repetición de preparación if (this._BehaviourState != AnimationBehaviourState.PREPARING_DEFAULT && this._BehaviourState != AnimationBehaviourState.PREPARING_WEB) { this.StartLerp(); } else if (this._BehaviourState == AnimationBehaviourState.PREPARING_DEFAULT) { //OnRepetitionEnd(); _BehaviourState = AnimationBehaviourState.PREPARING_WITH_PARAMS; timeSinceCapture = 0; this.StartLerp(); } else if (this._BehaviourState == AnimationBehaviourState.PREPARING_WEB) { OnRepetitionEnd(); Stop(); } } //No está la animación en caché else { if (this._BehaviourState == AnimationBehaviourState.PREPARING_DEFAULT || this._BehaviourState == AnimationBehaviourState.PREPARING_WEB) { this._timeAndAngles = new List <AnimationInfo>(); this.StartLerp(); } else { throw new Exception("Animation not prepared"); } } }
/* public override void PauseAnimation() * { * DebugLifeware.Log("Puasing animation", DebugLifeware.Developer.Alfredo_Gallardo); * originalABS = this._behaviourState; * * * * _BehaviourState = AnimationBehaviourState.STOPPED; * * if (this.IsInterleaved) * if ((_Opposite as LerpBehaviour)._BehaviourState != AnimationBehaviourState.STOPPED) * _Opposite.PauseAnimation(); * * if (animator.speed < 0) * { * animator.StartRecording(0); * animator.speed *= -1; * animator.StopRecording(); * } * * //animator.SetInteger(AnimatorParams.Movement, (int)Movement.Iddle); * animator.speed = 1; * * }*/ /// <summary> /// Cuando termina una interpolacion se comprueba el estado de la animacion para continuar con el ciclo de aceleración y desaceleracion /// </summary> private void InterpolationEnd() { switch (_currentLerpState) { case LerpState.Forward: _currentLerpState = LerpState.Stopped; _lastLerpState = LerpState.Forward; animator.speed = 0; //BeginLerp(0, -backwardSpeed); this.holdingPose = true; Debug.Log("Comenzando pausa entre rep " + this._currentParams.SecondsInPose); clockBehaviour.executeRepetitionTime(this._currentParams.SecondsInPose); break; case LerpState.Stopped: //si holdingPose es TRUE el instructor esta en mantener Pose if (holdingPose == false) { Debug.Log("Holding Pose " + holdingPose + " " + _currentLerpState + " " + _lastLerpState + " " + backwardSpeed); if (_lastLerpState == LerpState.Forward) { _currentLerpState = LerpState.Backward; _lastLerpState = LerpState.Stopped; BeginLerp(0, -backwardSpeed); } //De ser true, indica que termino una repeticion else if (_lastLerpState == LerpState.Backward) { _currentLerpState = LerpState.Forward; _lastLerpState = LerpState.Forward; BeginRep = false; if (this._BehaviourState == AnimationBehaviourState.PREPARING_DEFAULT || this._BehaviourState == AnimationBehaviourState.PREPARING_WEB) { try { DebugLifeware.Log("se intentara savear", DebugLifeware.Developer.Marco_Rojas); PreparedExercises.InsertPreparedExercise(new Exercise(movement, limb), _timeAndAngles); } catch { DebugLifeware.Log("ya existia el ejercicio", DebugLifeware.Developer.Marco_Rojas); ; // do nothing } if (this._BehaviourState == AnimationBehaviourState.PREPARING_DEFAULT) { this._BehaviourState = AnimationBehaviourState.PREPARING_WITH_PARAMS; } else { this._BehaviourState = AnimationBehaviourState.STOPPED; //TODO: NO SABEMOS SI DEJAR ESTA LINEA Stop(); OnRepetitionEnd(); } } else if (this._BehaviourState == AnimationBehaviourState.PREPARING_WITH_PARAMS) { //_BehaviourState = AnimationBehaviourState.STOPPED; Stop(); OnRepetitionEnd(); //TODO: Recolectar datos y entregarlos a jorge } //Hace repeticiones hasta el infinito else if (this._BehaviourState == AnimationBehaviourState.RUNNING_DEFAULT || this._BehaviourState == AnimationBehaviourState.RUNNING_WITH_PARAMS) { OnLerpRoundTripEnd(); if (!IsInterleaved || IsInterleaved && limb == Limb.Right) { if ((!this.IsWeb) && (!this.IsInInstruction)) { this.PauseAnimation(); } OnRepetitionEnd(); Debug.Log("REPETITION END____"); } if (IsInterleaved) { if (this.limb == Limb.Left) { this._Opposite.endRepTime = null; } animator.SetTrigger("ChangeLimb"); } if (this._BehaviourState == AnimationBehaviourState.STOPPED) { endRepTime = null; ReadyToLerp = false; } else if (!IsInterleaved) { StartLerp(); //BeginLerp(0, forwardSpeed, true); //animator.Play(animator.GetCurrentAnimatorStateInfo(0).fullPathHash, 0, 0); } } } } break; case LerpState.Backward: _currentLerpState = LerpState.Stopped; _lastLerpState = LerpState.Backward; BeginLerp(-backwardSpeed, 0); break; } }