Example #1
0
 public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
 {
     if (group != null && collector != null)
     {
         IsDirty = true;
     }
 }
Example #2
0
        // 资源收集器编辑相关
        public static void CreateCollector(AssetBundleCollectorGroup group, string collectPath)
        {
            AssetBundleCollector collector = new AssetBundleCollector();

            collector.CollectPath = collectPath;
            group.Collectors.Add(collector);
            IsDirty = true;
        }
Example #3
0
 public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
 {
     if (group.Collectors.Remove(collector))
     {
         IsDirty = true;
     }
     else
     {
         Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
     }
 }
        private void RemoveCollectorBtn_clicked(AssetBundleCollector selectCollector)
        {
            var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;

            if (selectGroup == null)
            {
                return;
            }
            if (selectCollector == null)
            {
                return;
            }

            Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow RemoveCollector");
            AssetBundleCollectorSettingData.RemoveCollector(selectGroup, selectCollector);
            FillCollectorViewData();
        }
        /// <summary>
        /// 导入XML配置表
        /// </summary>
        public static void ImportXmlConfig(string filePath)
        {
            if (File.Exists(filePath) == false)
            {
                throw new FileNotFoundException(filePath);
            }

            if (Path.GetExtension(filePath) != ".xml")
            {
                throw new Exception($"Only support xml : {filePath}");
            }

            // 加载配置文件
            XmlDocument xml = new XmlDocument();

            xml.Load(filePath);
            XmlElement root = xml.DocumentElement;

            // 读取配置版本
            string configVersion = root.GetAttribute(XmlVersion);

            if (configVersion != ConfigVersion)
            {
                throw new Exception($"The config version is invalid : {configVersion}");
            }

            // 读取公共配置
            bool   enableAddressable  = false;
            bool   autoCollectShaders = false;
            string shaderBundleName   = string.Empty;
            var    commonNodeList     = root.GetElementsByTagName(XmlCommon);

            if (commonNodeList.Count > 0)
            {
                XmlElement commonElement = commonNodeList[0] as XmlElement;
                if (commonElement.HasAttribute(XmlEnableAddressable) == false)
                {
                    throw new Exception($"Not found attribute {XmlEnableAddressable} in {XmlCommon}");
                }
                if (commonElement.HasAttribute(XmlAutoCollectShader) == false)
                {
                    throw new Exception($"Not found attribute {XmlAutoCollectShader} in {XmlCommon}");
                }
                if (commonElement.HasAttribute(XmlShaderBundleName) == false)
                {
                    throw new Exception($"Not found attribute {XmlShaderBundleName} in {XmlCommon}");
                }

                enableAddressable  = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
                autoCollectShaders = commonElement.GetAttribute(XmlAutoCollectShader) == "True" ? true : false;
                shaderBundleName   = commonElement.GetAttribute(XmlShaderBundleName);
            }

            // 读取分组配置
            List <AssetBundleCollectorGroup> groupTemper = new List <AssetBundleCollectorGroup>();
            var groupNodeList = root.GetElementsByTagName(XmlGroup);

            foreach (var groupNode in groupNodeList)
            {
                XmlElement groupElement = groupNode as XmlElement;
                if (groupElement.HasAttribute(XmlGroupName) == false)
                {
                    throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}");
                }
                if (groupElement.HasAttribute(XmlGroupDesc) == false)
                {
                    throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}");
                }
                if (groupElement.HasAttribute(XmlAssetTags) == false)
                {
                    throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}");
                }

                AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
                group.GroupName = groupElement.GetAttribute(XmlGroupName);
                group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc);
                group.AssetTags = groupElement.GetAttribute(XmlAssetTags);
                groupTemper.Add(group);

                // 读取收集器配置
                var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
                foreach (var collectorNode in collectorNodeList)
                {
                    XmlElement collectorElement = collectorNode as XmlElement;
                    if (collectorElement.HasAttribute(XmlCollectPath) == false)
                    {
                        throw new Exception($"Not found attribute {XmlCollectPath} in {XmlCollector}");
                    }
                    if (collectorElement.HasAttribute(XmlCollectorType) == false)
                    {
                        throw new Exception($"Not found attribute {XmlCollectorType} in {XmlCollector}");
                    }
                    if (collectorElement.HasAttribute(XmlAddressRule) == false)
                    {
                        throw new Exception($"Not found attribute {XmlAddressRule} in {XmlCollector}");
                    }
                    if (collectorElement.HasAttribute(XmlPackRule) == false)
                    {
                        throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}");
                    }
                    if (collectorElement.HasAttribute(XmlFilterRule) == false)
                    {
                        throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}");
                    }
                    if (collectorElement.HasAttribute(XmlAssetTags) == false)
                    {
                        throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}");
                    }

                    AssetBundleCollector collector = new AssetBundleCollector();
                    collector.CollectPath     = collectorElement.GetAttribute(XmlCollectPath);
                    collector.CollectorType   = StringUtility.NameToEnum <ECollectorType>(collectorElement.GetAttribute(XmlCollectorType));
                    collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
                    collector.PackRuleName    = collectorElement.GetAttribute(XmlPackRule);
                    collector.FilterRuleName  = collectorElement.GetAttribute(XmlFilterRule);
                    collector.AssetTags       = collectorElement.GetAttribute(XmlAssetTags);;
                    group.Collectors.Add(collector);
                }
            }

            // 保存配置数据
            AssetBundleCollectorSettingData.ClearAll();
            AssetBundleCollectorSettingData.Setting.EnableAddressable  = enableAddressable;
            AssetBundleCollectorSettingData.Setting.AutoCollectShaders = autoCollectShaders;
            AssetBundleCollectorSettingData.Setting.ShadersBundleName  = shaderBundleName;
            AssetBundleCollectorSettingData.Setting.Groups.AddRange(groupTemper);
            AssetBundleCollectorSettingData.SaveFile();
            Debug.Log($"导入配置完毕!");
        }
        private void RefreshFoldout(Foldout foldout, AssetBundleCollectorGroup group, AssetBundleCollector collector)
        {
            // 清空旧元素
            foldout.Clear();

            if (collector.IsValid() == false)
            {
                Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in group : {group.GroupName}");
                return;
            }

            if (collector.CollectorType == ECollectorType.MainAssetCollector || collector.CollectorType == ECollectorType.StaticAssetCollector)
            {
                List <CollectAssetInfo> collectAssetInfos = null;

                try
                {
                    collectAssetInfos = collector.GetAllCollectAssets(group);
                }
                catch (System.Exception e)
                {
                    Debug.LogError(e.ToString());
                }

                if (collectAssetInfos != null)
                {
                    foreach (var collectAssetInfo in collectAssetInfos)
                    {
                        VisualElement elementRow = new VisualElement();
                        elementRow.style.flexDirection = FlexDirection.Row;
                        foldout.Add(elementRow);

                        string showInfo = collectAssetInfo.AssetPath;
                        if (_enableAddressableToogle.value)
                        {
                            IAddressRule    instance     = AssetBundleCollectorSettingData.GetAddressRuleInstance(collector.AddressRuleName);
                            AddressRuleData ruleData     = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, group.GroupName);
                            string          addressValue = instance.GetAssetAddress(ruleData);
                            showInfo = $"[{addressValue}] {showInfo}";
                        }

                        var label = new Label();
                        label.text             = showInfo;
                        label.style.width      = 300;
                        label.style.marginLeft = 0;
                        label.style.flexGrow   = 1;
                        elementRow.Add(label);
                    }
                }
            }
        }