lyh916

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

参考链接:

https://blog.csdn.net/u013917120/article/details/79824448

https://www.jianshu.com/p/fd9538413907/

https://www.cnblogs.com/msxh/p/14090805.html

 

资源优化规则:https://upr.unity.com/instructions/assetchecker#UserManual

Animation优化规则:

 

注意点:

1.fbx中的动画是只读的,因此需要将fbx中的动画提取出来,这样才能对动画进行编辑

2.通过减少动画曲线精度,可以提高存储效果,从而达到减少内存占用的目的

3.去掉缩放曲线,也可以减少内存占用

 

代码如下:

 1 using UnityEditor;
 2 using UnityEngine;
 3 using System.Collections.Generic;
 4 
 5 public class OptimizeEditor
 6 {
 7     private static string artDir = "Assets/Art";
 8 
 9     [MenuItem("Tools/优化/动画优化")]
10     private static void OptimizeAnimation()
11     {
12         List<AnimationClip> animationClipList = EditorHelper.GetAssetsByFolders<AnimationClip>("t:AnimationClip", new string[] { artDir });
13         for (int i = 0; i < animationClipList.Count; i++)
14         {
15             AnimationClip animationClip = animationClipList[i];
16             EditorCurveBinding[] editorCurveBindings = AnimationUtility.GetCurveBindings(animationClip);
17             for (int j = 0; j < editorCurveBindings.Length; j++)
18             {
19                 EditorCurveBinding editorCurveBinding = editorCurveBindings[i];
20 
21                 //删减帧
22                 if (editorCurveBinding.propertyName.ToLower().Contains("scale"))
23                 {
24                     AnimationUtility.SetEditorCurve(animationClip, editorCurveBinding, null);
25                 }
26 
27                 //精度压缩
28                 AnimationCurve animationCurve = AnimationUtility.GetEditorCurve(animationClip, editorCurveBinding);
29                 if (animationCurve != null)
30                 {
31                     Keyframe[] keyframes = animationCurve.keys;
32                     for (int k = 0; k < keyframes.Length; k++)
33                     {
34                         Keyframe keyframe = keyframes[k];
35                         keyframe.value = float.Parse(keyframe.value.ToString("f3"));
36                         keyframe.inTangent = float.Parse(keyframe.inTangent.ToString("f3"));
37                         keyframe.outTangent = float.Parse(keyframe.outTangent.ToString("f3"));
38                         keyframes[k] = keyframe;
39                     }
40                     animationCurve.keys = keyframes;
41 
42                     AnimationUtility.SetEditorCurve(animationClip, editorCurveBinding, animationCurve);
43                 }
44             }
45         }
46     }
47 }

 

posted on 2021-07-31 18:45  艰苦奋斗中  阅读(232)  评论(0编辑  收藏  举报