Ejemplo n.º 1
0
    static private void RewriteUIPrefab(Transform node)
    {
        ImageEx _uisprite = node.GetComponent <ImageEx>();

        if (_uisprite != null)
        {
            if (_uisprite.sprite != null)
            {
                string          path   = AssetDatabase.GetAssetPath(_uisprite.sprite);
                TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter;

                if (texImp != null)
                {
                    _uisprite.SetInfo(texImp.spritePackingTag, _uisprite.sprite.name);
                }
                else
                {
                    _uisprite.SetInfo(null, null);
                }
                _uisprite.sprite = null;
            }
            else
            {
                _uisprite.SetInfo(null, null);
            }
        }

        RawImageEx _uitexture = node.GetComponent <RawImageEx>();

        if (_uitexture != null)
        {
            if (_uitexture.texture != null)
            {
                _uitexture.SetInfo(_uitexture.texture.name);
                _uitexture.texture = null;
            }
            else
            {
                _uitexture.SetInfo(null);
            }
        }
        ButtonEx _uibutton = node.GetComponent <ButtonEx>();

        if (_uibutton != null)
        {
            if (_uibutton.spriteState.highlightedSprite != null)
            {
                string          path   = AssetDatabase.GetAssetPath(_uibutton.spriteState.highlightedSprite);
                TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter;
                if (texImp != null)
                {
                    _uibutton.SetButtonInfo(1, texImp.spritePackingTag, _uibutton.spriteState.highlightedSprite.name);
                }
                else
                {
                    _uibutton.SetButtonInfo(1, null, null);
                }
            }
            else
            {
                _uibutton.SetButtonInfo(1, null, null);
            }

            if (_uibutton.spriteState.pressedSprite != null)
            {
                string          path   = AssetDatabase.GetAssetPath(_uibutton.spriteState.pressedSprite);
                TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter;
                if (texImp != null)
                {
                    _uibutton.SetButtonInfo(2, texImp.spritePackingTag, _uibutton.spriteState.pressedSprite.name);
                }
                else
                {
                    _uibutton.SetButtonInfo(2, null, null);
                }
            }
            else
            {
                _uibutton.SetButtonInfo(2, null, null);
            }

            if (_uibutton.spriteState.disabledSprite != null)
            {
                string          path   = AssetDatabase.GetAssetPath(_uibutton.spriteState.disabledSprite);
                TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter;
                if (texImp != null)
                {
                    _uibutton.SetButtonInfo(3, texImp.spritePackingTag, _uibutton.spriteState.disabledSprite.name);
                }
                else
                {
                    _uibutton.SetButtonInfo(3, null, null);
                }
            }
            else
            {
                _uibutton.SetButtonInfo(3, null, null);
            }

            _uibutton.spriteState = new SpriteState();
        }

        TextEx _uitext = node.GetComponent <TextEx>();

        if (_uitext != null)
        {
            if (_uitext.font != null)
            {
                if (_uitext.font.name.Equals("Arial"))
                {
                    //_uitext.SetInfo("DFYuanW7");
                }
                else
                {
                    _uitext.SetInfo(_uitext.font.name);
                    _uitext.font = null;
                }
            }
            else
            {
                _uitext.SetInfo(null);
            }
        }
        for (int i = 0; i < node.childCount; ++i)
        {
            RewriteUIPrefab(node.GetChild(i));
        }
    }