コード例 #1
0
        private void ApplyImporter(StreamWriter logWriter)
        {
            int totalCount = 0, skipCount = 0, successCount = 0; //统计变量

            logWriter.WriteLine("Start Setting Importers");
            foreach (var importerGroup in Module.UserConfig.Json.ImporterGroups)
            {
                Module.DisplayProgressBar("Setting " + importerGroup.Name, 0, true);
                logWriter.WriteLine("\nSetting " + importerGroup.Name);
                var assetInfos    = GetAssetInfoList(importerGroup.SearchFilter);
                int assetInfosLen = assetInfos.Length;
                foreach (var labelGroup in importerGroup.LabelGroups)
                {
                    if (!labelGroup.Active || labelGroup.LabelExpression.Trim() == "")
                    {
                        continue;
                    }

                    string expression = labelGroup.LabelExpression;
                    expression = regexSpace.Replace(expression, "");                                                        //消除所有\t\n\r\v\f
                    string[] labels = expression.Split(TruthExpressionParser.opset, StringSplitOptions.RemoveEmptyEntries); //获得labels
                    expression = regexOperator.Replace(expression, "o") + "#";                                              //获得表达式
                    int    labelsLen = labels.Length;
                    bool[] values    = new bool[labelsLen];                                                                 //存放每个资产的label包含结果
                    for (int i = 0; i < assetInfosLen; i++)
                    {
                        var assetInfo = assetInfos[i];
                        //没有label的资产跳过
                        if (assetInfo.Labels == null)
                        {
                            continue;
                        }
                        //标记该Asset是否包含当前表达式中的label
                        for (int j = 0; j < labelsLen; j++)
                        {
                            values[j] = assetInfo.Labels.Contains(labels[j]);
                        }
                        //计算真值表达式
                        bool truth = TruthExpressionParser.Parse(expression, values);
                        //值为false则跳过
                        if (truth == false)
                        {
                            continue;
                        }
                        //至此该Asset可以被设置
                        if (Module.DisplayCancelableProgressBar("Setting " + importerGroup.Name, assetInfo.Path, i / assetInfosLen, false, true))
                        {
                            throw new EBPException("运行被中止");
                        }
                        totalCount++;
                        if (labelGroup.SetPropertyGroups(assetInfo.Path))
                        {
                            logWriter.WriteLine("Set  " + assetInfo.Path);
                            successCount++;
                        }
                        else
                        {
                            logWriter.WriteLine("Skip " + assetInfo.Path);
                            skipCount++;
                        }
                    }
                }
            }
            logWriter.WriteLine("\n\nTotal: " + totalCount);
            logWriter.WriteLine("\nSkip: " + skipCount);
            logWriter.WriteLine("\nSuccess: " + successCount);
            totalCountList[currentStepIndex]   = totalCount;
            skipCountList[currentStepIndex]    = skipCount;
            successCountList[currentStepIndex] = successCount;
        }
コード例 #2
0
        protected override void CheckProcess(bool onlyCheckConfig = false)
        {
            if (Module.UserConfig.Json.Tags.Length == 0)
            {
                throw new EBPCheckFailedException("错误:Tag不能为为空!");
            }
            var    target    = BuildTarget.NoTarget;
            string targetStr = Module.UserConfig.Json.Tags[0];

            try
            {
                target = (BuildTarget)Enum.Parse(typeof(BuildTarget), targetStr, true);
            }
            catch
            {
                throw new EBPCheckFailedException("没有此平台:" + targetStr);
            }

            if (!onlyCheckConfig)
            {
                if (EditorUserBuildSettings.activeBuildTarget != target)
                {
                    throw new EBPCheckFailedException(string.Format("当前平台({0})与设置的平台({1})不一致,请改变设置或切换平台。", EditorUserBuildSettings.activeBuildTarget, target));
                }
                if (!Directory.Exists(Module.ModuleConfig.PreStoredAssetsFolderPath))
                {
                    throw new EBPCheckFailedException("不能应用配置,找不到PreStoredAssets目录:" + Module.ModuleConfig.PreStoredAssetsFolderPath);
                }
            }
            //检查所有label表达式
            foreach (var importerGroup in Module.UserConfig.Json.ImporterGroups)
            {
                foreach (var labelGroup in importerGroup.LabelGroups)
                {
                    string expression = labelGroup.LabelExpression;
                    if (string.IsNullOrEmpty(expression))
                    {
                        throw new EBPCheckFailedException("条件表达式不能为空!");
                    }
                    expression = regexSpace.Replace(expression, "");                                                        //消除所有\t\n\r\v\f
                    string[] labels = expression.Split(TruthExpressionParser.opset, StringSplitOptions.RemoveEmptyEntries); //获得labels
                    expression = regexOperator.Replace(expression, "o") + "#";                                              //获得表达式
                    int    labelsLen = labels.Length;
                    bool[] values    = new bool[labelsLen];                                                                 //存放每个资产的label包含结果
                    try
                    {
                        TruthExpressionParser.Parse(expression, values);
                    }
                    catch (Exception e)
                    {
                        throw new EBPCheckFailedException("条件表达式不正确:(" + e.Message + ")\n\n" + labelGroup.LabelExpression);
                    }
                    if (TruthExpressionParser.StackEmpty() == false)
                    {
                        throw new EBPCheckFailedException("条件表达式不正确(栈没有清空):\n\n" + labelGroup.LabelExpression);
                    }
                }
            }

            base.CheckProcess(onlyCheckConfig);
        }