Beispiel #1
0
        public static AnimationClip OptimizeAnimation(AnimationClip _srcClip, int _floatPrecision, bool _clearScale)
        {
            AnimationClip _dstClip = _srcClip.Copy();

            _dstClip.ClearCurves();
            foreach (var binding in AnimationUtility.GetCurveBindings(_srcClip))
            {
                if (_clearScale && binding.propertyName.Contains("Scale"))
                {
                    continue;
                }
                AnimationCurve curve     = AnimationUtility.GetEditorCurve(_srcClip, binding);
                Keyframe[]     keyframes = curve.keys;
                for (int i = 0; i < keyframes.Length; i++)
                {
                    Keyframe keyframe = keyframes[i];
                    keyframe.value      = OptimizeFloat(keyframe.value, _floatPrecision);
                    keyframe.time       = OptimizeFloat(keyframe.time, _floatPrecision);
                    keyframe.inTangent  = OptimizeFloat(keyframe.inTangent, _floatPrecision);
                    keyframe.outTangent = OptimizeFloat(keyframe.outTangent, _floatPrecision);
                    keyframe.inWeight   = OptimizeFloat(keyframe.inWeight, _floatPrecision);
                    keyframe.outWeight  = OptimizeFloat(keyframe.outWeight, _floatPrecision);
                    keyframes[i]        = keyframe;
                }
                curve.keys = keyframes;
                _dstClip.SetCurve(binding.path, binding.type, binding.propertyName, curve);
            }
            return(_dstClip);
        }