public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target) { int frameRate = seq.take.frameRate; float waitTime = getWaitTime(frameRate, 0.0f); var anim = (target as GameObject).GetComponent <Animation>(); float duration = wrapMode == WrapMode.Once ? amClip.length : ((seq.take.getLastFrame() - frame) + 1) / (float)frameRate; if (crossfade) { if (index > 0) { var prevKey = track.keys[index - 1] as UnityAnimationKey; var prevAnimState = anim[prevKey.amClip.name]; var prevWrap = prevKey.wrapMode; var prevStartTime = prevKey.getWaitTime(frameRate, 0.0f); var animState = anim[amClip.name]; var tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => 0f, (x) => { if (x < crossfadeTime) { float weight = x / crossfadeTime; prevAnimState.enabled = true; prevAnimState.wrapMode = prevWrap; prevAnimState.weight = 1.0f - weight; prevAnimState.time = (waitTime + x) - prevStartTime; animState.enabled = true; animState.wrapMode = wrapMode; animState.weight = weight; animState.time = x; anim.Sample(); prevAnimState.enabled = false; animState.enabled = false; } else { animState.enabled = true; animState.wrapMode = wrapMode; animState.weight = 1.0f; animState.time = x; anim.Sample(); animState.enabled = false; } }, duration, duration); seq.Insert(this, tween); } else { var animState = anim[amClip.name]; var tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => 0f, (x) => { animState.enabled = true; animState.wrapMode = wrapMode; animState.time = x; if (x < crossfadeTime) { animState.weight = x / crossfadeTime; } else { animState.weight = 1.0f; } anim.Sample(); animState.enabled = false; }, duration, duration); seq.Insert(this, tween); } } else { var animState = anim[amClip.name]; var tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => 0f, (x) => { animState.enabled = true; animState.wrapMode = wrapMode; animState.time = x; animState.weight = 1.0f; anim.Sample(); animState.enabled = false; }, duration, duration); seq.Insert(this, tween); } }
public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj) { Transform target = obj as Transform; int frameRate = seq.take.frameRate; //allow tracks with just one key if (track.keys.Count == 1) { interp = Interpolation.None; } var rotTrack = (RotationEulerTrack)track; var axis = rotTrack.axis; if (!canTween) { float timeLength = 1.0f / frameRate; if (axis == AxisFlags.X) { float _x = rotation.x; var tweenX = DOTween.To(new TweenPlugValueSet <float>(), () => _x, (x) => { var a = target.localEulerAngles; a.x = x; target.localEulerAngles = a; }, _x, timeLength); tweenX.plugOptions.SetSequence(seq); seq.Insert(this, tweenX); } else if (axis == AxisFlags.Y) { float _y = rotation.y; var tweenY = DOTween.To(new TweenPlugValueSet <float>(), () => _y, (y) => { var a = target.localEulerAngles; a.y = y; target.localEulerAngles = a; }, _y, timeLength); tweenY.plugOptions.SetSequence(seq); seq.Insert(this, tweenY); } else if (axis == AxisFlags.Z) { float _z = rotation.z; var tweenZ = DOTween.To(new TweenPlugValueSet <float>(), () => _z, (z) => { var a = target.localEulerAngles; a.z = z; target.localEulerAngles = a; }, _z, timeLength); tweenZ.plugOptions.SetSequence(seq); seq.Insert(this, tweenZ); } else if (axis == AxisFlags.All) { var tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), () => rotation, (r) => { target.localEulerAngles = r; }, rotation, timeLength); tweenV.plugOptions.SetSequence(seq); seq.Insert(this, tweenV); } else { var tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), () => rotation, (r) => { var rot = target.localEulerAngles; if ((axis & AxisFlags.X) != AxisFlags.None) { rot.x = r.x; } if ((axis & AxisFlags.Y) != AxisFlags.None) { rot.y = r.y; } if ((axis & AxisFlags.Z) != AxisFlags.None) { rot.z = r.z; } target.localEulerAngles = rot; }, rotation, timeLength); tweenV.plugOptions.SetSequence(seq); seq.Insert(this, tweenV); } } else if (endFrame == -1) { return; } else { float timeLength = getTime(frameRate); Vector3 endRotation = (track.keys[index + 1] as RotationEulerKey).rotation; Tweener tween; if (axis == AxisFlags.X) { tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.x, (x) => { var a = target.localEulerAngles; a.x = x; target.localEulerAngles = a; }, endRotation.x, timeLength); } else if (axis == AxisFlags.Y) { tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.y, (y) => { var a = target.localEulerAngles; a.y = y; target.localEulerAngles = a; }, endRotation.y, timeLength); } else if (axis == AxisFlags.Z) { tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.z, (z) => { var a = target.localEulerAngles; a.z = z; target.localEulerAngles = a; }, endRotation.z, timeLength); } else if (axis == AxisFlags.All) { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localEulerAngles, (r) => target.localEulerAngles = r, endRotation, timeLength); } else { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localEulerAngles, (r) => { var rot = target.localEulerAngles; if ((axis & AxisFlags.X) != AxisFlags.None) { rot.x = r.x; } if ((axis & AxisFlags.Y) != AxisFlags.None) { rot.y = r.y; } if ((axis & AxisFlags.Z) != AxisFlags.None) { rot.z = r.z; } target.localEulerAngles = rot; }, endRotation, timeLength); } if (hasCustomEase()) { tween.SetEase(easeCurve); } else { tween.SetEase(easeType, amplitude, period); } seq.Insert(this, tween); } }
public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj) { int frameRate = seq.take.frameRate; //allow tracks with just one key if (track.keys.Count == 1) { interp = Interpolation.None; } Transform trans = obj as Transform; var tTrack = track as TranslationTrack; bool pixelSnap = tTrack.pixelSnap; float ppu = tTrack.pixelPerUnit; if (!canTween) { //TODO: world position Vector3 pos = pixelSnap ? new Vector3(Mathf.Round(position.x * ppu) / ppu, Mathf.Round(position.y * ppu) / ppu, Mathf.Round(position.z * ppu) / ppu) : position; var tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => pos, (x) => trans.localPosition = x, pos, 1.0f / frameRate); //getTime(frameRate) tweener.plugOptions.SetSequence(seq); seq.Insert(this, tweener); } else { if (path.Length <= 1) { return; } if (getNumberOfFrames(seq.take.frameRate) <= 0) { return; } Tweener ret = null; bool isRelative = false; PathType pathType = path.Length == 2 ? PathType.Linear : PathType.CatmullRom; if (pixelSnap) { ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu), new Path(pathType, path, pathResolution), getTime(frameRate)).SetTarget(trans).SetRelative(isRelative).SetOptions(isClosed); } else { ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = x, new Path(pathType, path, pathResolution), getTime(frameRate)).SetTarget(trans).SetRelative(isRelative).SetOptions(isClosed); } if (hasCustomEase()) { ret.SetEase(easeCurve); } else { ret.SetEase(easeType, amplitude, period); } seq.Insert(this, ret); } }
public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj) { Transform target = obj as Transform; int frameRate = seq.take.frameRate; //allow tracks with just one key if (track.keys.Count == 1) { interp = Interpolation.None; } var scaleTrack = (ScaleTrack)track; var axis = scaleTrack.axis; if (!canTween) { float timeLength = getTime(frameRate); if (axis == AxisFlags.X) { float _x = scale.x; var tweenX = DOTween.To(new TweenPlugValueSet <float>(), () => target.localScale.x, (x) => { var a = target.localScale; a.x = x; target.localScale = a; }, _x, timeLength); seq.Insert(this, tweenX); } else if (axis == AxisFlags.Y) { float _y = scale.y; var tweenY = DOTween.To(new TweenPlugValueSet <float>(), () => target.localScale.y, (y) => { var a = target.localScale; a.y = y; target.localScale = a; }, _y, timeLength); seq.Insert(this, tweenY); } else if (axis == AxisFlags.Z) { float _z = scale.z; var tweenZ = DOTween.To(new TweenPlugValueSet <float>(), () => target.localScale.z, (z) => { var a = target.localScale; a.z = z; target.localScale = a; }, _z, timeLength); seq.Insert(this, tweenZ); } else if (axis == AxisFlags.All) { var tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), () => target.localScale, (s) => { target.localScale = s; }, scale, timeLength); seq.Insert(this, tweenV); } else { var tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), () => { var ls = scale; var curls = target.localScale; if ((axis & AxisFlags.X) != AxisFlags.None) { ls.x = curls.x; } if ((axis & AxisFlags.Y) != AxisFlags.None) { ls.y = curls.y; } if ((axis & AxisFlags.Z) != AxisFlags.None) { ls.z = curls.z; } return(ls); }, (s) => { var ls = target.localScale; if ((axis & AxisFlags.X) != AxisFlags.None) { ls.x = s.x; } if ((axis & AxisFlags.Y) != AxisFlags.None) { ls.y = s.y; } if ((axis & AxisFlags.Z) != AxisFlags.None) { ls.z = s.z; } target.localScale = ls; }, scale, timeLength); seq.Insert(this, tweenV); } } else if (endFrame == -1) { return; } else { float timeLength = getTime(frameRate); Vector3 endScale = ((ScaleKey)track.keys[index + 1]).scale; Tweener tween; if (axis == AxisFlags.X) { tween = DOTween.To(new FloatPlugin(), () => target.localScale.x, (x) => { var a = target.localScale; a.x = x; target.localScale = a; }, endScale.x, timeLength); } else if (axis == AxisFlags.Y) { tween = DOTween.To(new FloatPlugin(), () => target.localScale.y, (y) => { var a = target.localScale; a.y = y; target.localScale = a; }, endScale.y, timeLength); } else if (axis == AxisFlags.Z) { tween = DOTween.To(new FloatPlugin(), () => target.localScale.z, (z) => { var a = target.localScale; a.z = z; target.localScale = a; }, endScale.z, timeLength); } else if (axis == AxisFlags.All) { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localScale, (s) => target.localScale = s, endScale, timeLength); } else { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localScale, (s) => { var ls = target.localScale; if ((axis & AxisFlags.X) != AxisFlags.None) { ls.x = s.x; } if ((axis & AxisFlags.Y) != AxisFlags.None) { ls.y = s.y; } if ((axis & AxisFlags.Z) != AxisFlags.None) { ls.z = s.z; } target.localScale = ls; }, endScale, timeLength); } if (hasCustomEase()) { tween.SetEase(easeCurve); } else { tween.SetEase(easeType, amplitude, period); } seq.Insert(this, tween); } }
public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target) { //allow tracks with just one key if (track.keys.Count == 1) { interp = Interpolation.None; } else if (canTween) { //invalid or in-between keys if (endFrame == -1) { return; } } var matTrack = track as MaterialTrack; var propType = matTrack.propertyType; Material matInst = matTrack.materialInstance; string prop = matTrack.property; int propId = Shader.PropertyToID(prop); int frameRate = seq.take.frameRate; Tweener tween = null; int keyCount = track.keys.Count; float time = getTime(frameRate); if (interp == Interpolation.None) { switch (propType) { case MaterialTrack.ValueType.Float: case MaterialTrack.ValueType.Range: tween = DOTween.To(TweenPlugValueSet <float> .Get(), () => matInst.GetFloat(propId), (x) => matInst.SetFloat(propId, x), val, time); break; case MaterialTrack.ValueType.Vector: tween = DOTween.To(TweenPlugValueSet <Vector4> .Get(), () => matInst.GetVector(propId), (x) => matInst.SetVector(propId, x), vector, time); break; case MaterialTrack.ValueType.Color: tween = DOTween.To(TweenPlugValueSet <Color> .Get(), () => matInst.GetColor(propId), (x) => matInst.SetColor(propId, x), color, time); break; case MaterialTrack.ValueType.TexOfs: tween = DOTween.To(TweenPlugValueSet <Vector2> .Get(), () => matInst.GetTextureOffset(prop), (x) => matInst.SetTextureOffset(prop, x), texOfs, time); break; case MaterialTrack.ValueType.TexScale: tween = DOTween.To(TweenPlugValueSet <Vector2> .Get(), () => matInst.GetTextureScale(prop), (x) => matInst.SetTextureScale(prop, x), texScale, time); break; case MaterialTrack.ValueType.TexEnv: tween = DOTween.To(TweenPlugValueSet <Texture> .Get(), () => matInst.GetTexture(propId), (x) => matInst.SetTexture(propId, x), texture, time); break; } } else if (interp == Interpolation.Linear || path == null) { var endKey = track.keys[index + 1] as MaterialKey; switch (propType) { case MaterialTrack.ValueType.Float: case MaterialTrack.ValueType.Range: tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => val, (x) => matInst.SetFloat(propId, x), endKey.val, time); break; case MaterialTrack.ValueType.Vector: tween = DOTween.To(TweenPluginFactory.CreateVector4(), () => vector, (x) => matInst.SetVector(propId, x), endKey.vector, time); break; case MaterialTrack.ValueType.Color: tween = DOTween.To(TweenPluginFactory.CreateColor(), () => color, (x) => matInst.SetColor(propId, x), endKey.color, time); break; case MaterialTrack.ValueType.TexOfs: tween = DOTween.To(TweenPluginFactory.CreateVector2(), () => texOfs, (x) => matInst.SetTextureOffset(prop, x), endKey.texOfs, time); break; case MaterialTrack.ValueType.TexScale: tween = DOTween.To(TweenPluginFactory.CreateVector2(), () => texScale, (x) => matInst.SetTextureScale(prop, x), endKey.texScale, time); break; } } else { switch (propType) { case MaterialTrack.ValueType.Float: case MaterialTrack.ValueType.Range: tween = DOTween.To(TweenPlugPathFloat.Get(), () => val, (x) => matInst.SetFloat(propId, x), path, time); break; case MaterialTrack.ValueType.Vector: tween = DOTween.To(TweenPlugPathVector4.Get(), () => vector, (x) => matInst.SetVector(propId, x), path, time); break; case MaterialTrack.ValueType.Color: tween = DOTween.To(TweenPlugPathColor.Get(), () => color, (x) => matInst.SetColor(propId, x), path, time); break; case MaterialTrack.ValueType.TexOfs: tween = DOTween.To(TweenPlugPathVector2.Get(), () => texOfs, (x) => matInst.SetTextureOffset(propId, x), path, time); break; case MaterialTrack.ValueType.TexScale: tween = DOTween.To(TweenPlugPathVector2.Get(), () => texScale, (x) => matInst.SetTextureScale(propId, x), path, time); break; } } if (tween != null) { if (canTween) { if (hasCustomEase()) { tween.SetEase(easeCurve); } else { tween.SetEase((Ease)easeType, amplitude, period); } } seq.Insert(this, tween); } }
Tweener GenerateTweener(SequenceControl seq, PropertyTrack propTrack, float frameRate, Component comp) { float numFrames = endFrame == -1 ? 1f : (float)(endFrame - frame); float time = numFrames / frameRate; switch ((PropertyTrack.ValueType)propTrack.valueType) { case PropertyTrack.ValueType.Integer: { int _val = System.Convert.ToInt32(val); var tween = DOTween.To(new TweenPlugValueSet <int>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Float: { float _val = System.Convert.ToSingle(val); var tween = DOTween.To(new TweenPlugValueSet <float>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Double: { var tween = DOTween.To(new TweenPlugValueSet <double>(), () => val, GenerateSetter(propTrack, comp, val), val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Long: { long _val = System.Convert.ToInt64(val); var tween = DOTween.To(new TweenPlugValueSet <long>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Vector2: { Vector2 _val = vect2; var tween = DOTween.To(new TweenPlugValueSet <Vector2>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Vector3: { Vector3 _val = vect3; var tween = DOTween.To(new TweenPlugValueSet <Vector3>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Color: { Color _val = color; var tween = DOTween.To(new TweenPlugValueSet <Color>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Rect: { Rect _val = rect; var tween = DOTween.To(new TweenPlugValueSet <Rect>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Vector4: { var tween = DOTween.To(new TweenPlugValueSet <Vector4>(), () => vect4, GenerateSetter(propTrack, comp, vect4), vect4, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Quaternion: { Quaternion _val = quat; var tween = DOTween.To(new TweenPlugValueSet <Quaternion>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Bool: { bool _val = valb; var tween = DOTween.To(new TweenPlugValueSet <bool>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.String: { var tween = DOTween.To(new TweenPlugValueSet <string>(), () => valString, GenerateSetter(propTrack, comp, valString), valString, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Sprite: { var spriteRenderer = comp as SpriteRenderer; var _val = valObj as Sprite; var tween = DOTween.To(new TweenPlugValueSet <Sprite>(), () => _val, (x) => spriteRenderer.sprite = x, _val, time); tween.plugOptions.SetSequence(seq); return(tween); } case PropertyTrack.ValueType.Enum: { System.Type infType = propTrack.GetCachedInfoType(seq.target); object enumVal = infType != null?System.Enum.ToObject(infType, (int)val) : null; if (enumVal != null) { var tween = DOTween.To(new TweenPlugValueSet <object>(), () => enumVal, GenerateSetter(propTrack, comp, enumVal), enumVal, time); tween.plugOptions.SetSequence(seq); return(tween); } else { Debug.LogError("Invalid enum value."); break; } } } return(null); //no type match }
public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target) { PropertyTrack propTrack = track as PropertyTrack; if (endFrame == -1 && canTween && propTrack.canTween) { return; } PropertyTrack.ValueType valueType = propTrack.valueType; //get component and fill the cached method info Component comp = propTrack.GetTargetComp(target as GameObject); if (comp == null) { return; } string varName = propTrack.getMemberName(); int frameRate = seq.take.frameRate; //change to use setvalue track in AMSequence if (!string.IsNullOrEmpty(varName)) { propTrack.RefreshData(comp); //allow tracks with just one key if (!propTrack.canTween || !canTween || track.keys.Count == 1) { seq.Insert(this, GenerateTweener(seq, propTrack, frameRate, comp)); } else { //grab end frame var endKey = track.keys[index + 1] as PropertyKey; if (targetsAreEqual(valueType, endKey)) { return; } Tweener tween = null; PropertyInfo propInfo = propTrack.GetCachedPropertyInfo(); if (propInfo != null) { switch (valueType) { case PropertyTrack.ValueType.Integer: tween = DOTween.To(new IntPlugin(), () => System.Convert.ToInt32(propInfo.GetValue(comp, null)), (x) => propInfo.SetValue(comp, x, null), System.Convert.ToInt32(endKey.val), getTime(frameRate)); break; case PropertyTrack.ValueType.Float: tween = DOTween.To(new FloatPlugin(), () => System.Convert.ToSingle(propInfo.GetValue(comp, null)), (x) => propInfo.SetValue(comp, x, null), System.Convert.ToSingle(endKey.val), getTime(frameRate)); break; case PropertyTrack.ValueType.Double: tween = DOTween.To(new DoublePlugin(), () => System.Convert.ToDouble(propInfo.GetValue(comp, null)), (x) => propInfo.SetValue(comp, x, null), endKey.val, getTime(frameRate)); break; case PropertyTrack.ValueType.Long: tween = DOTween.To(new LongPlugin(), () => System.Convert.ToInt64(propInfo.GetValue(comp, null)), (x) => propInfo.SetValue(comp, x, null), System.Convert.ToInt64(endKey.val), getTime(frameRate)); break; case PropertyTrack.ValueType.Vector2: tween = DOTween.To(TweenPluginFactory.CreateVector2(), () => (Vector2)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.vect2, getTime(frameRate)); break; case PropertyTrack.ValueType.Vector3: tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => (Vector3)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.vect3, getTime(frameRate)); break; case PropertyTrack.ValueType.Color: tween = DOTween.To(TweenPluginFactory.CreateColor(), () => (Color)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.color, getTime(frameRate)); break; case PropertyTrack.ValueType.Rect: tween = DOTween.To(new RectPlugin(), () => (Rect)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.rect, getTime(frameRate)); break; case PropertyTrack.ValueType.Vector4: tween = DOTween.To(TweenPluginFactory.CreateVector4(), () => (Vector4)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.vect4, getTime(frameRate)); break; case PropertyTrack.ValueType.Quaternion: tween = DOTween.To(new PureQuaternionPlugin(), () => (Quaternion)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.quat, getTime(frameRate)); break; } } else { FieldInfo fieldInfo = propTrack.GetCachedFieldInfo(); if (fieldInfo != null) { switch (valueType) { case PropertyTrack.ValueType.Integer: tween = DOTween.To(new IntPlugin(), () => System.Convert.ToInt32(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), System.Convert.ToInt32(endKey.val), getTime(frameRate)); break; case PropertyTrack.ValueType.Float: tween = DOTween.To(new FloatPlugin(), () => System.Convert.ToSingle(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), System.Convert.ToSingle(endKey.val), getTime(frameRate)); break; case PropertyTrack.ValueType.Double: tween = DOTween.To(new DoublePlugin(), () => System.Convert.ToDouble(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), endKey.val, getTime(frameRate)); break; case PropertyTrack.ValueType.Long: tween = DOTween.To(new LongPlugin(), () => System.Convert.ToInt64(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), System.Convert.ToInt64(endKey.val), getTime(frameRate)); break; case PropertyTrack.ValueType.Vector2: tween = DOTween.To(TweenPluginFactory.CreateVector2(), () => (Vector2)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.vect2, getTime(frameRate)); break; case PropertyTrack.ValueType.Vector3: tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => (Vector3)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.vect3, getTime(frameRate)); break; case PropertyTrack.ValueType.Color: tween = DOTween.To(TweenPluginFactory.CreateColor(), () => (Color)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.color, getTime(frameRate)); break; case PropertyTrack.ValueType.Rect: tween = DOTween.To(new RectPlugin(), () => (Rect)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.rect, getTime(frameRate)); break; case PropertyTrack.ValueType.Vector4: tween = DOTween.To(TweenPluginFactory.CreateVector4(), () => (Vector4)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.vect4, getTime(frameRate)); break; case PropertyTrack.ValueType.Quaternion: tween = DOTween.To(new PureQuaternionPlugin(), () => (Quaternion)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.quat, getTime(frameRate)); break; } } } if (tween != null) { if (hasCustomEase()) { tween.SetEase(easeCurve); } else { tween.SetEase((Ease)easeType, amplitude, period); } seq.Insert(this, tween); } } } else { Debug.LogError("Animator: No FieldInfo or PropertyInfo set."); } return; }
public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj) { int frameRate = seq.take.frameRate; //allow tracks with just one key if (track.keys.Count == 1) { interp = Interpolation.None; } var trans = obj as Transform; var transParent = trans.parent; Rigidbody body = trans.GetComponent <Rigidbody>(); Rigidbody2D body2D = !body?trans.GetComponent <Rigidbody2D>() : null; var tTrack = track as TranslationTrack; bool pixelSnap = tTrack.pixelSnap; float ppu = tTrack.pixelPerUnit; if (!canTween) { //TODO: world position Vector3 pos = pixelSnap ? new Vector3(Mathf.Round(position.x * ppu) / ppu, Mathf.Round(position.y * ppu) / ppu, Mathf.Round(position.z * ppu) / ppu) : position; TweenerCore <Vector3, Vector3, TWeenPlugNoneOptions> tweener; if (body2D) { tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => body2D.position = transParent.TransformPoint(x), pos, getTime(frameRate)); //1.0f / frameRate } else if (body) { tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => body.position = transParent.TransformPoint(x), pos, getTime(frameRate)); //1.0f / frameRate } else { tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => trans.localPosition = x, pos, getTime(frameRate)); //1.0f / frameRate } seq.Insert(this, tweener); } else { if (path.Length <= 1) { return; } if (getNumberOfFrames(seq.take.frameRate) <= 0) { return; } TweenerCore <Vector3, Path, PathOptions> ret = null; bool isRelative = false; PathType pathType = path.Length == 2 ? PathType.Linear : PathType.CatmullRom; var pathTween = new Path(pathType, path, pathResolution); var timeTween = getTime(frameRate); if (body2D) { if (pixelSnap) { ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body2D.MovePosition(transParent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu))), pathTween, timeTween).SetTarget(body2D); } else { ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body2D.MovePosition(transParent.TransformPoint(x)), pathTween, timeTween).SetTarget(body2D); } } else if (body) { if (pixelSnap) { ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body.MovePosition(transParent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu))), pathTween, timeTween).SetTarget(body); } else { ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body.MovePosition(transParent.TransformPoint(x)), pathTween, timeTween).SetTarget(body); } } else { if (pixelSnap) { ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu), pathTween, timeTween).SetTarget(trans); } else { ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = x, pathTween, timeTween).SetTarget(trans); } } ret.SetRelative(isRelative).SetOptions(isClosed); if (hasCustomEase()) { ret.SetEase(easeCurve); } else { ret.SetEase(easeType, amplitude, period); } seq.Insert(this, ret); } }
public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target) { if (methodName == null) { return; } float duration = 1.0f / seq.take.frameRate; var tgt = target; //set target to component if (cachedComponent) { tgt = cachedComponent; } else if (!string.IsNullOrEmpty(componentType) && tgt is GameObject) { tgt = cachedComponent = ((GameObject)tgt).GetComponent(componentType); } if (!tgt) { if (!string.IsNullOrEmpty(componentType)) { if (target) { Debug.LogWarning(string.Format("Track {0} Key {1}: Component ({2}) missing in {3}.", track.name, index, componentType, target.name)); } else { Debug.LogWarning(string.Format("Track {0} Key {1}: Component ({2}) is missing.", track.name, index, componentType)); } } else { Debug.LogWarning(string.Format("Track {0} Key {1}: Target is missing.", track.name, index)); } return; } //can't send message if it's not a component Component compSendMsg = null; if (useSendMessage) { compSendMsg = tgt as Component; } if (compSendMsg) { if (parameters == null || parameters.Count <= 0) { seq.InsertCallback(this, () => compSendMsg.SendMessage(methodName, null, SendMessageOptions.DontRequireReceiver)); } else { seq.InsertCallback(this, () => compSendMsg.SendMessage(methodName, parameters[0].toObject(seq.target), SendMessageOptions.DontRequireReceiver)); } } else { var method = cachedMethodInfo != null ? cachedMethodInfo : tgt.GetType().GetMethod(methodName, GetParamTypes()); object[] parms = buildParams(seq.target); seq.InsertCallback(this, () => method.Invoke(tgt, parms)); } }
public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj) { //allow tracks with just one key if (track.keys.Count == 1) { interp = Interpolation.None; } else if (canTween) { //invalid or in-between keys if (endFrame == -1) { return; } } var trans = obj as Transform; Rigidbody body = trans.GetComponent <Rigidbody>(); Rigidbody2D body2D = !body?trans.GetComponent <Rigidbody2D>() : null; var tTrack = track as TranslationTrack; bool pixelSnap = tTrack.pixelSnap; float ppu = tTrack.pixelPerUnit; int frameRate = seq.take.frameRate; float time = getTime(frameRate); Tweener tween = null; if (interp == Interpolation.None) { //TODO: world position Vector3 pos = pixelSnap ? new Vector3(Mathf.Round(position.x * ppu) / ppu, Mathf.Round(position.y * ppu) / ppu, Mathf.Round(position.z * ppu) / ppu) : position; if (body2D) { tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => trans.localPosition, (x) => { var parent = trans.parent; if (parent) { body2D.position = parent.TransformPoint(x); } else { body2D.position = x; } }, pos, time); //1.0f / frameRate } else if (body) { tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => trans.localPosition, (x) => { var parent = trans.parent; if (parent) { body.position = parent.TransformPoint(x); } else { body.position = x; } }, pos, time); //1.0f / frameRate } else { tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => trans.localPosition, (x) => trans.localPosition = x, pos, time); //1.0f / frameRate } } else if (interp == Interpolation.Linear || path == null) { Vector3 endPos = (track.keys[index + 1] as TranslationKey).position; DOSetter <Vector3> setter; if (body2D) { if (pixelSnap) { setter = x => { var parent = trans.parent; if (parent) { body2D.MovePosition(parent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu))); } else { body2D.MovePosition(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu)); } } } ; else { setter = x => { var parent = trans.parent; if (parent) { body2D.MovePosition(parent.TransformPoint(x)); } else { body2D.MovePosition(x); } } }; } else if (body) { if (pixelSnap) { setter = x => { var parent = trans.parent; if (parent) { body.MovePosition(parent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu))); } else { body.MovePosition(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu)); } } } ; else { setter = x => { var parent = trans.parent; if (parent) { body.MovePosition(parent.TransformPoint(x)); } else { body.MovePosition(x); } } }; } else { if (pixelSnap) { setter = x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu); } else { setter = x => trans.localPosition = x; } } if (orientMode == OrientMode.None) { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => position, setter, endPos, time); } else { TweenerCore <Vector3, Vector3, TweenPlugVector3LookAtOptions> tweenOrient; if (body) { tweenOrient = DOTween.To(TweenPlugVector3LookAtRigidbody.Get(), () => position, setter, endPos, time); tweenOrient.target = body; } else if (body2D) { tweenOrient = DOTween.To(TweenPlugVector3LookAtRigidbody2D.Get(), () => position, setter, endPos, time); tweenOrient.target = body2D; } else { tweenOrient = DOTween.To(TweenPlugVector3LookAtTransform.Get(), () => position, setter, endPos, time); tweenOrient.target = trans; } tweenOrient.plugOptions = new TweenPlugVector3LookAtOptions() { orientMode = orientMode, lockAxis = orientLockAxis, lookAtPt = endPos, lookAtIsLocal = true }; tween = tweenOrient; } } else if (interp == Interpolation.Curve) { DOSetter <Vector3> setter; if (body2D) { if (pixelSnap) { setter = x => { var parent = trans.parent; if (parent) { body2D.MovePosition(parent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu))); } else { body2D.MovePosition(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu)); } } } ; else { setter = x => { var parent = trans.parent; if (parent) { body2D.MovePosition(parent.TransformPoint(x)); } else { body2D.MovePosition(x); } } }; } else if (body) { if (pixelSnap) { setter = x => { var parent = trans.parent; if (parent) { body.MovePosition(parent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu))); } else { body.MovePosition(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu)); } } } ; else { setter = x => { var parent = trans.parent; if (parent) { body.MovePosition(parent.TransformPoint(x)); } else { body.MovePosition(x); } } }; } else { if (pixelSnap) { setter = x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu); } else { setter = x => trans.localPosition = x; } } if (orientMode == OrientMode.None) { tween = DOTween.To(TweenPlugPathVector3.Get(), () => position, setter, path, time); } else { TweenerCore <Vector3, TweenPlugPath, TweenPlugPathOrientOptions> tweenOrient; if (body) { tweenOrient = DOTween.To(TweenPlugPathOrientRigidbody.Get(), () => position, setter, path, time); tweenOrient.target = body; } else if (body2D) { tweenOrient = DOTween.To(TweenPlugPathOrientRigidbody2D.Get(), () => position, setter, path, time); tweenOrient.target = body2D; } else { tweenOrient = DOTween.To(TweenPlugPathOrientTransform.Get(), () => position, setter, path, time); tweenOrient.target = trans; } tweenOrient.plugOptions = new TweenPlugPathOrientOptions { orientMode = orientMode, lockAxis = orientLockAxis }; tween = tweenOrient; } } if (tween != null) { if (canTween) { if (hasCustomEase()) { tween.SetEase(easeCurve); } else { tween.SetEase(easeType, amplitude, period); } } seq.Insert(this, tween); } }
public override void buildSequenceStart(SequenceControl sequence) { //cache material instance Init(sequence.target); }
public virtual void buildSequenceStart(SequenceControl sequence) { }
/// <summary> /// Use sequence to insert callbacks, or some other crap, just don't insert the tweener you are returning! /// target is set if required. index = this key's index in the track /// </summary> public virtual void build(SequenceControl seq, Track track, int index, UnityEngine.Object target) { Debug.LogError("Animator: No override for build."); }
public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj) { //allow tracks with just one key if (track.keys.Count == 1) { interp = Interpolation.None; } else if (canTween) { //invalid or in-between keys if (endFrame == -1) { return; } } Transform trans = obj as Transform; Rigidbody body = trans.GetComponent <Rigidbody>(); Rigidbody2D body2D = !body?trans.GetComponent <Rigidbody2D>() : null; int frameRate = seq.take.frameRate; float time = getTime(frameRate); if (interp == Interpolation.None) { TweenerCore <Quaternion, Quaternion, TWeenPlugNoneOptions> valueTween; if (body2D) { valueTween = DOTween.To(TweenPlugValueSet <Quaternion> .Get(), () => trans.localRotation, (x) => { var parent = trans.parent; if (parent) { body2D.rotation = (x * parent.rotation).eulerAngles.z; } else { body2D.rotation = x.eulerAngles.z; } }, rotation, time); } else if (body) { valueTween = DOTween.To(TweenPlugValueSet <Quaternion> .Get(), () => trans.localRotation, (x) => { var parent = trans.parent; if (parent) { body.rotation = x * parent.rotation; } else { body.rotation = x; } }, rotation, time); } else { valueTween = DOTween.To(TweenPlugValueSet <Quaternion> .Get(), () => trans.localRotation, (x) => trans.localRotation = x, rotation, time); } seq.Insert(this, valueTween); } else if (interp == Interpolation.Linear || path == null) { Quaternion endRotation = (track.keys[index + 1] as RotationKey).rotation; TweenerCore <Quaternion, Quaternion, NoOptions> linearTween; if (body2D) { linearTween = DOTween.To(TweenPluginFactory.CreateQuaternion(), () => rotation, (x) => { var parent = trans.parent; if (parent) { body2D.MoveRotation((x * parent.rotation).eulerAngles.z); } else { body2D.MoveRotation(x.eulerAngles.z); } }, endRotation, time); } else if (body) { linearTween = DOTween.To(TweenPluginFactory.CreateQuaternion(), () => rotation, (x) => { var parent = trans.parent; if (parent) { body.MoveRotation(x * parent.rotation); } else { body.MoveRotation(x); } }, endRotation, time); } else { linearTween = DOTween.To(TweenPluginFactory.CreateQuaternion(), () => rotation, (x) => trans.localRotation = x, endRotation, time); } if (hasCustomEase()) { linearTween.SetEase(easeCurve); } else { linearTween.SetEase(easeType, amplitude, period); } seq.Insert(this, linearTween); } else if (interp == Interpolation.Curve) { DOSetter <Quaternion> setter; if (body2D) { setter = x => { var parent = trans.parent; if (parent) { body2D.MoveRotation((x * parent.rotation).eulerAngles.z); } else { body2D.MoveRotation(x.eulerAngles.z); } } } ; else if (body) { setter = x => { var parent = trans.parent; if (parent) { body.MoveRotation(x * parent.rotation); } else { body.MoveRotation(x); } } } ; else { setter = x => trans.localRotation = x; } var pathTween = DOTween.To(TweenPlugPathEuler.Get(), () => rotation, setter, path, time); if (hasCustomEase()) { pathTween.SetEase(easeCurve); } else { pathTween.SetEase(easeType, amplitude, period); } seq.Insert(this, pathTween); } }