示例#1
0
        internal SelectBoxElement(string name, IPsdLayer layer, ElementType type, IPsdLayer[] childs) : base(name,
                                                                                                             layer, type, childs)
        {
            normal = FindChildElement(normalSuffix);
            if (normal != null)
            {
                normalPiece = new TexturePiece(name + normalSuffix, GetTexture2D(normal));
            }
            else
            {
                canShow = false;
                P2UUtil.AddError("勾选框:" + name + "需要有一张未选择态的图");
            }

            select = FindChildElement(selectSuffix);
            if (select != null)
            {
                selectPiece = new TexturePiece(name + selectSuffix, GetTexture2D(select));
            }
            else
            {
                canShow = false;
                P2UUtil.AddError("勾选框:" + name + "需要有一张选择态的图");
            }
        }
示例#2
0
        public Image9Element(string name, IPsdLayer layer, ElementType type, IPsdLayer[] childs) : base(name, layer,
                                                                                                        type, childs)
        {
            Png9 = FindChildElement(png9Suffix);
            if (Png9 != null)
            {
                Png9Piece = new TexturePiece(name, GetTexture2D(Png9), true);
            }
            else
            {
                canShow = false;
                P2UUtil.AddError("九宫格图:" + name + "需要有一张九宫格大小的图");
            }

            Preview = FindChildElement(previewSuffix);
            if (Preview != null)
            {
                PreviewPiece = new TexturePiece(name + previewSuffix, GetTexture2D(Preview), false);
            }
            else
            {
                canShow = false;
                P2UUtil.AddError("九宫格图:" + name + "需要有一张预览图来决定其大小");
            }
        }
示例#3
0
        //初始化
        internal ButtonElement(string name, IPsdLayer layer, ElementType type, IPsdLayer[] childs) : base(name, layer,
                                                                                                          type, childs)
        {
            var normalSuffix   = "@normal";
            var pressedSuffix  = "@pressed";
            var disabledSuffix = "@disabled";

            normal = FindChildElement(normalSuffix);
            if (normal != null && normal.HasImage)
            {
                normalPiece = new TexturePiece(name + normalSuffix, GetTexture2D(normal));
            }
            else
            {
                canShow = false;
                P2UUtil.AddError("按钮:" + name + "至少要有一张正常态的图片");
            }

            pressed = FindChildElement(pressedSuffix);
            if (pressed != null && pressed.HasImage)
            {
                pressedPiece = new TexturePiece(name + pressedSuffix, GetTexture2D(pressed));
            }

            disabled = FindChildElement(disabledSuffix);
            if (disabled != null && disabled.HasImage)
            {
                disabledPiece = new TexturePiece(name + disabledSuffix, GetTexture2D(disabled));
            }
        }
示例#4
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();
        }
示例#5
0
 internal ListElement(string name, IPsdLayer layer, ElementType type, IPsdLayer[] childs) : base(name, layer,
                                                                                                 type, childs)
 {
     Background = FindChildElement(backgroundSuffix);
     if (Background != null && Background.HasImage)
     {
         BackgroundPiece = new TexturePiece(name + backgroundSuffix, GetTexture2D(Background));
     }
     else
     {
         canShow = false;
         P2UUtil.AddError("列表:" + name + "需要有一张背景图来确定列表区域");
     }
 }