public static bool tryGetPreparedExercise(Exercise e, out List <AnimationInfo> animationInfo, float animationLength)
    {
        float TIME_ERROR = 0.1f;

        animationInfo = null;
        //TODO: Evaluar borrar esta correccion cuando se tenga claridad de todos los ejercicios
        e.Limb = Limb.Left;


        string serializedPreparedExercises = PlayerPrefs.GetString("ExerciseCache");

        if (serializedPreparedExercises == null || serializedPreparedExercises == String.Empty)
        {
            _preparedExercises = new Dictionary <Exercise, List <AnimationInfo> >();
        }
        else
        {
            _preparedExercises = (Dictionary <Exercise, List <AnimationInfo> >)JsonConvert.DeserializeObject <Dictionary <Exercise, List <AnimationInfo> > >(serializedPreparedExercises);
        }


        if (_preparedExercises.TryGetValue(e, out animationInfo))
        {
            //No sé por qué, pero debe estar comentado para que funcione.
            //if (Math.Abs(animationInfo[animationInfo.Count / 2].time - animationLength) <= TIME_ERROR)
            return(true);

            DebugLifeware.Log("Encontrado el exercis saved pero no cumle con el TIME_ERROR", DebugLifeware.Developer.Marco_Rojas);
        }
        else
        {
            DebugLifeware.Log("No encontrado el ejercicio saved.", DebugLifeware.Developer.Marco_Rojas);
        }
        return(false);
    }
Beispiel #2
0
    /// <summary>
    /// Debug log filtrador por desarrollador, se pueden concatenar varios desarrolladores.
    /// Ejemplo: LifewareTools.Log("Prueba", LifewareTools.Developer.Marco_Rojas | LifewareTools.Developer.Alfredo_Gallardo);
    /// </summary>
    /// <param name="message"></param>
    /// <param name="logger">Desarrollador o desarrolladores concatenados.</param>
    public static void Log(object message, Developer logger)
    {
        string msg = DebugLifeware.formatMessage(message, logger);

        if (actualDeveloper.HasValue && (logger & actualDeveloper.Value) != 0)
        {
            Debug.Log(msg);
        }
    }
 public static void InsertPreparedExercise(Exercise e, List <AnimationInfo> animationInfo)
 {
     //TODO: Evaluar borrar esta correccion cuando se tenga claridad de todos los ejercicios
     e.Limb = Limb.Left;
     if (!_preparedExercises.ContainsKey(e))
     {
         _preparedExercises.Add(e, animationInfo);
         DebugLifeware.Log("Saving exercise", DebugLifeware.Developer.Marco_Rojas);
         PlayerPrefs.SetString("ExerciseCache", JsonConvert.SerializeObject(_preparedExercises));
     }
     else
     {
         throw new Exception("Exercise already exists");
     }
 }
Beispiel #4
0
    public void PrepareExerciseWeb(string s)
    {
        RaiseEvent(OnPrepareExerciseStart, PrepareStatus.Preparing);
        PrepareExerciseWebParams pwp = JsonConvert.DeserializeObject <PrepareExerciseWebParams>(s);
        Exercise e = (pwp.Exercise) as Exercise;

        this.prepareCaller = (Caller)(pwp.Caller);
        //Exercise e = JsonConvert.DeserializeObject<Exercise>(s);

        behaviour = AnimationBehaviour.GetBehaviour(e.Movement, e.Limb);
        if (behaviour == null)
        {
            DebugLifeware.LogAllDevelopers("Importante: Behaviour no encontrado");
            RaiseEvent(OnPrepareExerciseEnd, PrepareStatus.NotFound);
            return;
        }
        behaviour.RepetitionEnd += behaviour_PrepareEndWeb;
        timeSinceStartPrepareWeb = Time.time;
        behaviour.PrepareWeb();
        CurrentExercise = e;
    }
Beispiel #5
0
    /*  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;
        }
    }
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (_BehaviourState == AnimationBehaviourState.INITIAL_POSE)
        {
            if (!animator.IsInTransition(0))
            {
                animator.speed = 0;
            }
            return;
        }

        DateTime temp = DateTime.Now;

        if (_BehaviourState == AnimationBehaviourState.PREPARING_WITH_PARAMS)
        {
            animator.speed  = 0;
            stayInPoseState = StayInPoseState.Resting;
            BeginRep        = false;
            this.Stop();
            OnRepetitionEnd();
        }

        else 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;
                animator.speed  = this._RealParams.ForwardSpeed;
                startHoldTime   = Time.time;
                stayInPoseState = StayInPoseState.HoldingOn;
            }

            //Si ya pasó el tiempo indicado realizando el movimiento
            if (stayInPoseState == StayInPoseState.HoldingOn && (Time.time - startHoldTime) >= this._RealParams.SecondsInPose)
            {
                DebugLifeware.Log("Tiempo en pose maxima = " + (Time.time - startHoldTime).ToString(), DebugLifeware.Developer.Alfredo_Gallardo);
                animator.speed = 0;
                //startHoldTime = 0;
                stayInPoseState = StayInPoseState.Resting;
                BeginRep        = false;
                if ((!this.IsWeb) && (!this.IsInInstruction) && this._BehaviourState != AnimationBehaviourState.PREPARING_WITH_PARAMS)
                {
                    this.PauseAnimation();
                }
                else if ((this.IsWeb) || (this.IsInInstruction) && this._BehaviourState == AnimationBehaviourState.RUNNING_WITH_PARAMS)
                {
                    endRepTime = DateTime.Now;
                }

                /*
                 * if(this._BehaviourState == AnimationBehaviourState.PREPARING_WITH_PARAMS)
                 * {
                 *  this.Stop();
                 * }*/
                OnRepetitionEnd();
            }


//            //Si ya pasó el tiempo en el ángulo máximo
//            else if(stayInPoseState == StayInPoseState.HoldingOn && Time.time - startHoldTime >= _realLerpParams.SecondsInPose)
//            {
//                //DebugLifeware.Log("Para atrás", DebugLifeware.Developer.Marco_Rojas);
//                animator.StartRecording(0);
//                animator.speed = -1;
//                animator.StopRecording();
//                stayInPoseState = StayInPoseState.Leaving;
//            }

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

//                if (!this.isWeb && _behaviourState != AnimationBehaviourState.PREPARING_WITH_PARAMS && (!IsInterleaved || (IsInterleaved && limb == Limb.Right)))
//                    this.PauseAnimation();
//                if (IsInterleaved && this._BehaviourState == AnimationBehaviourState.RUNNING_WITH_PARAMS)
//                {
//                    //DebugLifeware.Log("cambiando limb", DebugLifeware.Developer.Marco_Rojas);
//                    haCambiadoDeEstado = false;
//                    animator.SetTrigger("ChangeLimb");
//                }
//                OnRepetitionEnd();

//                if (_behaviourState == AnimationBehaviourState.PREPARING_WITH_PARAMS)
//                    _behaviourState = AnimationBehaviourState.STOPPED;

//            }

//            else if (stayInPoseState == StayInPoseState.Resting && Time.time - startRestTime>= _realLerpParams.SecondsBetweenRepetitions)
//            {
//                //DebugLifeware.Log("descansando", DebugLifeware.Developer.Marco_Rojas);
//                animator.speed = 1;
//                stayInPoseState = StayInPoseState.GoingTo;

//            }
//            //DebugLifeware.Log("termino", DebugLifeware.Developer.Marco_Rojas);
        }
    }