示例#1
0
        /// <summary>
        /// 核心算法步骤:
        /// 1、获得资源的依赖列表List<string> dependAssetPathList = GetDependAssetPathList(entryPath);
        /// 2、根据节点正则表达式,获得该节点分离出来的资源列表pathSet = ApplyStrategyNode(entryPath, asset, node); pathList = pathSet.ToList()
        /// 3、移除pathList中和之前节点帅选结果相同的部分RemoveFilteredPath(filteredPathSet, pathList);
        /// 4、在dependAssetPathList中移除pathList,RemoveFromDependPathList(dependAssetPathList, pathList);
        /// 5、讲pathList加入筛选资源集合AddToFilteredPathSet(filteredPathSet, pathList);
        /// 6、若资源存在临时创建的副本,用副本替换原资源,对副本打包
        /// </summary>
        /// <param name="entryPath"></param>
        /// <param name="strategy"></param>
        /// <returns></returns>
        public virtual List <List <string> > Process(string entryPath, AssetBuildStrategy strategy)
        {
            Object                asset = GetAsset(entryPath);
            List <string>         dependAssetPathList = GetDependAssetPathList(entryPath);
            List <List <string> > pathListList        = new List <List <string> >();
            HashSet <string>      filteredPathSet     = new HashSet <string>();

            for (int i = 0; i < strategy.nodeList.Count; i++)
            {
                StrategyNode     node = strategy.nodeList[i];
                HashSet <string> pathSet;
                if (string.IsNullOrEmpty(node.processor) == false)
                {
                    pathSet = ApplyStrategyNode(entryPath, asset, node);
                }
                else
                {
                    pathSet = ApplyEmptyStrategyNode(dependAssetPathList, node);
                }
                List <string> pathList = pathSet.ToList();
                RemoveFilteredPath(filteredPathSet, pathList);
                RemoveFromDependPathList(dependAssetPathList, pathList);
                AddToFilteredPathSet(filteredPathSet, pathList);
                ReplaceWithTempAssetPath(pathList);
                pathListList.Add(pathList);
            }
            SaveAssets(asset, entryPath);
            return(pathListList);
        }
示例#2
0
        private List <StrategyNode> GetStrategyNodeList(string json, string strategyName)
        {
            List <StrategyNode> result   = new List <StrategyNode>();
            JsonData            jsonData = null;

            try
            {
                jsonData = JsonMapper.ToObject(json);
            }catch (Exception e)
            {
                Logger.GetLogger(AssetBundleExporter.LOGGER_NAME).Log(json);
                Logger.GetLogger(AssetBundleExporter.LOGGER_NAME).Exception(e);
            }

            JsonData strategyData = jsonData["strategy"];

            for (int i = 0; i < strategyData.Count; i++)
            {
                StrategyNode node     = new StrategyNode();
                JsonData     nodeData = strategyData[i];
                node.strategy  = strategyName;
                node.processor = nodeData.Keys.Contains("processor") == true ? (string)nodeData["processor"] : string.Empty;
                node.mode      = ((string)nodeData["mode"]).ToLower();
                node.pattern   = new Regex((string)nodeData["pattern"], RegexOptions.IgnoreCase);
                result.Add(node);
                Verify(node);
            }

            return(result);
        }
        public override HashSet <string> Process(string entryPath, GameObject go, StrategyNode node)
        {
            HashSet <string> result = new HashSet <string>();
            Image            image  = go.GetComponent <Image>();

            if (image != null && image.material != null)
            {
                result = _shaderProcessor.Process(entryPath, image.material, node);
            }
            return(result);
        }
示例#4
0
 private void Verify(StrategyNode node)
 {
     if (node.mode == PackageMode.FOLDER)
     {
         string[] groupName = node.pattern.GetGroupNames();
         int      index     = Array.IndexOf <string>(groupName, AssetPathHelper.REGEX_TOKEN_PATH);
         if (index == -1)
         {
             string msg = "打包策略中,Folder模式节点中Pattern错误,没有文件夹路径定义,策略:" + node.strategy + ", Pattern" + node.pattern;
             AssetBundleExporter.ThrowException(msg);
         }
     }
 }
