Example #1
0
 public IVFSBuilder UseProfile(string profileName)
 {
     mProfileName = profileName;
     curProfile   = VFSManagerEditor.GetProfileRecord(profileName);
     mDevelopMode = XCoreEditor.IsXProfileDevelopMode(mProfileName);
     return(this);
 }
Example #2
0
 private void refreshProfileInfos()
 {
     if (curProfile == null)
     {
         curProfile = VFSManagerEditor.GetProfileRecord(XCoreEditor.GetCurrentActiveXProfileName());
     }
 }
Example #3
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));
 }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="root_path">存放一系列VFS目录的根目录</param>
        /// <param name="build_root_path">Unity的Build结果输出目录</param>
        public void HandleVFSFiles(string root_path, string build_root_path, XRuntimePlatform platform)
        {
            mEditorBuildInfo = new EditorBuildInfo();
            List <VFSEditorGroup> groups  = VFSManagerEditor.GetGroups();
            string remote_files_root_path = Path.Combine(root_path, VFSEditorConst.PROJECT_VFS_FILE_FOLDER_REMOTE);
            string local_files_root_path  = Path.Combine(root_path, VFSEditorConst.PROJECT_VFS_FILES_FOLDER_MAIN);
            string source_packages_extension_root_folder = Path.Combine(root_path, VFSEditorConst.PROJECT_VFS_FILES_FOLDER_EXTENSION);

            XDirectory.DeleteIfExists(remote_files_root_path, true);
            XDirectory.DeleteIfExists(local_files_root_path, true);
            XDirectory.DeleteIfExists(source_packages_extension_root_folder, true);

            foreach (var group in groups)
            {
                //扩展组的判断
                if (group.ExtensionGroup)
                {
                    #region 处理扩展组
                    string extension_group_root_path = Path.Combine(source_packages_extension_root_folder, group.GroupName.ToLower());
                    bool   moved = CopyAssetBundleFilesByGroup(group, build_root_path, extension_group_root_path);
                    if (moved)
                    {
                        //manifest
                        group.MakeVFSManifest(root_path, mDict_Group_AssetBundleNames[group.GroupName], ref mAssetBundleManifest);
                        //给独立的组生成一份hash
                        group.MakeAssetBundleFilesHash(root_path, extension_group_root_path, mDict_Group_AssetBundleNames[group.GroupName]);
                        SaveExtensionGroupInfo(extension_group_root_path, group.GroupName, platform, group.ExtensionGroup_MainPackageVersionLimit, Config.AssetBundleFileExtension);
                        //保存Options
                        group.SaveGroupOptionFile(root_path);
                    }

                    #endregion

                    //登记
                    if (curProfile.IsDisabledGroup(group.GroupName))
                    {
                        mEditorBuildInfo.list_disable_extension.Add(group.GroupName);
                    }
                    else
                    {
                        mEditorBuildInfo.list_total_extension.Add(group.GroupName);

                        if (group.HandleMode == GroupHandleMode.LocalOrRemote)
                        {
                            if (curProfile.TryGetGroupLocation(group.GroupName, out var location))
                            {
                                if (location == ProfileRecord.E_GroupAssetsLocation.Local)
                                {
                                    mEditorBuildInfo.list_extension_local.Add(group.GroupName);
                                }
                                else if (location == ProfileRecord.E_GroupAssetsLocation.Remote)
                                {
                                    mEditorBuildInfo.list_extension_remote.Add(group.GroupName);
                                }
                            }
                            else
                            {
                                mEditorBuildInfo.list_extension_local.Add(group.GroupName);
                            }
                        }
                        else if (group.HandleMode == GroupHandleMode.RemoteOnly)
                        {
                            mEditorBuildInfo.list_extension_remote.Add(group.GroupName);
                        }
                        else
                        {
                            mEditorBuildInfo.list_extension_local.Add(group.GroupName);
                        }
                    }
                }
                else
                {
                    bool moveToRemote = false;
                    bool moveToLocal  = false;

                    if (group.HandleMode == GroupHandleMode.LocalOrRemote)
                    {
                        if (curProfile.TryGetGroupLocation(group.GroupName, out var location))
                        {
                            if (location == ProfileRecord.E_GroupAssetsLocation.Remote)
                            {
                                moveToRemote = true;
                            }
                            else
                            {
                                moveToLocal = true;
                            }
                        }
                        else
                        {
                            moveToLocal = true;
                        }
                    }
                    else if (group.HandleMode == GroupHandleMode.RemoteOnly)
                    {
                        moveToRemote = true;
                    }
                    else if (group.HandleMode == GroupHandleMode.LocalOnly || group.HandleMode == GroupHandleMode.LocalAndUpdatable)
                    {
                        moveToLocal = true;
                    }

                    //登记
                    mEditorBuildInfo.list_total_main_package.Add(group.GroupName);

                    if (moveToRemote)
                    {
                        //登记
                        mEditorBuildInfo.list_main_package_remote.Add(group.GroupName);
                        XDirectory.CreateIfNotExists(remote_files_root_path);
                        CopyAssetBundleFilesByGroup(group, build_root_path, remote_files_root_path);
                        //上一步copy的时候,开发者自定义的pipeline可以改变文件,所以制作assetbundle的hash信息的时候,必须使用上一步处理后的结果
                        group.MakeAssetBundleFilesHash(root_path, remote_files_root_path, mDict_Group_AssetBundleNames[group.GroupName]);
                    }
                    else if (moveToLocal)
                    {
                        //登记
                        mEditorBuildInfo.list_main_package_local.Add(group.GroupName);
                        XDirectory.CreateIfNotExists(local_files_root_path);
                        CopyAssetBundleFilesByGroup(group, build_root_path, local_files_root_path);
                        //上一步copy的时候,开发者自定义的pipeline可以改变文件,所以制作assetbundle的hash信息的时候,必须使用上一步处理后的结果
                        group.MakeAssetBundleFilesHash(root_path, local_files_root_path, mDict_Group_AssetBundleNames[group.GroupName]);
                    }


                    group.MakeVFSManifest(root_path, mDict_Group_AssetBundleNames[group.GroupName], ref mAssetBundleManifest);
                }
            }
        }
Example #5
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();
            }
        }