StartRecording() 개인적인 메소드

private StartRecording ( ) : void
리턴 void
예제 #1
0
 protected override void OnForward()
 {
     _animator.speed = 1;
     _isPlayback     = false;
     _animator.StopPlayback();
     _animator.StartRecording(0);
 }
예제 #2
0
	override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        clockBehaviour.Update();
        if (_BehaviourState == AnimationBehaviourState.INITIAL_POSE)
        {
            if (!animator.IsInTransition(0))
                animator.speed = 0;
            return;
        }
                
        #region Interpolate
        //Si no estamos en estado Stopped 
        //Y estamos preparados para hacer Lerp
        //Y el tiempo que ha transcurrido de la ultima rep es mayor al tiempo de pause entre repeticiones. O no ha habido última rep.
       
        if (_BehaviourState != AnimationBehaviourState.STOPPED && ReadyToLerp
            && (endRepTime == null || new TimeSpan(0, 0, (int)_currentParams.SecondsBetweenRepetitions) <= DateTime.Now - endRepTime))
        {
            if (!BeginRep && (!IsInterleaved || (IsInterleaved && limb == Limb.Left)) && 
                this._BehaviourState != AnimationBehaviourState.PREPARING_WEB && 
                this._BehaviourState != AnimationBehaviourState.PREPARING_WITH_PARAMS && 
                this._BehaviourState != AnimationBehaviourState.PREPARING_DEFAULT)
            {
                OnRepetitionReallyStart();
                BeginRep = true;
            }
            //if(_LerpBehaviourState == LerpBehaviourState.STOPPED)
            float timeSinceStarted = Time.time - timeStartedLerping;
            float percentageComplete = 0f;
            /*
            switch (_currentLerpState)
            {
                case LerpState.Forward:
                    
                    percentageComplete = timeSinceStarted / timeTakenDuringForwardLerp;
                    Debug.Log("1 " + percentageComplete + "= " + timeSinceStarted + " / " + timeTakenDuringForwardLerp + " " + animator.GetCurrentAnimatorStateInfo(0).normalizedTime );
                    break;

                case LerpState.Stopped:
                    if (_lastLerpState == LerpState.Forward)
                    {
                        percentageComplete = timeSinceStarted / timeTakenDuringForwardLerp;
                        Debug.Log("2 " + percentageComplete + "= " + timeSinceStarted + " / " + timeTakenDuringForwardLerp + " " + animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
                    }

                    //De ser true, indica que termino una repeticion
                    else if (_lastLerpState == LerpState.Backward)
                    {
                        percentageComplete = timeSinceStarted / timeTakenDuringBackwardLerp;
                        Debug.Log("3 " + percentageComplete + "= " + timeSinceStarted + " / " + timeTakenDuringBackwardLerp + " " + animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
                    }
                    break;

                case LerpState.Backward:
                    percentageComplete = timeSinceStarted / timeTakenDuringBackwardLerp;
                    Debug.Log("4 " + percentageComplete + "= " + timeSinceStarted + " / " + timeTakenDuringBackwardLerp + " " + animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
                    break;
            }*/

            percentageComplete = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;

            //float normalizedSpeed;
            //if (percentageComplete < 0.5)
            //    normalizedSpeed = timeSinceStarted/timeTakenDuringForwardLerp * 4;
            //else
            //    normalizedSpeed = 4f- timeSinceStarted / timeTakenDuringForwardLerp * 4;
            //Aplico el suavizado "Smotherstep"
            //percentageComplete = percentageComplete * percentageComplete * (3f - 2f * percentageComplete);
            //float percentageSmotherstep = timeSinceStarted * timeSinceStarted * timeSinceStarted * (timeSinceStarted * (6f * timeSinceStarted - 15f) + 10f);

            float sp = endPosition + startPosition;


            if (!holdingPose)
            {
                animator.StartRecording(0);
                animator.speed = sp;// Mathf.Lerp(startPosition, endPosition, normalizedSpeed);
                                    //Debug.Log("% "+ percentageComplete + "normalized speed " + normalizedSpeed + "  speed " + animator.speed);
                animator.StopRecording();
            }

            float DELTA = 0.03f;
            if ((animator.speed > 0  && percentageComplete >= 1.0f - DELTA) ||
                (animator.speed < 0 && percentageComplete <= 0f + DELTA))
            {
                Debug.Log("int end " + percentageComplete);
                InterpolationEnd();
            }
        }
        else if(this._BehaviourState == AnimationBehaviourState.RUNNING_WITH_PARAMS)
        {
            animator.speed = 0;
        }


        if (_BehaviourState == AnimationBehaviourState.PREPARING_WITH_PARAMS)
        {
            timeSinceCapture += Time.deltaTime;
            if (timeSinceCapture > INTERVAL)
            {
                timeSinceCapture = timeSinceCapture - INTERVAL;
                /*
                if (exerciseDataGenerator == null)
                    exerciseDataGenerator = GameObject.FindObjectOfType<Detector.ExerciseDataGenerator>();
                if (this.exerciseDataGenerator != null)
                    this.exerciseDataGenerator.CaptureData();*/
            }
        }

        
        #endregion
        if (_BehaviourState == AnimationBehaviourState.PREPARING_DEFAULT || _BehaviourState == AnimationBehaviourState.PREPARING_WEB)
            this.SaveTimesAngle(stateInfo);
        lastReadyToLerp = ReadyToLerp;


        JointTypePlanoResult tempJointTypePlanoResult = MovementJointMatch.movementJointMatch[new MovementLimbKey(movement, limb)];
        ArticulacionClass joint = AnimatorScript.instance.utils.getArticulacion(tempJointTypePlanoResult.jointType);
        AnimationInfo tempAnimationInfo = new AnimationInfo();
        float time = stateInfo.normalizedTime; //* stateInfo.length;
        switch (tempJointTypePlanoResult.plain)
        {
            case Plano.planos.planoFrontal:
                tempAnimationInfo = new AnimationInfo(time, joint.AngleFrontal);
                break;
            case Plano.planos.planoHorizontal:
                tempAnimationInfo = new AnimationInfo(time, joint.AngleHorizontal);
                break;
            case Plano.planos.planoSagital:
                tempAnimationInfo = new AnimationInfo(time, joint.AngleSagital);
                break;
            case Plano.planos.planoHorizontalAcostado:
                tempAnimationInfo = new AnimationInfo(time, joint.AngleHorizontalAcostado);
                break;
        }
        //GameObject.FindGameObjectWithTag("angulotexto").GetComponent<Text>().text = "Angulo " + joint.articulacion.ToString() + " : " + tempAnimationInfo.angle.ToString();

    }