示例#5
0
        public override HashSet <string> Process(string entryPath, GameObject go, StrategyNode node)
        {
            HashSet <string> result = new HashSet <string>();
            Image            image  = go.GetComponent <Image>();

            if (image != null)
            {
                string path = AssetDatabase.GetAssetPath(go);
                if (node.pattern.IsMatch(path))
                {
                    string folderPath = Path.GetDirectoryName(path);
                    image.spriteKey = AssetPathHelper.ReplaceSlash(AssetPathHelper.EliminaterStartToken(folderPath)) + "${0}";
                    result.Add(path);
                }
            }
            return(result);
        }
示例#6
0
        public override HashSet <string> Process(string entryPath, GameObject go, StrategyNode node)
        {
            HashSet <string> result = new HashSet <string>();
            Text             text   = go.GetComponent <Text>();

            if (text != null && text.font != null)
            {
                string fontPath = AssetDatabase.GetAssetPath(text.font);
                if (node.pattern.IsMatch(fontPath))
                {
                    text.fontKey = AssetPathHelper.GetObjectKey(entryPath, fontPath, text.font, node);
                    text.font    = null;
                    result.Add(fontPath);
                }
            }
            return(result);
        }
        // TODO 看不懂
        public override HashSet <string> Process(string entryPath, GameObject go, StrategyNode node)
        {
            HashSet <string> result    = new HashSet <string>();
            Animation        animation = go.GetComponent <Animation>();

            if (animation != null)
            {
                AnimationClip[] clips       = AnimationUtility.GetAnimationClips(go);
                AnimationClip   defaultClip = animation.clip;
                VerifyClipsName(entryPath, clips);
                string[] clipTokens = GetClipTokens(go, clips.Length);
                if (defaultClip != null)
                {
                    string defaultClipPath = AssetDatabase.GetAssetPath(defaultClip);
                    if (node.pattern.IsMatch(defaultClipPath))
                    {
                        string defaultClipKey = AssetPathHelper.GetObjectKey(entryPath, defaultClipPath, defaultClip, node);
                        result.Add(defaultClipPath);
                        animation.clip = null;
                        clipTokens[0]  = defaultClipKey;
                    }
                }

                for (int i = 0; i < clips.Length; i++)
                {
                    AnimationClip clip = clips[i];
                    if (clip != null)
                    {
                        string clipPath = AssetDatabase.GetAssetPath(clip);
                        if (node.pattern.IsMatch(clipPath))
                        {
                            string clipKey = AssetPathHelper.GetObjectKey(entryPath, clipPath, clip, node);
                            result.Add(clipPath);
                            animation.RemoveClip(clip);
                            clipTokens[i + 1] = clipKey;
                        }
                    }
                }
                if (IsClipTokensEmpty(clipTokens) == false)
                {
                    AssetBridgeHelper.AddEntry(go, this.Name, clipTokens);
                }
            }
            return(result);
        }
示例#8
0
        public void FillNoTexturePropertyData(Material material, StrategyNode node)
        {
            int propertyCount = ShaderUtil.GetPropertyCount(material.shader);

            for (int i = 0; i < propertyCount; i++)
            {
                if (ShaderUtil.GetPropertyType(material.shader, i) != ShaderUtil.ShaderPropertyType.TexEnv)
                {
                    string propertyName = ShaderUtil.GetPropertyName(material.shader, i);
                    if (_recordPropertySet.Contains(propertyName) == false)
                    {
                        _recordPropertySet.Add(propertyName);
                        List <string> list = GenerateNonTexturePropertyTokenList(material, i);
                        propertyTokenListList.Add(list);
                    }
                }
            }
        }
示例#9
0
        public override HashSet <string> Process(string entryPath, GameObject go, StrategyNode node)
        {
            HashSet <string> result = new HashSet <string>();
            Image            image  = go.GetComponent <Image>();

            if (image != null && image.material != null)
            {
                string materialPath = MaterialAssetProcessor.GetMaterialPath(image.material);
                if (node.pattern.IsMatch(materialPath))
                {
                    result.Add(materialPath);
                    image.materialKey = AssetPathHelper.GetObjectKey(entryPath, materialPath, image.material, node);
                    image.material    = null;
                    image.spriteKey   = AssetPathHelper.GetObjectKey(entryPath, materialPath, image.sprite, node);
                    image.sprite      = null;
                }
            }
            return(result);
        }
