Exemplo n.º 1
0
        /// <summary>
        /// 清理无用的材质球属性
        /// </summary>
        private void ClearMaterialUnusedProperty()
        {
            // 获取所有的打包路径
            List <string> collectDirectorys = AssetBundleCollectorSettingData.GetAllCollectDirectory();

            if (collectDirectorys.Count == 0)
            {
                throw new Exception("[BuildPackage] 打包路径列表不能为空");
            }

            // 获取所有资源列表
            int checkCount   = 0;
            int removedCount = 0;

            string[] guids = AssetDatabase.FindAssets(string.Empty, collectDirectorys.ToArray());
            foreach (string guid in guids)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(guid);
                string ext       = System.IO.Path.GetExtension(assetPath);
                if (ext == $".{EAssetFileExtension.mat}")
                {
                    Material mat     = AssetDatabase.LoadAssetAtPath <Material>(assetPath);
                    bool     removed = EditorTools.ClearMaterialUnusedProperty(mat);
                    if (removed)
                    {
                        removedCount++;
                        Debug.LogWarning($"[Build] 材质球已被处理:{assetPath}");
                    }
                }

                // 进度条相关
                checkCount++;
                EditorUtility.DisplayProgressBar("进度", $"清理无用的材质球属性:{checkCount}/{guids.Length}", (float)checkCount / guids.Length);
            }

            EditorUtility.ClearProgressBar();
            if (removedCount == 0)
            {
                Debug.Log($"没有发现冗余的材质球属性");
            }
            else
            {
                AssetDatabase.SaveAssets();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 清理无用的材质球属性
        /// </summary>
        public static void ClearMaterialUnusedProperty()
        {
            // 获取所有的打包路径
            List <string> collectDirectorys = AssetBundleCollectorSettingData.GetAllCollectDirectory();

            if (collectDirectorys.Count == 0)
            {
                throw new Exception("打包路径列表不能为空");
            }

            // 获取所有资源列表
            int checkCount   = 0;
            int removedCount = 0;

            string[] findAssets = EditorTools.FindAssets(EAssetSearchType.Material, collectDirectorys.ToArray());
            foreach (string assetPath in findAssets)
            {
                Material mat     = AssetDatabase.LoadAssetAtPath <Material>(assetPath);
                bool     removed = EditorTools.ClearMaterialUnusedProperty(mat);
                if (removed)
                {
                    removedCount++;
                    Debug.LogWarning($"材质球已被处理:{assetPath}");
                }
                EditorTools.DisplayProgressBar("清理无用的材质球属性", ++checkCount, findAssets.Length);
            }
            EditorTools.ClearProgressBar();

            if (removedCount == 0)
            {
                Debug.Log($"没有发现冗余的材质球属性");
            }
            else
            {
                AssetDatabase.SaveAssets();
            }
        }