Esempio n. 1
0
        public static void ScanAnimationClip()
        {
            bool isCancel = false;

            try {
                AnimationOpt _AnimOpt = _AnimOptList[_Index];
                isCancel = EditorUtility.DisplayCancelableProgressBar("优化AnimationClip", _AnimOpt.path, (float)_Index / (float)_AnimOptList.Count);
                _AnimOpt.OptimizeSize();
                _Index++;
            }
            catch (Exception e) {
                isCancel = true;
            }
            if (isCancel || _Index >= _AnimOptList.Count)
            {
                EditorUtility.ClearProgressBar();
                Debug.Log(string.Format("--优化完成--    错误数量: {0}    总数量: {1}/{2}    错误信息↓:\n{3}\n----------输出完毕----------", _Errors.Count, _Index, _AnimOptList.Count, string.Join(string.Empty, _Errors.ToArray())));
                Resources.UnloadUnusedAssets();
                GC.Collect();
                AssetDatabase.SaveAssets();
                EditorApplication.update = null;
                _AnimOptList.Clear();
                _cachedOpts.Clear();
                _Index = 0;
            }
        }
Esempio n. 2
0
 static List <AnimationOpt> FindAnims()
 {
     assets.Clear();
     foreach (var guid in Selection.assetGUIDs)
     {
         string path = AssetDatabase.GUIDToAssetPath(guid);
         if (Directory.Exists(path))
         {
             string[] files = Directory.GetFiles(path, "*.anim", SearchOption.AllDirectories);
             foreach (var file in files)
             {
                 AnimationOpt animopt = GetNewAOpt(file);
                 if (animopt != null)
                 {
                     assets.Add(animopt);
                 }
             }
         }
         else if (File.Exists(path))
         {
             AnimationOpt animopt = GetNewAOpt(path);
             if (animopt != null)
             {
                 assets.Add(animopt);
             }
         }
     }
     return(assets);
 }
Esempio n. 3
0
        public static void Optimize(OptimizeType optimizeType)
        {
            AnimOptList = FindAnims();
            for (int i = 0; i < AnimOptList.Count; ++i)
            {
                AnimationOpt anim = AnimOptList[i];
                if (EditorUtility.DisplayCancelableProgressBar("优化AnimationClip", anim.Path, (float)i / (float)AnimOptList.Count))
                {
                    break;
                }
                switch (optimizeType)
                {
                case OptimizeType.SACLE:
                    anim.OptmizeAnimationScaleCurve();
                    break;

                case OptimizeType.FLOAT:
                    anim.Optimize_Scale_Float3(false);
                    break;

                default:
                    anim.Optimize_Scale_Float3(true);
                    break;
                }
            }
            EditorUtility.ClearProgressBar();
            AssetDatabase.SaveAssets();
            AnimOptList.Clear();
            cachedOpts.Clear();
        }
Esempio n. 4
0
    private static bool ProcessAnima(string path)
    {
        if (Path.GetExtension(path).ToLower() == ".anim")
        {
            EditorTool.AnimationOpt animaOpt = EditorTool.OptimizeAnimationClipTool.GetNewAOpt(path);
            animaOpt.OptimizeSize();
            return(true);
        }

        return(false);
    }
Esempio n. 5
0
        public static AnimationOpt GetNewAOpt(string path)
        {
            AnimationOpt opt = null;

            if (!_cachedOpts.ContainsKey(path))
            {
                AnimationClip clip = AssetDatabase.LoadAssetAtPath <AnimationClip> (path);
                if (clip != null)
                {
                    opt = new AnimationOpt(path, clip);
                    //_cachedOpts [path] = opt;
                }
            }
            return(opt);
        }
Esempio n. 6
0
        static AnimationOpt GetNewAOpt(string path)
        {
            AnimationOpt opt = null;

            if (!cachedOpts.TryGetValue(path, out opt))
            {
                AnimationClip clip = AssetDatabase.LoadAssetAtPath <AnimationClip>(path);
                if (clip != null)
                {
                    opt = new AnimationOpt(path, clip);
                    cachedOpts[path] = opt;
                }
            }
            return(opt);
        }
Esempio n. 7
0
        public static List <AnimationOpt> FindAnims()
        {
            string[]            guids  = null;
            List <string>       path   = new List <string>();
            List <AnimationOpt> assets = new List <AnimationOpt> ();

            UnityEngine.Object[] objs = Selection.GetFiltered(typeof(object), SelectionMode.Assets);
            if (objs.Length > 0)
            {
                for (int i = 0; i < objs.Length; i++)
                {
                    if (objs [i].GetType() == typeof(AnimationClip))
                    {
                        string       p       = AssetDatabase.GetAssetPath(objs [i]);
                        AnimationOpt animopt = GetNewAOpt(p);
                        if (animopt != null)
                        {
                            assets.Add(animopt);
                        }
                    }
                    else
                    {
                        path.Add(AssetDatabase.GetAssetPath(objs [i]));
                    }
                }
                if (path.Count > 0)
                {
                    guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(AnimationClip).ToString().Replace("UnityEngine.", "")), path.ToArray());
                }
                else
                {
                    guids = new string[] {}
                };
            }
            for (int i = 0; i < guids.Length; i++)
            {
                string       assetPath = AssetDatabase.GUIDToAssetPath(guids [i]);
                AnimationOpt animopt   = GetNewAOpt(assetPath);
                if (animopt != null)
                {
                    assets.Add(animopt);
                }
            }
            return(assets);
        }
    }
        private static void ScanAnimationClip()
        {
            AnimationOpt animOpt  = animOptList[index];
            bool         isCancel = EditorUtility.DisplayCancelableProgressBar("优化AnimationClip", animOpt.aniPath, (float)index / (float)animOptList.Count);

            animOpt.Optimize_Scale_Float3();
            index++;
            if (isCancel || index >= animOptList.Count)
            {
                EditorUtility.ClearProgressBar();
                Debug.Log(string.Format("--优化完成--    错误数量: {0}    总数量: {1}/{2}    错误信息↓:\n{3}\n----------输出完毕----------", errors.Count, index, animOptList.Count, string.Join(string.Empty, errors.ToArray())));
                Resources.UnloadUnusedAssets();
                GC.Collect();
                AssetDatabase.SaveAssets();
                EditorApplication.update = null;
                animOptList.Clear();
                cachedOpts.Clear();
                index = 0;
            }
        }