示例#10
0
        public HashSet <string> Process(string entryPath, Material material, StrategyNode node)
        {
            HashSet <string> result = new HashSet <string>();

            if (material == null)
            {
                Debug.LogError("资源打包出错, 缺少Material:" + entryPath);
            }
            string materialPath = MaterialAssetProcessor.GetMaterialPath(material);
            string shaderPath   = MaterialAssetProcessor.GetShaderPath(material.shader);

            if (node.pattern.IsMatch(shaderPath))
            {
                MaterialJsonData jsonData = MaterialJsonData.GetMaterialJsonData(materialPath);
                jsonData.shaderFileName = GetShaderFileName(material.shader);
                jsonData.shaderKey      = AssetPathHelper.GetObjectKey(entryPath, shaderPath, material.shader, node);
                jsonData.FillNoTexturePropertyData(material, node);
                result.Add(shaderPath);
            }
            return(result);
        }
示例#11
0
        private HashSet <string> ApplyEmptyStrategyNode(List <string> dependPathList, StrategyNode node)
        {
            HashSet <string> result = new HashSet <string>();

            foreach (string path  in dependPathList)
            {
                if (node.pattern.IsMatch(path))
                {
                    result.Add(path);
                }
            }
            return(result);
        }
示例#12
0
 /// <summary>
 /// 在资源上应用策略节点筛选资源
 /// </summary>
 /// <param name="entryPath"></param>
 /// <param name="asset"></param>
 /// <param name="node"></param>
 /// <returns></returns>
 protected virtual HashSet <string> ApplyStrategyNode(string entryPath, Object asset, StrategyNode node)
 {
     return(new HashSet <string>());
 }
示例#13
0
        /// <summary>
        /// entryPath:打包入口资源路径
        /// assetPath:打包入口资源所依赖的资源路径
        /// </summary>
        /// <param name="entryPath"></param>
        /// <param name="materialPath"></param>
        /// <param name="material"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public static string GetObjectKey(string entryPath, string assetPath, Object obj, StrategyNode node)
        {
            string token = string.Empty;

            if (string.IsNullOrEmpty(assetPath))
            {
                throw new Exception("Asset physicalPath should not be empty!");
            }

            if (node.mode == PackageMode.SINGLE)
            {
                token = GetSingleModeBundlePath(assetPath);
                //字体ttf和模型文件是特殊的类型,一个Asset中包含多个Object
                //AssetDatabase.LoadAllAssetsAtPath(assetPath) 返回长度大于一
                if (token.Contains(FBX) || token.Contains(TTF))
                {
                    token = token + obj.GetType().Name + obj.name;
                }
            }
            else if (node.mode == PackageMode.FOLDER)
            {
                token = GetFolderModeBundlePath(assetPath, node.pattern) + obj.GetType().Name + obj.name;
            }
            else if (node.mode == PackageMode.SELECTION)
            {
                token = GetSelectionModeBundlePath(entryPath, assetPath, node.pattern) + obj.GetType().Name + obj.name;
            }
            return(token);
        }
示例#14
0
 public abstract HashSet <string> Process(string entryPath, GameObject go, StrategyNode node);
示例#15
0
        protected override HashSet <string> ApplyStrategyNode(string path, Object asset, StrategyNode node)
        {
            HashSet <string> result = new HashSet <string>();

            string[] depentAssetPaths = AssetDatabase.GetDependencies(new string[] { path });
            foreach (string s in depentAssetPaths)
            {
                if (node.pattern.IsMatch(s))
                {
                    result.Add(s);
                }
            }
            return(result);
        }
        protected override HashSet <string> ApplyStrategyNode(string entryPath, Object asset, StrategyNode node)
        {
            GameObject         go        = asset as GameObject;
            HashSet <string>   result    = new HashSet <string>();
            ComponentProcessor processor = GetComponentProcessor(node.processor);
            HashSet <string>   sub       = processor.Process(entryPath, go, node);

            result.UnionWith(sub);
            int count = go.transform.childCount;

            for (int i = 0; i < count; i++)
            {
                GameObject child = go.transform.GetChild(i).gameObject;
                result.UnionWith(ApplyStrategyNode(entryPath, child, node));
            }
            return(result);
        }
 //TODO
 public override HashSet <string> Process(string entryPath, UnityEngine.GameObject go, StrategyNode node)
 {
     throw new NotImplementedException();
 }