示例#1
0
        //生成listItem列表
        private Dictionary <Vector2Int, IPsdLayer> GetListItems(IPsdLayer[] layers)
        {
            var layout = new Dictionary <Vector2Int, IPsdLayer>();

            foreach (var layer in layers)
            {
                string regexStr1 = "@[0-9]+_[0-9]+";
                string regexStr2 = "(?<=@).+(?=_[0-9]+)";
                string regexStr3 = "(?<=@[0-9]+_)[0-9]+";

                if (!Regex.IsMatch(layer.Name, regexStr1))
                {
                    continue;
                }

                var suffix = Regex.Match(layer.Name, regexStr1).ToString();
                int row    = Convert.ToInt32(Regex.Match(suffix, regexStr2).ToString());
                var column = Convert.ToInt32(Regex.Match(suffix, regexStr3).ToString());
                var key    = new Vector2Int(row, column);
                if (!layout.ContainsKey(key))
                {
                    layout.Add(key, layer);
                }
                else
                {
                    var error = "列表中:" + layer.Name + " 位置命名重复";
                    Debug.LogError(error);
                    P2UUtil.ShowError(error);
                }
            }

            return(layout);
        }
示例#2
0
        //生成psd元素列表
        private void GenerateElementMap(ref Dictionary<string, PsdElement> map, string parentName, IPsdLayer[] layers)
        {
            if (layers == null)
                return;

            foreach (var layer in layers)
            {
                var layerName = parentName + "-" + layer.Name.Replace(" ", "");
                var elementName = layerName;

                //解析为PsdElement

                //正则获取后缀与名字
                var suffixRegex = "(?<=@).+";
                var nameRegex = ".+(?=@)";
                var suffix = "";
                var name = elementName;
                if (Regex.IsMatch(elementName, suffixRegex))
                {
                    suffix = Regex.Match(elementName, suffixRegex).ToString();
                    name = Regex.Match(elementName, nameRegex).ToString();
                }

                if (suffix == "@")
                    continue;
                var type = P2UUtil.GetTypeBySuffix(suffix, layer.HasImage);

                if (type == PsdElement.ElementType.Null)
                {
                    Debug.LogError(elementName + "后缀使用错误");
                    P2UUtil.AddError(elementName + "后缀使用错误");
                    continue;
                }

                //添加子项
                var childs = layer.Childs;
                PsdElement element = P2UUtil.GetPsdElement(name, layer, type, childs);
                if (!map.ContainsKey(element.name))
                {
                    if (type != PsdElement.ElementType.Group)
                        map.Add(name, element);
                }
                else
                {
                    string error = "图层命名重复:" + layerName;
                    error = error.Replace("-", "/");
                    P2UUtil.ShowError(error);
                    Debug.LogError("图层命名重复:" + layerName);
                }

                if (element.type == PsdElement.ElementType.Group)
                    GenerateElementMap(ref map, layerName, layer.Childs);
            }

            P2UUtil.ShowError();
            P2UUtil.ClearError();
        }