Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="path"></param>
 /// <param name="result"></param>
 /// <param name="simple">如果true,在检查到“不能被VFS管理”的任何一个条件后就停止查询</param>
 /// <returns>如果是“可以被VFS管理”的资源,返回true</returns>
 public static bool QueryAsset(string path, out AssetsStatusQueryResult result, bool simple = false)
 {
     return(VFSManagerEditor.QueryAsset(path, mConfig, out result, simple));
 }
Esempio n. 2
0
        public void RefreshAssetBundleSign()
        {
            /*
             * Unity目前提供的API对应的打包方法是:
             * 1. 给全局的文件加上assetbundle标记
             * 2. 整体打包
             */

            //获取到所有组的文件白名单目录
            refreshProfileInfos();
            if (EnableTipsGUI)
            {
                EditorUtility.DisplayProgressBar("VFS Builder", "Handle AssetBundle signs ...", 0f);
            }

            var    _whiteLists_folder = VFSManagerEditor.GetAllFolderPaths();
            string ab_extension       = Config.AssetBundleFileExtension; //没有点开头的后缀名

            if (ab_extension.StartsWith("."))
            {
                ab_extension = ab_extension.Substring(1, ab_extension.Length - 1);
            }
            ab_extension = ab_extension.ToLower();
            List <string> _whiteLists_folder_list_temp = new List <string>();

            foreach (var path in _whiteLists_folder)
            {
                if (!IsAssetFolderExists(path))
                {
                    Debug.LogError("[TinaX][VFS]Folder path in vfs config is not exists: \"" + path + "\"");
                }
                else
                {
                    if (path.EndsWith("/"))
                    {
                        _whiteLists_folder_list_temp.Add(path.Substring(0, path.Length - 1));
                    }
                    else
                    {
                        _whiteLists_folder_list_temp.Add(path);
                    }
                }
            }
            var _whitelist_folder_temp = _whiteLists_folder_list_temp.ToArray();

            string[] guids = AssetDatabase.FindAssets("", _whitelist_folder_temp);

            string[]      asset_paths = VFSManagerEditor.GetAllWithelistAssetsPaths();
            List <string> asset_guids = new List <string>();

            foreach (var item in asset_paths)
            {
                var myguid = AssetDatabase.AssetPathToGUID(item);
                if (!myguid.IsNullOrEmpty())
                {
                    asset_guids.Add(myguid);
                }
            }
            if (asset_guids.Count > 0)
            {
                ArrayUtil.Combine(ref guids, asset_guids.ToArray());
            }
            ArrayUtil.RemoveDuplicationElements(ref guids);
            asset_paths = null;
            asset_guids = null;

            asset_hash_book.Clear();
            dict_asset_hash_book.Clear();
            int counter     = 0;
            int counter_t   = 0;
            int totalLength = guids.Length;

            foreach (var guid in guids)
            {
                string cur_asset_path = AssetDatabase.GUIDToAssetPath(guid);
                if (VFSManagerEditor.QueryAsset(cur_asset_path, Config, out AssetsStatusQueryResult result, true))
                {
                    //查询到了信息,但是并不是所有情况都需要设置assetbundle记录,
                    bool sign_flag = true;
                    if (result.DevType == FolderBuildDevelopType.editor_only)
                    {
                        sign_flag = false; //该资源仅在编辑器下被加载,不参与打包。
                    }
                    if (result.DevType == FolderBuildDevelopType.develop_mode_only)
                    {
                        if (!mDevelopMode)
                        {
                            sign_flag = false; //资源应该仅在develop模式下使用,但是当前Profile的设置并不是develop
                        }
                    }

                    if (result.ExtensionGroup)
                    {
                        if (curProfile.IsDisabledGroup(result.GroupName))
                        {
                            sign_flag = false;
                        }
                    }

                    if (sign_flag)
                    {
                        var importer = AssetImporter.GetAtPath(cur_asset_path);
                        if (!XPath.IsFolder(cur_asset_path) && !result.AssetBundleFileNameWithoutExtension.IsNullOrEmpty())
                        {
                            string assetBundleName_without_extension = result.AssetBundleFileNameWithoutExtension;
                            void InvokePipeline(BuilderPipelineContext ctx)
                            {
                                if (ctx != null && ctx.Handler != null)
                                {
                                    bool b = ctx.Handler.BeforeSetAssetBundleSign(ref assetBundleName_without_extension, ref result);
                                    if (b && ctx.Next != null)
                                    {
                                        InvokePipeline(ctx.Next);
                                    }
                                }
                            }

                            if (mUsePipeline)
                            {
                                InvokePipeline(mPipeline.First);
                            }

                            //正式设置AssetBundle
                            importer.SetAssetBundleNameAndVariant(assetBundleName_without_extension, ab_extension);

                            //记录Asset原始hash(用于补丁版本检索)
                            if (result.ExtensionGroup)
                            {
                                //记录到字典里
                                if (!dict_asset_hash_book.ContainsKey(result.GroupName))
                                {
                                    dict_asset_hash_book.Add(result.GroupName, new List <FilesHashBook.FileHash>());
                                }
                                dict_asset_hash_book[result.GroupName].Add(new FilesHashBook.FileHash()
                                {
                                    p = cur_asset_path, h = XFile.GetMD5(cur_asset_path, true)
                                });
                            }
                            else
                            {
                                asset_hash_book.Add(new FilesHashBook.FileHash()
                                {
                                    p = cur_asset_path, h = XFile.GetMD5(cur_asset_path, true)
                                });
                            }
                            //记录AssetBundle名
                            string final_ab_name = assetBundleName_without_extension + "." + ab_extension;
                            if (!mDict_Group_AssetBundleNames.ContainsKey(result.GroupName))
                            {
                                mDict_Group_AssetBundleNames.Add(result.GroupName, new List <string>());
                            }
                            if (!mDict_Group_AssetBundleNames[result.GroupName].Contains(final_ab_name))
                            {
                                mDict_Group_AssetBundleNames[result.GroupName].Add(final_ab_name);
                            }
                        }
                    }
                }

                if (EnableTipsGUI)
                {
                    counter++;
                    if (totalLength < 100)
                    {
                        EditorUtility.DisplayProgressBar("VFS Builder", $"Handle AssetBundle signs : {counter} / {totalLength}", counter / totalLength);
                    }
                    else
                    {
                        counter_t++;
                        if (counter_t > 50)
                        {
                            counter_t = 0;
                            EditorUtility.DisplayProgressBar($"VFS Builder", "Handle AssetBundle signs : {counter} / {totalLength}", counter / totalLength);
                        }
                    }
                }
            }


            AssetDatabase.SaveAssets();
            if (EnableTipsGUI)
            {
                EditorUtility.ClearProgressBar();
            }
        }