private float t; //to keep track of how far we've gone towards our goal if we're timed // When this method is called, the GameObject moves towards destination // at the given speed and will keep moving until it reaches the destination. public void LerpToAtSpeed(Vector3 destination, float speed) { MovingSetup(); movingDestination = transform.InverseTransformPoint(destination); state = LerpState.Speed; movingSpeed = speed; }
private void Update() { if (state != LerpState.None) { switch (state) { case LerpState.Speed: float distCovered = (Time.time - startTime) * movingSpeed; float fracJourney = distCovered / journeyLength; transform.localPosition = Vector3.Lerp(startPosition, movingDestination, fracJourney); break; case LerpState.Time: t += Time.deltaTime / movingTime; transform.localPosition = Vector3.Lerp(startPosition, movingDestination, t); break; } // If we've reached our destination, we're done. if (movingDestination == transform.localPosition) { state = LerpState.None; OnCompleted(); } } }
// When this method is called, the GameObject moves towards the destination // and reaches it in the given amount of time (in seconds). public void LerpToInTime(Vector3 destination, float time) { MovingSetup(); movingDestination = transform.InverseTransformPoint(destination); state = LerpState.Time; movingTime = time; t = 0.0f; }
/// <summary> /// 補間移動を開始する /// </summary> public virtual void StartLerp() { //開始時の状態に変化 this.transform.position = this.startPosition; this.transform.eulerAngles = this.startRotation; this.transform.localScale = this.startScale; this.currentState = LerpState.LERPING; }
void HandleMenuTouchControls() { Touch[] touches = Input.touches; if (touches.Length > 0) // Make Sure There Are Touches On Screen { if (Mathf.Abs(touches[0].deltaPosition.x) > menuClosingSwipeStrength) { if (menuState == MenuState.LeftMenuOpen) { lerpState = LerpState.LerpingLeftPanelOut; startTime = Time.time; } else if (menuState == MenuState.RightMenuOpen) { lerpState = LerpState.LerpingRightPanelOut; startTime = Time.time; } } } }
// OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //} // OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here. //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //} /// <summary> /// Comienza la interpolación entre 0 y el tiempo donde está el ángulo requerido (LerpTime), aplicando las velocidades concéntras y excéntricas indicadas /// </summary> /// <param name="_lerpTime">Tiempo donde se encuentra el ángulo al que se quiere llegar</param> /// <param name="_forwardSpeed">Velocidad concéntrica</param> /// <param name="_backwardSpeed">Velocidad excéntrica</param> public void StartLerp() { _currentLerpState = LerpState.Forward; if (_BehaviourState == AnimationBehaviourState.PREPARING_DEFAULT || _BehaviourState == AnimationBehaviourState.PREPARING_WEB || _BehaviourState == AnimationBehaviourState.RUNNING_DEFAULT) { _currentParams = new BehaviourParams(defaultAnimationLength, 1, 1, 0, 3); timeTakenDuringLerp = (float)Math.Floor(defaultAnimationLength * 10) / 10; Debug.Log("1timeTakenDuringLerp " + timeTakenDuringLerp); } else { _currentParams = _RealParams; timeTakenDuringLerp = (float)Math.Floor(GetAnimationInfo(_currentParams.Angle, _timeAndAngles).time * 10) / 10; Debug.Log("2timeTakenDuringLerp " + timeTakenDuringLerp); } //Normalizo el tiempo que tardo en parar timeTakenDuringForwardLerp = timeTakenDuringLerp / _currentParams.ForwardSpeed; timeTakenDuringBackwardLerp = timeTakenDuringLerp / _currentParams.BackwardSpeed; forwardSpeed = _currentParams.ForwardSpeed; backwardSpeed = _currentParams.BackwardSpeed; BeginLerp(0, forwardSpeed, true); }
void LerpMenu(LerpState lerpState, Transform target, float time) { if (lerpState == LerpState.LerpingLeftPanelIn) { target.position = Vector3.Lerp(leftPanelOutDock.position, leftPanelInDock.position, time); return; } if (lerpState == LerpState.LerpingLeftPanelOut) { target.position = Vector3.Lerp(leftPanelInDock.position, leftPanelOutDock.position, time); return; } if (lerpState == LerpState.LerpingRightPanelIn) { target.position = Vector3.Lerp(rightPanelOutDock.position, rightPanelInDock.position, time); return; } if (lerpState == LerpState.LerpingRightPanelOut) { target.position = Vector3.Lerp(rightPanelInDock.position, rightPanelOutDock.position, time); return; } }
/* 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; } }
/* 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; } }
void Update() { switch (menuState) { case MenuState.Closed: HandleWorldViewTouchControls(); return; case MenuState.LeftMenuOpen: if (lerpState != LerpState.None) // Handle Lerping { float normalizedTime = 0; if (lerpState == LerpState.LerpingLeftPanelIn) { normalizedTime = Mathf.Clamp01(1 - ((startTime + lerpTime) - Time.time) / lerpTime); } else if (lerpState == LerpState.LerpingLeftPanelOut) { normalizedTime = Mathf.Clamp01(1 - ((startTime + lerpTime) - Time.time) / lerpTime); } LerpMenu(lerpState, leftPanel, normalizedTime); if (normalizedTime == 1) { if (lerpState == LerpState.LerpingLeftPanelOut || lerpState == LerpState.LerpingRightPanelOut) { menuState = MenuState.Closed; } lerpState = LerpState.None; } } else // Handle Any Menu Interactions { HandleMenuTouchControls(); } return; case MenuState.RightMenuOpen: if (lerpState != LerpState.None) // Handle Lerping { float normalizedTime = 0; if (lerpState == LerpState.LerpingRightPanelIn) { normalizedTime = Mathf.Clamp01(1 - ((startTime + lerpTime) - Time.time) / lerpTime); } else if (lerpState == LerpState.LerpingRightPanelOut) { normalizedTime = Mathf.Clamp01(1 - ((startTime + lerpTime) - Time.time) / lerpTime); } LerpMenu(lerpState, rightPanel, normalizedTime); if (normalizedTime == 1) { if (lerpState == LerpState.LerpingLeftPanelOut || lerpState == LerpState.LerpingRightPanelOut) { menuState = MenuState.Closed; } lerpState = LerpState.None; } } else // Handle Any Menu Interactions { HandleMenuTouchControls(); } return; default: Debug.LogError("SwitchCase Isnt Meant To Get Here PANIC! >:O"); break; } }
bool HandleWorldViewTouchControls() { Touch[] touches = Input.touches; if (touches.Length > 0) // Make Sure There Are Touches On Screen { // Zoom Camera In Out if (touches.Length >= 2) { float distance = Vector2.Distance(touches[0].position, touches[1].position); // Fingers Moved Away From Each OTher if (distance > zoomFingerDistanceLastFrame + zoomMagnitude) { cam.UpdateZoomDistance(-distance / zoomTouchSensitivity); } else if (distance < zoomFingerDistanceLastFrame - zoomMagnitude) // Fingers Moved Closer { cam.UpdateZoomDistance(distance / zoomTouchSensitivity); } // Set it up for next frame zoomFingerDistanceLastFrame = distance; return(true); } // If Just A Press if (touches[0].phase == TouchPhase.Began) { elegibleForPress = true; initialPress = touches[0].position; } else if (Vector2.Distance(initialPress, touches[0].position) > pressElegibilitySensitivity && touches[0].position.y > Screen.height * 0.20f) // Remves the elegibility of it being a press if over a threshold { elegibleForPress = false; } else if (touches[0].phase == TouchPhase.Ended && elegibleForPress && touches[0].position.y > Screen.height * 0.20f) { Ray ray = Camera.main.ScreenPointToRay(touches[0].position); RaycastHit hit; LayerMask layerMask = (1 << LayerMask.NameToLayer("Targetable")); if (Physics.Raycast(ray, out hit, 1000f, layerMask)) { if (hit.collider != null) { cam.SetParameters(hit.collider.GetComponent <CameraParameters>()); if (hit.collider.CompareTag("Satellite")) { SatelliteDetails details = hit.collider.GetComponent <SatelliteDetails>(); missionText.text = details.MissionText; satelliteDetailsText.text = details.DetailsText; parentObject.SetActive(true); } else { parentObject.SetActive(false); } } } } // Open Left UI Panel if (touches[0].position.x <= Screen.width * leftBorderPercentage) // If Finger Is On The Left Side Of The Screen { if (touches[0].deltaPosition.magnitude > swipeMagnitude && touches[0].deltaPosition.x > 0) // If Swipe Was Strong Enough Open Menu { if (menuState == MenuState.Closed) // If Menu Is Closed Open It { lerpState = LerpState.LerpingLeftPanelIn; menuState = MenuState.LeftMenuOpen; startTime = Time.time; return(true); } } return(false); } // Open Right UI Panel if (touches[0].position.x > Screen.width * rightBorderPercentage) // If Finger Is On The Left Side Of The Screen { if (touches[0].deltaPosition.magnitude > swipeMagnitude && touches[0].deltaPosition.x < 0) // If Swipe Was Strong Enough Open Menu { if (menuState == MenuState.Closed) // If Menu Is Closed Open It { lerpState = LerpState.LerpingRightPanelIn; menuState = MenuState.RightMenuOpen; startTime = Time.time; return(true); } } return(false); } // Rotate Camera Around Object if (touches[0].position.x > Screen.width * leftBorderPercentage && touches[0].position.x <Screen.width * rightBorderPercentage && touches[0].position.y> Screen.height * 0.20f) // If Finger Is Inside External Bounds Screen { if (touches[0].deltaPosition.magnitude > swipeMagnitude) // If Swipe Was Strong Enough Open Menu { // Add Angles To Rotation Vector2 delta = touches[0].deltaPosition / rotateTouchSensitivity; cam.UpdateRotation(delta); } return(true); } } return(false); }