public void Init() { listTranslation = new List <Translation>(); currentTranslation = null; startPosOverride = null; state = State.idle; fLerp = 0; }
public void Play(string _name, State _mode, bool bFromCurPos) { if (bFromCurPos) { startPosOverride = new Translation.KeyPose(trHandled.position, trHandled.rotation, null); } SetCurrent(_name); PlayCurrent(_mode); }
private void ComputeTranslationSector() { vFrom = (startPosOverride != null) ? startPosOverride.Position : currentTranslation.listKeyPoses[currentTranslation.iCurrentKeyPose].Position; keyPosToFollow = currentTranslation.listKeyPoses[currentTranslation.iCurrentKeyPose + (int)state]; vTo = currentTranslation.listKeyPoses[currentTranslation.iCurrentKeyPose + (int)state].Position; fSpeed = currentTranslation.speed / Vector3.Magnitude(vFrom - vTo); }
private void UpdateTranslation() { if (bFollow) { ComputeTranslationSector(); } fLerp += Time.unscaledDeltaTime * fSpeed; trHandled.position = Vector3.Lerp(vFrom, vTo, fLerp); Quaternion qFrom = (startPosOverride != null) ? startPosOverride.rotation : currentTranslation.listKeyPoses[currentTranslation.iCurrentKeyPose].rotation; Quaternion qTo = currentTranslation.listKeyPoses[currentTranslation.iCurrentKeyPose + (int)state].rotation; trHandled.rotation = Quaternion.Lerp(qFrom, qTo, fLerp); if (fLerp >= 1) { if (startPosOverride != null) { startPosOverride = null; } currentTranslation.iCurrentKeyPose += (int)state; if ((currentTranslation.iCurrentKeyPose >= currentTranslation.listKeyPoses.Count - 1) || (currentTranslation.iCurrentKeyPose <= 0)) // Si la Translation est terminée { state = State.idle; } else // Si la translation n'est pas terminée { fLerp = 0; ComputeTranslationSector(); } } }