// preview a frame in the scene view public override void previewFrame(float frame, AMTrack extraTrack = null) { if (!obj) { return; } if (cache.Count <= 0) { return; } // if before first frame if (frame <= (float)cache[0].startFrame) { obj.position = (cache[0] as AMTranslationAction).path[0]; return; } // if beyond last frame if (frame >= (float)(cache[cache.Count - 1] as AMTranslationAction).endFrame) { obj.position = (cache[cache.Count - 1] as AMTranslationAction).path[(cache[cache.Count - 1] as AMTranslationAction).path.Length - 1]; return; } // if lies on curve foreach (AMTranslationAction action in cache) { if (((int)frame < action.startFrame) || ((int)frame > action.endFrame)) { continue; } if (action.path.Length == 1) { obj.position = action.path[0]; return; } float _value; float framePositionInPath = frame - (float)action.startFrame; if (framePositionInPath < 0f) { framePositionInPath = 0f; } AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } _value = ease(0f, 1f, framePositionInPath / action.getNumberOfFrames(), curve); AMTween.PutOnPath(obj, action.path, Mathf.Clamp(_value, 0f, 1f)); return; } }
void Update() { percent += 0.003f * speedValues[selectedSpeedIndex]; if (percent > 1f + waitPercent) { percent = waitPercent * -1f; } float x_pos_start = 50f; float x_pos_end = position.width - 50f - 80f - 200f; if (percent <= 1f) { AMTween.EasingFunction ease; AnimationCurve _curve = null; if (isCustomEase) { _curve = curve; ease = AMTween.customEase; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)getSelectedEaseIndex(category, selectedIndex)); } x_pos = ease(x_pos_start, x_pos_end, (percent < 0f ? 0f : percent), _curve); } this.Repaint(); }
// preview a frame in the scene view public override void previewFrame(float frame, AMTrack extraTrack = null) { if (!obj) { return; } if (cache.Count <= 1) { return; } // if before first frame if (frame <= (float)cache[0].startFrame) { obj.localScale = (cache[0] as AMScaleAction).startScale; return; } // if beyond last frame if (frame >= (float)(cache[cache.Count - 2] as AMScaleAction).endFrame) { obj.localScale = (cache[cache.Count - 2] as AMScaleAction).endScale; return; } // if lies on curve for (int i = 0; i <= cache.Count - 2; ++i) { AMScaleAction action = cache[i] as AMScaleAction; if (((int)frame < action.startFrame) || ((int)frame > action.endFrame)) { continue; } float _value; float framePositionInPath = frame - (float)action.startFrame; if (framePositionInPath < 0f) { framePositionInPath = 0f; } AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } _value = ease(0f, 1f, framePositionInPath / action.getNumberOfFrames(), curve); obj.localScale = Vector3.Lerp(action.startScale, action.endScale, _value); return; } }
public Vector3 getPositionAtFrame(float frame) { if (cache.Count <= 0) { return(obj.position); } // if before first frame if (frame <= (float)cache[0].startFrame) { return((cache[0] as AMTranslationAction).path[0]); } // if beyond last frame if (frame >= (float)(cache[cache.Count - 1] as AMTranslationAction).endFrame) { return((cache[cache.Count - 1] as AMTranslationAction).path[(cache[cache.Count - 1] as AMTranslationAction).path.Length - 1]); } // if lies on curve foreach (AMTranslationAction action in cache) { if (((int)frame < action.startFrame) || ((int)frame > action.endFrame)) { continue; } if (action.path.Length == 1) { return(action.path[0]); } // ease AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } float framePositionInPath = frame - (float)action.startFrame; if (framePositionInPath < 0f) { framePositionInPath = 0f; } return(AMTween.PointOnPath(action.path, Mathf.Clamp(ease(0f, 1f, framePositionInPath / action.getNumberOfFrames(), curve), 0f, 1f))); } Debug.LogError("Animator: Could not get " + obj.name + " position at frame '" + frame + "'"); return(new Vector3(0f, 0f, 0f)); }
public Quaternion getQuaternionAtPercent(float percentage, /*Vector3 startPosition, Vector3 endPosition,*/ Vector3?startVector = null, Vector3?endVector = null) { if (isLookFollow()) { obj.LookAt(startTarget); return(obj.rotation); } Vector3 _temp = obj.position; if (isSetStartPosition) { obj.position = (Vector3)startPosition; } obj.LookAt(startVector ?? startTarget.position); Vector3 eStart = obj.eulerAngles; if (isSetEndPosition) { obj.position = (Vector3)endPosition; } obj.LookAt(endVector ?? endTarget.position); Vector3 eEnd = obj.eulerAngles; obj.position = _temp; eEnd = new Vector3(AMTween.clerp(eStart.x, eEnd.x, 1), AMTween.clerp(eStart.y, eEnd.y, 1), AMTween.clerp(eStart.z, eEnd.z, 1)); Vector3 eCurrent = new Vector3(); AMTween.EasingFunction ease; AnimationCurve curve = null; if (hasCustomEase()) { curve = easeCurve; ease = AMTween.customEase; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)easeType); } eCurrent.x = ease(eStart.x, eEnd.x, percentage, curve); eCurrent.y = ease(eStart.y, eEnd.y, percentage, curve); eCurrent.z = ease(eStart.z, eEnd.z, percentage, curve); return(Quaternion.Euler(eCurrent)); }
// preview a frame in the scene view public void previewFrame(float frame, bool quickPreview = false) { if (cache == null || cache.Count <= 0) { return; } if (!component || !obj) { return; } int morph_count = 0; // if before or equal to first frame, or is the only frame if ((frame <= (float)cache[0].startFrame) || ((cache[0] as AMPropertyAction).endFrame == -1)) { //obj.rotation = (cache[0] as AMPropertyAction).getStartQuaternion(); if (fieldInfo != null) { fieldInfo.SetValue(component, (cache[0] as AMPropertyAction).getStartValue()); refreshTransform(); } else if (propertyInfo != null) { propertyInfo.SetValue(component, (cache[0] as AMPropertyAction).getStartValue(), null); refreshTransform(); } else if (methodInfo != null) { try { string[] channelNames = getMorphNames(); morph_count = channelNames.Length; } catch { // do nothing } previewMorph((cache[0] as AMPropertyAction).start_morph, morph_count); } return; } // if beyond or equal to last frame if (frame >= (float)(cache[cache.Count - 2] as AMPropertyAction).endFrame) { if (fieldInfo != null) { fieldInfo.SetValue(component, (cache[cache.Count - 2] as AMPropertyAction).getEndValue()); refreshTransform(); } else if (propertyInfo != null) { propertyInfo.SetValue(component, (cache[cache.Count - 2] as AMPropertyAction).getEndValue(), null); refreshTransform(); } else if (methodInfo != null) { string[] channelNames = getMorphNames(); morph_count = channelNames.Length; previewMorph((cache[cache.Count - 2] as AMPropertyAction).end_morph, morph_count); } return; } // if lies on property action foreach (AMPropertyAction action in cache) { if ((frame < (float)action.startFrame) || (frame > (float)action.endFrame)) { continue; } if (quickPreview && !action.targetsAreEqual()) { return; // quick preview; if action will execute then skip } // if on startFrame if (frame == (float)action.startFrame) { if (fieldInfo != null) { fieldInfo.SetValue(component, action.getStartValue()); refreshTransform(); } else if (propertyInfo != null) { propertyInfo.SetValue(component, action.getStartValue(), null); refreshTransform(); } else if (methodInfo != null) { string[] channelNames = getMorphNames(); morph_count = channelNames.Length; previewMorph(action.start_morph, morph_count); } return; } // if on endFrame if (frame == (float)action.endFrame) { if (fieldInfo != null) { fieldInfo.SetValue(component, action.getEndValue()); refreshTransform(); } else if (propertyInfo != null) { propertyInfo.SetValue(component, action.getEndValue(), null); refreshTransform(); } else if (methodInfo != null) { string[] channelNames = getMorphNames(); morph_count = channelNames.Length; previewMorph(action.end_morph, morph_count); } return; } // else find value using easing function AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } float framePositionInAction = frame - (float)action.startFrame; if (framePositionInAction < 0f) { framePositionInAction = 0f; } float percentage = framePositionInAction / action.getNumberOfFrames(); //qCurrent.x = ease(qStart.x,qEnd.x,percentage); if (action.valueType == (int)ValueType.MorphChannels) { string[] channelNames = getMorphNames(); morph_count = channelNames.Length; List <float> morphCurrent = new List <float>(); //bool isMorphValid = true; for (int p = 0; p < morph_count; p++) { if (action.start_morph.Count <= p || action.end_morph.Count <= p) { //isMorphValid = false; //Debug.Log("p = "+p+"; invalid morph! start count: "+action.start_morph.Count+", end count: "+action.end_morph.Count); break; } morphCurrent.Add(0f); morphCurrent[p] = ease(action.start_morph[p], action.end_morph[p], percentage, curve); } /*if(isMorphValid)*/ previewMorph(morphCurrent, morph_count); } else if (action.valueType == (int)ValueType.Integer) { float vStartInteger = Convert.ToSingle(action.start_val); float vEndInteger = Convert.ToSingle(action.end_val); int vCurrentInteger = (int)ease(vStartInteger, vEndInteger, percentage, curve); if (fieldInfo != null) { fieldInfo.SetValue(component, vCurrentInteger); } else if (propertyInfo != null) { propertyInfo.SetValue(component, vCurrentInteger, null); } refreshTransform(); } else if (action.valueType == (int)ValueType.Long) { float vStartLong = Convert.ToSingle(action.start_val); float vEndLong = Convert.ToSingle(action.end_val); long vCurrentLong = (long)ease(vStartLong, vEndLong, percentage, curve); if (fieldInfo != null) { fieldInfo.SetValue(component, vCurrentLong); } else if (propertyInfo != null) { propertyInfo.SetValue(component, vCurrentLong, null); } refreshTransform(); } else if (action.valueType == (int)ValueType.Float) { float vStartFloat = Convert.ToSingle(action.start_val); float vEndLong = Convert.ToSingle(action.end_val); float vCurrentFloat = (float)ease(vStartFloat, vEndLong, percentage, curve); if (fieldInfo != null) { fieldInfo.SetValue(component, vCurrentFloat); } else if (propertyInfo != null) { propertyInfo.SetValue(component, vCurrentFloat, null); } refreshTransform(); } else if (action.valueType == (int)ValueType.Double) { float vStartDouble = Convert.ToSingle(action.start_val); float vEndDouble = Convert.ToSingle(action.end_val); double vCurrentDouble = (double)ease(vStartDouble, vEndDouble, percentage, curve); if (fieldInfo != null) { fieldInfo.SetValue(component, vCurrentDouble); } else if (propertyInfo != null) { propertyInfo.SetValue(component, vCurrentDouble, null); } refreshTransform(); } else if (action.valueType == (int)ValueType.Vector2) { Vector2 vStartVector2 = action.start_vect2; Vector2 vEndVector2 = action.end_vect2; Vector2 vCurrentVector2 = new Vector2(); vCurrentVector2.x = ease(vStartVector2.x, vEndVector2.x, percentage, curve); vCurrentVector2.y = ease(vStartVector2.y, vEndVector2.y, percentage, curve); if (fieldInfo != null) { fieldInfo.SetValue(component, vCurrentVector2); } else if (propertyInfo != null) { propertyInfo.SetValue(component, vCurrentVector2, null); } refreshTransform(); } else if (action.valueType == (int)ValueType.Vector3) { Vector3 vStartVector3 = action.start_vect3; Vector3 vEndVector3 = action.end_vect3; Vector3 vCurrentVector3 = new Vector3(); vCurrentVector3.x = ease(vStartVector3.x, vEndVector3.x, percentage, curve); vCurrentVector3.y = ease(vStartVector3.y, vEndVector3.y, percentage, curve); vCurrentVector3.z = ease(vStartVector3.z, vEndVector3.z, percentage, curve); if (fieldInfo != null) { fieldInfo.SetValue(component, vCurrentVector3); } else if (propertyInfo != null) { propertyInfo.SetValue(component, vCurrentVector3, null); } refreshTransform(); } else if (action.valueType == (int)ValueType.Color) { Color vStartColor = action.start_color; Color vEndColor = action.end_color; Color vCurrentColor = new Color(); vCurrentColor.r = ease(vStartColor.r, vEndColor.r, percentage, curve); vCurrentColor.g = ease(vStartColor.g, vEndColor.g, percentage, curve); vCurrentColor.b = ease(vStartColor.b, vEndColor.b, percentage, curve); vCurrentColor.a = ease(vStartColor.a, vEndColor.a, percentage, curve); if (fieldInfo != null) { fieldInfo.SetValue(component, vCurrentColor); } else if (propertyInfo != null) { propertyInfo.SetValue(component, vCurrentColor, null); } refreshTransform(); } else if (action.valueType == (int)ValueType.Rect) { Rect vStartRect = action.start_rect; Rect vEndRect = action.end_rect; Rect vCurrentRect = new Rect(); vCurrentRect.x = ease(vStartRect.x, vEndRect.x, percentage, curve); vCurrentRect.y = ease(vStartRect.y, vEndRect.y, percentage, curve); vCurrentRect.width = ease(vStartRect.width, vEndRect.width, percentage, curve); vCurrentRect.height = ease(vStartRect.height, vEndRect.height, percentage, curve); if (fieldInfo != null) { fieldInfo.SetValue(component, vCurrentRect); } else if (propertyInfo != null) { propertyInfo.SetValue(component, vCurrentRect, null); } refreshTransform(); } else { Debug.LogError("Animator: Invalid ValueType " + valueType.ToString()); } return; } }
public Quaternion getRotationAtFrame(float frame) { // if before or equal to first frame, or is the only frame if ((frame <= (float)cache[0].startFrame) || ((cache[0] as AMRotationAction).endFrame == -1)) { //obj.rotation = (cache[0] as AMRotationAction).getStartQuaternion(); return((cache[0] as AMRotationAction).getStartQuaternion()); } // if beyond or equal to last frame if (frame >= (float)(cache[cache.Count - 2] as AMRotationAction).endFrame) { //obj.rotation = (cache[cache.Count-2] as AMRotationAction).getEndQuaternion(); return((cache[cache.Count - 2] as AMRotationAction).getEndQuaternion()); } // if lies on rotation action foreach (AMRotationAction action in cache) { if ((frame < (float)action.startFrame) || (frame > (float)action.endFrame)) { continue; } // if on startFrame if (frame == (float)action.startFrame) { return(action.getStartQuaternion()); } // if on endFrame if (frame == (float)action.endFrame) { return(action.getEndQuaternion()); } // else find Quaternion using easing function AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } float framePositionInAction = frame - (float)action.startFrame; if (framePositionInAction < 0f) { framePositionInAction = 0f; } float percentage = framePositionInAction / action.getNumberOfFrames(); Quaternion qStart = action.getStartQuaternion(); Quaternion qEnd = action.getEndQuaternion(); Quaternion qCurrent = new Quaternion(); qCurrent.x = ease(qStart.x, qEnd.x, percentage, curve); qCurrent.y = ease(qStart.y, qEnd.y, percentage, curve); qCurrent.z = ease(qStart.z, qEnd.z, percentage, curve); qCurrent.w = ease(qStart.w, qEnd.w, percentage, curve); return(qCurrent); } Debug.LogError("Animator: Could not get " + obj.name + " rotation at frame '" + frame + "'"); return(new Quaternion(0f, 0f, 0f, 0f)); }
// preview a frame in the scene view public override void previewFrame(float frame, AMTrack extraTrack = null) { if (!obj) { return; } if (cache.Count <= 0) { return; } if (cache[0] == null) { updateCache(); } // if before or equal to first frame, or is the only frame if ((frame <= (float)cache[0].startFrame) || ((cache[0] as AMRotationAction).endFrame == -1)) { obj.rotation = (cache[0] as AMRotationAction).getStartQuaternion(); return; } // if beyond or equal to last frame if (frame >= (float)(cache[cache.Count - 2] as AMRotationAction).endFrame) { obj.rotation = (cache[cache.Count - 2] as AMRotationAction).getEndQuaternion(); return; } // if lies on rotation action foreach (AMRotationAction action in cache) { if ((frame < (float)action.startFrame) || (frame > (float)action.endFrame)) { continue; } // if on startFrame if (frame == (float)action.startFrame) { obj.rotation = action.getStartQuaternion(); return; } // if on endFrame if (frame == (float)action.endFrame) { obj.rotation = action.getEndQuaternion(); return; } // else find Quaternion using easing function AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } float framePositionInAction = frame - (float)action.startFrame; if (framePositionInAction < 0f) { framePositionInAction = 0f; } float percentage = framePositionInAction / action.getNumberOfFrames(); Quaternion qStart = action.getStartQuaternion(); Quaternion qEnd = action.getEndQuaternion(); Quaternion qCurrent = new Quaternion(); qCurrent.x = ease(qStart.x, qEnd.x, percentage, curve); qCurrent.y = ease(qStart.y, qEnd.y, percentage, curve); qCurrent.z = ease(qStart.z, qEnd.z, percentage, curve); qCurrent.w = ease(qStart.w, qEnd.w, percentage, curve); obj.rotation = qCurrent; return; } }
private void previewCameraFade(float frame, AMCameraSwitcherAction action, bool isPreview) { // if transition is None, show end camera / color if (action.cameraFadeType == (int)AMTween.Fade.None) { // reset camera fade if visible // camera if (action.endTargetType == 0) { if (action.endCamera) { AMTween.SetTopCamera(action.endCamera, cachedAllCameras); } AMCameraFade.reset(); } else { showColor(action.endColor, isPreview); } return; } // Get camerafade AMCameraFade cf = AMCameraFade.getCameraFade(isPreview); if (Application.isPlaying) { cf.keepAlivePreview = true; } cf.isReset = false; bool isReversed = action.isReversed(); int firstTargetType = (isReversed ? action.endTargetType : action.startTargetType); int secondTargetType = (isReversed ? action.startTargetType : action.endTargetType); // Set render texture or colors if render texture is used setRenderTexture(cf, frame, firstTargetType, secondTargetType, isReversed, action, isPreview); setColors(cf, firstTargetType, secondTargetType, isReversed, action); if (cf.irisShape != action.irisShape) { cf.irisShape = action.irisShape; } cf.mode = action.cameraFadeType; cf.setupMaterials(); cf.r = action.cameraFadeParameters.ToArray(); // calculate and set value AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } float percentage = (float)(frame - action.startFrame) / (float)(action.endFrame - action.startFrame); float value = ease(1f, 0f, percentage, curve); cf.value = value; cf.percent = percentage; }