Slate Forums › Support › Suggestion: Support Easings for GetClipWeight and GetTrackWeight › Reply To: Suggestion: Support Easings for GetClipWeight and GetTrackWeight
My changes are a bit sloppy, mostly because 1) I haven’t thoroughly tested this (and I’ve just used it on Animator Tracks so far), and 2) I didn’t properly account for how it probably doesn’t make sense to enable this for all possible tracks. So my changes just enable it across the board for all tracks, and I’ll just be careful about whether it acts weird in some cases.
So far this seems to work as I’d expect, even when adjusting a clip’s ClipWeight property in the inspector.
As far as the issue you mentioned, about non-linear cross blending, I wonder if that’s only an issue if two adjacent clips use a different easing function? In my case, I just set a single easing for the whole track, not for individual tracks. Or maybe my change is actually broken in some way I just haven’t noticed yet. 🙂
My changes were:
1) CameraTrack.cs: Moved public EaseType interpolation = EaseType.QuarticInOut;
to the base class, so that all tracks can specify their interpolation.
2) CutsceneTrack.cs: Added easing to GetTrackWeights:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
///---------------------------------------------------------------------------------------------- /// DGG: Wrapped all these in ApplyEasing public float GetTrackWeight() { return ApplyEasing(this.GetWeight(root.currentTime - this.startTime, this.blendIn, this.blendOut)); } public float GetTrackWeight(float time) { return ApplyEasing(this.GetWeight(time, this.blendIn, this.blendOut)); } public float GetTrackWeight(float time, float blendInOut) { return ApplyEasing(this.GetWeight(time, blendInOut, blendInOut)); } public float GetTrackWeight(float time, float blendIn, float blendOut) { return ApplyEasing(this.GetWeight(time, blendIn, blendOut)); } // DGG private float ApplyEasing(float v) { if (interpolation == EaseType.Linear) { return v; } else { return Easing.Ease(interpolation, 0, 1, v); } } |
3) ActionClip.cs: Applied easing to the final GetClipWeight, which asks the track for its interpolation mode, and uses that easing. Referencing the track in this way is a bit ugly, but I didn’t see a cleaner way to go from a Clip to a Track.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// DGG: Added easing public float GetClipWeight(float time, float blendIn, float blendOut) { return ApplyEasing(this.GetWeight(time, blendIn, blendOut)); } // DGG: Added easing private float ApplyEasing(float v) { var track = this.parent as CutsceneTrack; float retval = v; if (track != null && track.interpolation != EaseType.Linear) { retval = Easing.Ease(track.interpolation, 0, 1, v); } return retval; } |