예제 #1
0
        public static void RefreshManager(bool Normalization = false)
        {
            mConfig = XConfig.GetConfig <VFSConfigModel>(VFSConst.ConfigFilePath_Resources);
            if (mConfig == null)
            {
                return;
            }
            if (Normalization)
            {
                VFSUtil.NormalizationConfig(mConfig);
            }

            if (!VFSUtil.CheckConfiguration(mConfig, out var errorCode, out var folderError))
            {
                string log_str = string.Empty;
                //配置文件校验未通过
                switch (errorCode)
                {
                case VFSErrorCode.ConfigureGroupsConflict:
                    //资源组规则未通过,log提示出来
                    log_str = VFSManagerEditorI18N.Log_ConfigureGroupsConflict;
                    if (folderError != null && folderError.Length > 0)
                    {
                        foreach (var f in folderError)
                        {
                            log_str += $"\nGroup [{f.GroupName}] , FolderPath: {f.FolderPath}";
                        }
                    }
                    Debug.LogError(log_str);
                    return;     //直接不继续往下执行了

                case VFSErrorCode.NoneGroup:
                    //没有配置任何资源组
                    //这个问题不报Error
                    return;

                case VFSErrorCode.SameGroupName:
                    log_str = VFSManagerEditorI18N.Log_SameGroupName;
                    Debug.LogError(log_str);
                    return;
                }
            }

            Groups.Clear();
            if (!mConfig.EnableVFS)
            {
                return;
            }

            //VFS Profile
            XDirectory.CreateIfNotExists(XEditorConst.EditorProjectSettingRootFolder);
            var profile_path = Path.Combine(XEditorConst.EditorProjectSettingRootFolder, VFSEditorConst.VFSProfileProjectSettingFileName);

            if (File.Exists(profile_path))
            {
                //load
                VFSProfileEditor = XConfig.GetJson <VFSProfileModel>(profile_path, AssetLoadType.SystemIO, false);
            }
            else
            {
                //create profile editor file in "ProjectSetting"
                initProfileRecord();
                //var json_text = JsonUtility.ToJson(VFSProfileEditor);
                XConfig.SaveJson(VFSProfileEditor, profile_path, AssetLoadType.SystemIO);
            }

            foreach (var group_opt in mConfig.Groups)
            {
                var _group_obj = new VFSEditorGroup(group_opt);
                Groups.Add(_group_obj);
                FolderPaths.AddRange(_group_obj.FolderPaths);
                foreach (var assetPath in _group_obj.AssetPaths)
                {
                    if (!AssetPaths.Contains(assetPath))
                    {
                        AssetPaths.Add(assetPath);
                    }
                }
            }

            LastRefreshManagerTime = System.DateTime.UtcNow;
        }
예제 #2
0
        /// <summary>
        /// 把构建好的AssetBundle文件根据组进行复制分类
        /// </summary>
        /// <param name="group"></param>
        /// <param name="build_ab_path"></param>
        /// <param name="target_root_path"></param>
        /// <returns></returns>
        private bool CopyAssetBundleFilesByGroup(VFSEditorGroup group, string build_ab_path, string target_root_path)
        {
            bool moved     = false;
            int  counter   = 0;
            int  counter_t = 0;
            int  total_len = mDict_Group_AssetBundleNames[group.GroupName].Count;

            if (EnableTipsGUI && total_len > 100)
            {
                EditorUtility.DisplayProgressBar("Classifying files", $"Classifying assetbundle files by group \"{group.GroupName}\"", 0.5f);
            }
            foreach (var assetbundle_name in mDict_Group_AssetBundleNames[group.GroupName])
            {
                if (EnableTipsGUI)
                {
                    counter++;
                    counter_t++;
                    if (total_len > 100)
                    {
                        if (counter_t > 50)
                        {
                            counter_t = 0;
                            EditorUtility.DisplayProgressBar("Classifying files", $"Classifying assetbundle files by group \"{group.GroupName}\"\n{counter} / {total_len}", counter / total_len);
                        }
                    }
                }
                string assetbundle_path = Path.Combine(build_ab_path, assetbundle_name);
                if (File.Exists(assetbundle_path))
                {
                    string target_path = Path.Combine(target_root_path, assetbundle_name);
                    XFile.DeleteIfExists(target_path);
                    XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path));

                    File.Copy(assetbundle_path, target_path);

                    if (mUsePipeline)
                    {
                        FileStream fileStream = new FileStream(target_path, FileMode.Open, FileAccess.ReadWrite);
                        void InvokePipline(BuilderPipelineContext ctx)
                        {
                            if (ctx.Handler != null)
                            {
                                bool b = ctx.Handler.BeforeAssetBundleFileSavedByGroup(ref group, assetbundle_name, ref fileStream);
                                if (b && ctx.Next != null)
                                {
                                    InvokePipline(ctx.Next);
                                }
                            }
                        }

                        if (mPipeline.First != null)
                        {
                            InvokePipline(mPipeline.First);
                        }
                        fileStream.Close();
                        fileStream.Dispose();
                    }
                    moved = true;
                }
            }
            if (EnableTipsGUI)
            {
                EditorUtility.ClearProgressBar();
            }
            return(moved);
        }