zoukankan      html  css  js  c++  java
  • [Unity优化]UPR资源优化:Animation

    参考链接:

    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 }
  • 相关阅读:
    自建 IPA 分发平台
    一个优雅的占位图解决方案。适用于 UITableView 和 UICollectionView。
    Vuejs2.0购物车和地址选配学习笔记
    UIWebView 加 MJRefresh 同时解决底部黑影问题
    UIWebView 不自动全屏播放视频
    左右分页按钮的集合视图控件。用于快速编写出集合视图上分页多按钮点击事件!
    课程总结
    IO流实训
    事件处理
    变色
  • 原文地址:https://www.cnblogs.com/lyh916/p/15084937.html
Copyright © 2011-2022 走看看