Beispiel #1
0
    public override string ExportFrame(int index)
    {
        string extraStr;

        if (image.color == Color.white)
        {
            extraStr = "";
        }
        else
        {
            extraStr = string.Format(", color={0}", image.color.ToBGRA());
        }

        E2DSprite e2DSprite;

        if (E2DPackage.active.spriteRefMap.TryGetValue(this.image.sprite, out e2DSprite))
        {
            var mat = E2DMatrix3x2.FromE2DImage(this, e2DSprite);
            return(string.Format("{{index = {0}, mat = {1}{2}}},\n", container.spriteIndexMap[this.image][this.image.sprite], mat, extraStr));
        }
        else
        {
            Debug.LogError("引用到不在图集内的Sprite:" + E2DHelper.PrintNodePath(node, root), this.image.sprite);
        }
        return("");
    }
Beispiel #2
0
    public override string ExportCom()
    {
        string name = E2DHelper.PrintNodePath(node, root, false);

        //没有指定id只有name字段的时候会被当作是一个Anchor
        return(string.Format("\t\t{{name = \"{0}\"}},\n", name));
    }
Beispiel #3
0
    public void Convert()
    {
#if UNITY_EDITOR
        ParseComponent(root, root);
        if (animator != null)
        {
            foreach (var clip in animator.exportClips)
            {
                if (clip == null)
                {
                    Debug.LogError("Clip is null:" + animator.name);
                    continue;
                }

                var allObjBindings = AnimationUtility.GetObjectReferenceCurveBindings(clip);
                foreach (var binding in allObjBindings)
                {
                    var image = AnimationUtility.GetAnimatedObject(this.root.gameObject, binding) as Image;
                    if (image != null)
                    {
                        var keyFrames = AnimationUtility.GetObjectReferenceCurve(clip, binding);
                        foreach (var frame in keyFrames)
                        {
                            var sprite = frame.value as Sprite;
                            if (sprite != null)
                            {
                                E2DSprite e2DSprite;
                                if (E2DPackage.active.spriteRefMap.TryGetValue(sprite, out e2DSprite))
                                {
                                    Dictionary <Sprite, int> spriteIndexes;
                                    if (!this.spriteIndexMap.TryGetValue(image, out spriteIndexes))
                                    {
                                        spriteIndexes = new Dictionary <Sprite, int>();
                                        this.spriteIndexMap.Add(image, spriteIndexes);
                                    }

                                    if (!spriteIndexes.ContainsKey(sprite))
                                    {
                                        var e2dImage = new E2DImage(e2DSprite, image, this, root);
                                        e2dImage.ignoreFrame = true;
                                        this.components.Add(e2dImage);
                                        spriteIndexes.Add(sprite, this.components.Count - 1);
                                    }
                                }
                                else
                                {
                                    Debug.LogError("引用到不在图集内的Sprite:" + E2DHelper.PrintNodePath(node, root), sprite);
                                }
                            }
                        }
                    }
                }
            }
        }
#endif
    }
Beispiel #4
0
    public E2DFontStyle(Text text)
    {
        this.size   = text.fontSize;
        this.color  = text.color;
        this.width  = (int)text.rectTransform.sizeDelta.x;
        this.height = (int)text.rectTransform.sizeDelta.y;
        switch (text.alignment)
        {
        case TextAnchor.UpperLeft:
            this.align = 0;
            break;

        case TextAnchor.UpperCenter:

            this.align = 2;
            break;

        case TextAnchor.UpperRight:
            this.align = 1;
            break;

        case TextAnchor.MiddleLeft:
        case TextAnchor.LowerLeft:
            this.align = 0;
            Debug.LogError("ejoy2d不支持此种字体对齐方式:" + E2DHelper.PrintNodePath(text.transform, E2DHelper.FindRoot(text.transform)));
            break;

        case TextAnchor.MiddleCenter:
        case TextAnchor.LowerCenter:
            this.align = 2;
            Debug.LogError("ejoy2d不支持此种字体对齐方式:" + E2DHelper.PrintNodePath(text.transform, E2DHelper.FindRoot(text.transform)));
            break;

        case TextAnchor.MiddleRight:
        case TextAnchor.LowerRight:
            this.align = 1;
            Debug.LogError("ejoy2d不支持此种字体对齐方式:" + E2DHelper.PrintNodePath(text.transform, E2DHelper.FindRoot(text.transform)));
            break;

        default:
            this.align = 2;
            break;
        }

        var localize = text.GetComponent <UILocalize>();

        if (localize != null)
        {
            this.langKey = localize.key;
        }

        var outline = text.GetComponent <Outline>();

        this.noedge = outline == null;
    }
