public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target) { GameObject go = target as GameObject; if (go == null) { return; } var tween = DOTween.To(TweenPlugValueSet <bool> .Get(), () => go.activeSelf, (x) => go.SetActive(x), setActive, getTime(seq.take.frameRate)); seq.Insert(this, tween); }
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 target = obj as Transform; int frameRate = seq.take.frameRate; var scaleTrack = (ScaleTrack)track; var axis = scaleTrack.axis; float timeLength = getTime(frameRate); if (interp == Interpolation.None) { if (axis == AxisFlags.X) { float _x = scale.x; var tweenX = DOTween.To(TweenPlugValueSet <float> .Get(), () => 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(TweenPlugValueSet <float> .Get(), () => 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(TweenPlugValueSet <float> .Get(), () => 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(TweenPlugValueSet <Vector3> .Get(), () => target.localScale, (s) => { target.localScale = s; }, scale, timeLength); seq.Insert(this, tweenV); } else { var tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => { 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 (interp == Interpolation.Linear || path == null) { Vector3 endScale = ((ScaleKey)track.keys[index + 1]).scale; Tweener tween; if (axis == AxisFlags.X) { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => scale.x, (x) => { var a = target.localScale; a.x = x; target.localScale = a; }, endScale.x, timeLength); } else if (axis == AxisFlags.Y) { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => scale.y, (y) => { var a = target.localScale; a.y = y; target.localScale = a; }, endScale.y, timeLength); } else if (axis == AxisFlags.Z) { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => scale.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(), () => scale, (s) => target.localScale = s, endScale, timeLength); } else { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => scale, (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); } else if (interp == Interpolation.Curve) { DOSetter <Vector3> setter; if (axis == AxisFlags.X) { setter = (s) => { var a = target.localScale; a.x = s.x; target.localScale = a; } } ; else if (axis == AxisFlags.Y) { setter = (s) => { var a = target.localScale; a.y = s.y; target.localScale = a; } } ; else if (axis == AxisFlags.Z) { setter = (s) => { var a = target.localScale; a.z = s.z; target.localScale = a; } } ; else if (axis == AxisFlags.All) { setter = (s) => target.localScale = s; } else { setter = (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; } }; var tweenPath = DOTween.To(TweenPlugPathVector3.Get(), () => scale, setter, path, timeLength); if (hasCustomEase()) { tweenPath.SetEase(easeCurve); } else { tweenPath.SetEase(easeType, amplitude, period); } seq.Insert(this, tweenPath); } } #endregion }
Tweener GenerateSingleValueTweener(SequenceControl seq, PropertyTrack propTrack, float time, Component comp) { switch (propTrack.valueType) { case PropertyTrack.ValueType.Integer: { int _val = System.Convert.ToInt32(val); var tween = DOTween.To(TweenPlugValueSet <int> .Get(), GenerateGetter <int>(propTrack, comp), GenerateSetter <int>(propTrack, comp), _val, time); return(tween); } case PropertyTrack.ValueType.Float: { float _val = System.Convert.ToSingle(val); var tween = DOTween.To(TweenPlugValueSet <float> .Get(), GenerateGetter <float>(propTrack, comp), GenerateSetter <float>(propTrack, comp), _val, time); return(tween); } case PropertyTrack.ValueType.Double: { var tween = DOTween.To(TweenPlugValueSet <double> .Get(), GenerateGetter <double>(propTrack, comp), GenerateSetter <double>(propTrack, comp), val, time); return(tween); } case PropertyTrack.ValueType.Long: { long _val = System.Convert.ToInt64(val); var tween = DOTween.To(TweenPlugValueSet <long> .Get(), GenerateGetter <long>(propTrack, comp), GenerateSetter <long>(propTrack, comp), _val, time); return(tween); } case PropertyTrack.ValueType.Vector2: { Vector2 _val = vect2; var tween = DOTween.To(TweenPlugValueSet <Vector2> .Get(), GenerateGetter <Vector2>(propTrack, comp), GenerateSetter <Vector2>(propTrack, comp), _val, time); return(tween); } case PropertyTrack.ValueType.Vector3: { Vector3 _val = vect3; var tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), GenerateGetter <Vector3>(propTrack, comp), GenerateSetter <Vector3>(propTrack, comp), _val, time); return(tween); } case PropertyTrack.ValueType.Color: { Color _val = color; var tween = DOTween.To(TweenPlugValueSet <Color> .Get(), GenerateGetter <Color>(propTrack, comp), GenerateSetter <Color>(propTrack, comp), _val, time); return(tween); } case PropertyTrack.ValueType.Rect: { Rect _val = rect; var tween = DOTween.To(TweenPlugValueSet <Rect> .Get(), GenerateGetter <Rect>(propTrack, comp), GenerateSetter <Rect>(propTrack, comp), _val, time); return(tween); } case PropertyTrack.ValueType.Vector4: { var tween = DOTween.To(TweenPlugValueSet <Vector4> .Get(), GenerateGetter <Vector4>(propTrack, comp), GenerateSetter <Vector4>(propTrack, comp), vect4, time); return(tween); } case PropertyTrack.ValueType.Quaternion: { Quaternion _val = quat; var tween = DOTween.To(TweenPlugValueSet <Quaternion> .Get(), GenerateGetter <Quaternion>(propTrack, comp), GenerateSetter <Quaternion>(propTrack, comp), _val, time); return(tween); } case PropertyTrack.ValueType.Bool: { bool _val = valb; var tween = DOTween.To(TweenPlugValueSet <bool> .Get(), GenerateGetter <bool>(propTrack, comp), GenerateSetter <bool>(propTrack, comp), _val, time); return(tween); } case PropertyTrack.ValueType.String: { var tween = DOTween.To(TweenPlugValueSet <string> .Get(), GenerateGetter <string>(propTrack, comp), GenerateSetter <string>(propTrack, comp), valString, time); return(tween); } case PropertyTrack.ValueType.Sprite: { var spriteRenderer = comp as SpriteRenderer; var _val = valObj as Sprite; var tween = DOTween.To(TweenPlugValueSet <Sprite> .Get(), () => spriteRenderer.sprite, (x) => spriteRenderer.sprite = x, _val, time); 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(TweenPlugValueSet <object> .Get(), GenerateGetter <object>(propTrack, comp), GenerateSetter <object>(propTrack, comp), enumVal, time); 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 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 target = obj as Transform; Rigidbody body = target.GetComponent <Rigidbody>(); Rigidbody2D body2D = !body?target.GetComponent <Rigidbody2D>() : null; int frameRate = seq.take.frameRate; var rotTrack = (RotationEulerTrack)track; var axis = rotTrack.axis; float timeLength = getTime(frameRate);//1.0f / frameRate; if (interp == Interpolation.None) { if (axis == AxisFlags.X) { float _x = rotation.x; TweenerCore <float, float, TWeenPlugNoneOptions> tweenX; if (body) { tweenX = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.x, (x) => { var a = target.localEulerAngles; var parent = target.parent; if (parent) { body.rotation = Quaternion.Euler(x, a.y, a.z) * parent.rotation; } else { body.rotation = Quaternion.Euler(x, a.y, a.z); } }, _x, timeLength); } else { tweenX = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.x, (x) => { var a = target.localEulerAngles; a.x = x; target.localEulerAngles = a; }, _x, timeLength); } seq.Insert(this, tweenX); } else if (axis == AxisFlags.Y) { float _y = rotation.y; TweenerCore <float, float, TWeenPlugNoneOptions> tweenY; if (body) { tweenY = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.y, (y) => { var a = target.localEulerAngles; var parent = target.parent; if (parent) { body.rotation = Quaternion.Euler(a.x, y, a.z) * parent.rotation; } else { body.rotation = Quaternion.Euler(a.x, y, a.z); } }, _y, timeLength); } else { tweenY = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.y, (y) => { var a = target.localEulerAngles; a.y = y; target.localEulerAngles = a; }, _y, timeLength); } seq.Insert(this, tweenY); } else if (axis == AxisFlags.Z) { float _z = rotation.z; TweenerCore <float, float, TWeenPlugNoneOptions> tweenZ; if (body2D) { tweenZ = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.z, (z) => { var parent = target.parent; if (parent) { body2D.rotation = z + parent.eulerAngles.z; } else { body2D.rotation = z; } }, _z, timeLength); } else if (body) { tweenZ = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.z, (z) => { var a = target.localEulerAngles; var parent = target.parent; if (parent) { body.rotation = Quaternion.Euler(a.x, a.y, z) * parent.rotation; } else { body.rotation = Quaternion.Euler(a.x, a.y, z); } }, _z, timeLength); } else { tweenZ = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.z, (z) => { var a = target.localEulerAngles; a.z = z; target.localEulerAngles = a; }, _z, timeLength); } seq.Insert(this, tweenZ); } else if (axis == AxisFlags.All) { TweenerCore <Vector3, Vector3, TWeenPlugNoneOptions> tweenV; if (body2D) { tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => target.localEulerAngles, (r) => { var parent = target.parent; if (parent) { body2D.rotation = r.z + parent.eulerAngles.z; } else { body2D.rotation = r.z; } }, rotation, timeLength); } else if (body) { tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => target.localEulerAngles, (r) => { var parent = target.parent; if (parent) { body.rotation = Quaternion.Euler(r) * parent.rotation; } else { body.rotation = Quaternion.Euler(r); } }, rotation, timeLength); } else { tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => target.localEulerAngles, (r) => { target.localEulerAngles = r; }, rotation, timeLength); } seq.Insert(this, tweenV); } else { TweenerCore <Vector3, Vector3, TWeenPlugNoneOptions> tweenV; DOGetter <Vector3> getter = () => { var ret = rotation; var rot = target.localEulerAngles; if ((axis & AxisFlags.X) != AxisFlags.None) { ret.x = rot.x; } if ((axis & AxisFlags.Y) != AxisFlags.None) { ret.y = rot.y; } if ((axis & AxisFlags.Z) != AxisFlags.None) { ret.z = rot.z; } return(ret); }; if (body2D) { tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), getter, (r) => { if ((axis & AxisFlags.Z) != AxisFlags.None) { var parent = target.parent; if (parent) { body2D.rotation = r.z + parent.eulerAngles.z; } else { body2D.rotation = r.z; } } }, rotation, timeLength); } else if (body) { tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), getter, (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; } var parent = target.parent; if (parent) { body.rotation = Quaternion.Euler(rot) * parent.rotation; } else { body.rotation = Quaternion.Euler(rot); } }, rotation, timeLength); } else { tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), getter, (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); } seq.Insert(this, tweenV); } } else if (interp == Interpolation.Linear || path == null) { Vector3 endRotation = (track.keys[index + 1] as RotationEulerKey).rotation; Tweener tween; if (axis == AxisFlags.X) { if (body) { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.x, (x) => { var a = target.localEulerAngles; var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(x, a.y, a.z) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(x, a.y, a.z)); } }, endRotation.x, timeLength); } else { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.x, (x) => { var a = target.localEulerAngles; a.x = x; target.localEulerAngles = a; }, endRotation.x, timeLength); } } else if (axis == AxisFlags.Y) { if (body) { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.y, (y) => { var a = target.localEulerAngles; var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(a.x, y, a.z) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(a.x, y, a.z)); } }, endRotation.y, timeLength); } else { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.y, (y) => { var a = target.localEulerAngles; a.y = y; target.localEulerAngles = a; }, endRotation.y, timeLength); } } else if (axis == AxisFlags.Z) { if (body2D) { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.z, (z) => { var parent = target.parent; if (parent) { body2D.MoveRotation(z + parent.eulerAngles.z); } else { body2D.MoveRotation(z); } }, endRotation.z, timeLength); } else if (body) { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.z, (z) => { var a = target.localEulerAngles; var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(a.x, a.y, z) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(a.x, a.y, z)); } }, endRotation.z, timeLength); } else { tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.z, (z) => { var a = target.localEulerAngles; a.z = z; target.localEulerAngles = a; }, endRotation.z, timeLength); } } else if (axis == AxisFlags.All) { if (body2D) { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => { var parent = target.parent; if (parent) { body2D.MoveRotation(r.z + parent.eulerAngles.z); } else { body2D.MoveRotation(r.z); } }, endRotation, timeLength); } else if (body) { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => { var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(r) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(r)); } }, endRotation, timeLength); } else { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => target.localEulerAngles = r, endRotation, timeLength); } } else { if (body2D) { if ((axis & AxisFlags.Z) != AxisFlags.None) { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => { var parent = target.parent; if (parent) { body2D.MoveRotation(r.z + parent.eulerAngles.z); } else { body2D.MoveRotation(r.z); } }, endRotation, timeLength); } else { tween = null; } } else if (body) { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => 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; } var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(rot) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(rot)); } }, endRotation, timeLength); } else { tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => 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; }, endRotation, timeLength); } } if (tween != null) { if (hasCustomEase()) { tween.SetEase(easeCurve); } else { tween.SetEase(easeType, amplitude, period); } seq.Insert(this, tween); } } else if (interp == Interpolation.Curve) { DOSetter <Vector3> setter; if (axis == AxisFlags.X) { if (body) { setter = (x) => { var a = target.localEulerAngles; var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(x.x, a.y, a.z) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(x.x, a.y, a.z)); } } } ; else { setter = (x) => { var a = target.localEulerAngles; a.x = x.x; target.localEulerAngles = a; } }; } else if (axis == AxisFlags.Y) { if (body) { setter = (x) => { var a = target.localEulerAngles; var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(a.x, x.y, a.z) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(a.x, x.y, a.z)); } } } ; else { setter = (x) => { var a = target.localEulerAngles; a.y = x.y; target.localEulerAngles = a; } }; } else if (axis == AxisFlags.Z) { if (body2D) { setter = (x) => { var parent = target.parent; if (parent) { body2D.MoveRotation(x.z + parent.eulerAngles.z); } else { body2D.MoveRotation(x.z); } } } ; else if (body) { setter = (x) => { var a = target.localEulerAngles; var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(a.x, a.y, x.z) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(a.x, a.y, x.z)); } } } ; else { setter = (x) => { var a = target.localEulerAngles; a.z = x.z; target.localEulerAngles = a; } }; } else if (axis == AxisFlags.All) { if (body2D) { setter = (r) => { var parent = target.parent; if (parent) { body2D.MoveRotation(r.z + parent.eulerAngles.z); } else { body2D.MoveRotation(r.z); } } } ; else if (body) { setter = (r) => { var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(r) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(r)); } } } ; else { setter = (r) => target.localEulerAngles = r; } } else { if (body2D) { if ((axis & AxisFlags.Z) != AxisFlags.None) { setter = (r) => { var parent = target.parent; if (parent) { body2D.MoveRotation(r.z + parent.eulerAngles.z); } else { body2D.MoveRotation(r.z); } } } ; else { return; } } else if (body) { setter = (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; } var parent = target.parent; if (parent) { body.MoveRotation(Quaternion.Euler(rot) * parent.rotation); } else { body.MoveRotation(Quaternion.Euler(rot)); } } } ; else { setter = (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; } }; } var tweenPath = DOTween.To(TweenPlugPathVector3.Get(), () => rotation, setter, path, timeLength); if (hasCustomEase()) { tweenPath.SetEase(easeCurve); } else { tweenPath.SetEase(easeType, amplitude, period); } seq.Insert(this, tweenPath); } } #endregion }
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); } }
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 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); } }