예제 #1
0
 public E2DWidgetRef(E2DWidget widget, RectTransform node, RectTransform root)
 {
     this.root      = root;
     this.node      = node;
     this.id        = -1;
     this.refWidget = widget;
     this.name      = node.name;
 }
예제 #2
0
 public E2DImage(E2DSprite e2DSprite, Image image, E2DWidget container, RectTransform root)
 {
     this.root      = root;
     this.node      = image.rectTransform;
     this.image     = image;
     this.id        = e2DSprite.id;
     this.name      = image.name;
     this.container = container;
 }
예제 #3
0
    public E2DWidget AddWidget(Transform prefab)
    {
        var widget = new E2DWidget(prefab);

        RegisterCom(widget);
        this.widgets.Add(widget);
        this.uiRefMap.Add(prefab.name, widget);
        return(widget);
    }
예제 #4
0
 public E2DRawImage(RawImage rawImage, E2DWidget container, RectTransform root)
 {
     this.root     = root;
     this.node     = rawImage.rectTransform;
     this.rawImage = rawImage;
     //引用外部资源时ID为特定值
     this.id        = 0xFFFF - 1;
     this.name      = string.Format("{0}/{1}.png@{2}", E2DPackage.RawImageDir, rawImage.texture.name, rawImage.name);
     this.container = container;
 }
예제 #5
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);
        }
    }