Beispiel #5
0
 public virtual string ExportCom()
 {
     if (node == root)
     {
         return(string.Format("\t\t{{id = {0}, name = \"{1}\"}},\n", this.id, name));
     }
     else
     {
         string name = E2DHelper.PrintNodePath(node, root, false);
         if (string.IsNullOrEmpty(name))
         {
             return(string.Format("\t\t{{id = {0}}},\n", this.id));
         }
         return(string.Format("\t\t{{id = {0}, name = \"{1}\"}},\n", this.id, name));
     }
 }
Beispiel #6
0
    /// <summary>
    /// 解析Prefab结构提取相应组件
    /// </summary>
    /// <param name="node"></param>
    /// <param name="root"></param>
    private void ParseComponent(RectTransform node, RectTransform root)
    {
        //@前缀的忽略导出
        if (node.IsUnExportNode())
        {
            return;
        }

        var nestedPrefab = node.GetComponent <NestedPrefab>();

        if (nestedPrefab != null)
        {
            E2DWidget refWidget = E2DPackage.active.GetWidget(nestedPrefab.Asset.name);
            //这是一个引用外部Prefab的按钮控件
            this.components.Add(new E2DWidgetRef(refWidget, node, root));
            return;
        }

        bool isAnchor = true;
        var  btn      = node.GetComponent <Button>();

        if (btn != null)
        {
            isAnchor = false;
            //这是一个按钮组件
            if (btn.image != null)
            {
                //if (node != root)
                //{
                //	Debug.LogError("不支持此种方式布局,Button应该制作为独立控件:" + E2DHelper.PrintNodePath(node, root));
                //}

                E2DSprite e2DSprite;
                if (E2DPackage.active.spriteRefMap.TryGetValue(btn.image.sprite, out e2DSprite))
                {
                    var e2dBtn = new E2DButton(e2DSprite, btn, root);
                    this.components.Add(e2dBtn);
                }
                else
                {
                    Debug.LogError("该按钮图片没有引用图集内资源:" + E2DHelper.PrintNodePath(node, root));
                }
            }
            else
            {
                Debug.LogError("Button必须要有目标图片:" + E2DHelper.PrintNodePath(node, root));
            }
        }

        var image = node.GetComponent <Image>();

        if (image != null && btn == null)
        {
            isAnchor = false;
            if (image.sprite == null)
            {
                image.sprite = E2DPackage.active.defaultSprite;
            }
            E2DSprite e2DSprite;
            if (E2DPackage.active.spriteRefMap.TryGetValue(image.sprite, out e2DSprite))
            {
                Dictionary <Sprite, int> spriteIndexes;
                if (!this.spriteIndexMap.TryGetValue(image, out spriteIndexes))
                {
                    spriteIndexes = new Dictionary <Sprite, int>();
                    this.spriteIndexMap.Add(image, spriteIndexes);
                }

                if (!spriteIndexes.ContainsKey(image.sprite))
                {
                    var e2dImage = new E2DImage(e2DSprite, image, this, root);
                    this.components.Add(e2dImage);
                    spriteIndexes.Add(image.sprite, this.components.Count - 1);
                }
            }
            else
            {
                Debug.LogError("引用到不在图集内的Sprite:" + E2DHelper.PrintNodePath(node, root), image.sprite);
            }
        }

        var rawImage = node.GetComponent <RawImage>();

        if (rawImage != null && rawImage.texture != null)
        {
            isAnchor = false;
            var e2DRawImage = new E2DRawImage(rawImage, this, root);
            this.components.Add(e2DRawImage);
            E2DPackage.active.AddRawTexture(rawImage.texture);
        }

        var text = node.GetComponent <Text>();

        if (text != null)
        {
            isAnchor = false;
            var e2dText = new E2DText(text, root);
            this.components.Add(e2dText);
        }

        var rectMask = node.GetComponent <RectMask2D>();

        if (rectMask != null)
        {
            isAnchor = false;
            var e2dPanel = new E2DPanel(node, root);
            this.components.Add(e2dPanel);
        }

        var gridLayoutGroup = node.GetComponent <GridLayoutGroup>();

        if (gridLayoutGroup != null)
        {
            LayoutRebuilder.ForceRebuildLayoutImmediate(node);
        }

        if (isAnchor && node != root)
        {
            int childCount = node.childCount;
            for (int i = 0; i < node.childCount; i++)
            {
                var child = node.GetChild(i);
                if (child.IsUnExportNode())
                {
                    childCount -= 1;
                }
            }

            if (childCount == 0)
            {
                var e2dAnchor = new E2DAnchor(node, root);
                this.components.Add(e2dAnchor);
            }
        }

        //遍历其子节点
        foreach (RectTransform child in node)
        {
            ParseComponent(child, root);
        }
    }