public AnimationTracker(AniMeshData.AniClip Clip, AniMeshData Data) { _Clip = Clip; _Data = Data; _ClipMin = ((float)(_Clip.StartFrame + 1) / (float)_Data.FrameCount); _ClipMax = ((float)_Clip.StartFrame + (float)_Clip.Length) / (float)_Data.FrameCount; }
public void UpdateTracker(Renderer[] Renderers, MaterialPropertyBlock[] Blocks, AniMeshData Data, int Index, float AnimatorSpeed) { // update frame _CurrentFrame = Mathf.Clamp(_CurrentFrame + ((_Clip.FrameRate * Time.deltaTime) * _Clip.Speed) * AnimatorSpeed, 0, _Clip.Length); if (_CurrentFrame >= _Clip.Length && _Clip.Loop) { _CurrentFrame = 0; } // update strength Strength = Lerp(_From, _TargetStrength, FadePercentage()); // lerp to target strength // on done fading callback if (OnDoneFade != null && FadePercentage() >= 1f) { OnDoneFade.Invoke(); OnDoneFade = null; } if (Strength <= 0 && !_Clip.Loop) { ResetFrames(); } // update renderers for (int i = 0; i < Blocks.Length; i++) { if (Renderers [i].isVisible) { MaterialPropertyBlock props = Blocks [i]; Vector4 AnimationData = new Vector4( Lerp(ClipMin, ClipMax, (float)_CurrentFrame / (float)_Clip.Length), Strength, _Clip.MagnitudeMultiply, 0f ); props.SetVector(_PropertyKeys [Index], AnimationData); Renderers [i].SetPropertyBlock(props); } } }