예제 #3
0
	override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        timeSinceCapture += Time.deltaTime;
        if (this._BehaviourState == AnimationBehaviourState.INITIAL_POSE)//Testear si esto funciona en este behaviour.
        {
            if (!animator.IsInTransition(0))
                animator.speed = 0;
            return;
        }

        
        if (_BehaviourState == AnimationBehaviourState.PREPARING_WITH_PARAMS && timeSinceCapture > INTERVAL)
        {
            timeSinceCapture = timeSinceCapture - INTERVAL;
            /*
            if (exerciseDataGenerator == null)
                exerciseDataGenerator = GameObject.FindObjectOfType<Detector.ExerciseDataGenerator>();
            if (this.exerciseDataGenerator != null)
                this.exerciseDataGenerator.CaptureData();*/
        }
        float DELTA = 0.05f;
        DateTime temp = DateTime.Now;
        if (_BehaviourState != AnimationBehaviourState.STOPPED && (endRepTime == null || new TimeSpan(0, 0, (int)_RealParams.SecondsBetweenRepetitions) <= temp - endRepTime))
        {
            if (!BeginRep && (!IsInterleaved || (IsInterleaved && limb == Limb.Left)) &&
                this._BehaviourState != AnimationBehaviourState.PREPARING_WEB &&
                this._BehaviourState != AnimationBehaviourState.PREPARING_WITH_PARAMS &&
                this._BehaviourState != AnimationBehaviourState.PREPARING_DEFAULT)
            {
                OnRepetitionReallyStart();
                BeginRep = true;
            }

            if (stayInPoseState == StayInPoseState.GoingTo &&  stateInfo.normalizedTime + DELTA >= 1)
            {
                animator.speed = 0;
                startHoldTime = Time.time;
                stayInPoseState = StayInPoseState.HoldingOn;
                //Esperar
            }

            //Si ya pasó el tiempo en el ángulo máximo
            else if(stayInPoseState == StayInPoseState.HoldingOn && Time.time - startHoldTime >= _RealParams.SecondsInPose)
            {
                animator.StartRecording(0);
                animator.speed = -this._RealParams.BackwardSpeed;
                animator.StopRecording();
                stayInPoseState = StayInPoseState.Leaving;
            }

            else if (stayInPoseState == StayInPoseState.Leaving && stateInfo.normalizedTime - DELTA <= 0 && haCambiadoDeEstado)
            {
                BeginRep = false;
                animator.speed = 0;
                stayInPoseState = StayInPoseState.Resting;
                startRestTime = Time.time;

                if (((!this.IsWeb) && (!this.IsInInstruction)) && _BehaviourState != AnimationBehaviourState.PREPARING_WITH_PARAMS && (!IsInterleaved || (IsInterleaved && limb == Limb.Right)))
                    this.PauseAnimation();
                if (IsInterleaved && this._BehaviourState == AnimationBehaviourState.RUNNING_WITH_PARAMS)
                {
                    haCambiadoDeEstado = false;
                    animator.SetTrigger("ChangeLimb");
                }
                OnRepetitionEnd();
                if (_BehaviourState == AnimationBehaviourState.PREPARING_WITH_PARAMS)
                    this.Stop();

            }

            else if (stayInPoseState == StayInPoseState.Resting && Time.time - startRestTime>= _realParams.SecondsBetweenRepetitions)
            {
                this.animator.speed = this._realParams.ForwardSpeed;
                stayInPoseState = StayInPoseState.GoingTo;

            }
        }
        
    }
예제 #4
0
	override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
	{
        clockBehaviour.Update();

        if (_BehaviourState == AnimationBehaviourState.INITIAL_POSE)
        {
            if (!animator.IsInTransition(0))
                animator.speed = 0;
            return;
        }
		float DELTA = 0.05f;
		DateTime temp = DateTime.Now;
        if (this._BehaviourState != AnimationBehaviourState.STOPPED && !IsCentralNode)
		{
            if (!BeginRep && (!IsInterleaved || (IsInterleaved && limb == Limb.Left)) &&
			    this._BehaviourState != AnimationBehaviourState.PREPARING_WEB &&
			    this._BehaviourState != AnimationBehaviourState.PREPARING_WITH_PARAMS &&
			    this._BehaviourState != AnimationBehaviourState.PREPARING_DEFAULT)
			{
				OnRepetitionReallyStart();
				BeginRep = true;
			}

            if (this.CentralNode._StayInPoseState == StayInPoseState.GoingTo && stateInfo.normalizedTime - DELTA >= 1)
			{
                animator.speed = 0;
				startHoldTime = Time.time;
                clockBehaviour.executeRepetitionTime(this.CentralNode._RealParams.SecondsInPose);
                this.CentralNode._StayInPoseState = StayInPoseState.HoldingOn;
			}
			
			//Si ya pasó el tiempo en el ángulo máximo
			else if(this.CentralNode._StayInPoseState == StayInPoseState.HoldingOn && this.CentralNode.holdingPose)
			{
                this.CentralNode.holdingPose = false;
				animator.StartRecording(0);
				animator.speed = -this.CentralNode._RealParams.BackwardSpeed;
				animator.StopRecording();
                this.CentralNode._StayInPoseState = StayInPoseState.Leaving;
            }
			else if (this.CentralNode._StayInPoseState == StayInPoseState.Leaving && 
                stateInfo.normalizedTime - DELTA <= 0)
			{
                BeginRep = false;
				animator.speed = this.CentralNode._RealParams.ForwardSpeed;
                this.CentralNode._StayInPoseState = StayInPoseState.GoingTo;
				startRestTime = Time.time;
                animator.SetInteger("Movement", -1);
				
				if (IsInterleaved && this._BehaviourState == AnimationBehaviourState.RUNNING_WITH_PARAMS)
				{
					animator.SetTrigger("ChangeLimb");
				}
				
				if (_BehaviourState == AnimationBehaviourState.PREPARING_WITH_PARAMS)
                    _BehaviourState = AnimationBehaviourState.STOPPED;

                //OnRepetitionEnd();

            }
		}

    }