コード例 #1
0
        public static void RecordAndRemoveReference(GameObject g, bool removeReference)
        {
            var text = g.GetComponent <Text>();

            if (text == null)
            {
                return;
            }
            Font font = text.font;

            if (font == null || font.name == "" || font.name.Equals("Arial", StringComparison.OrdinalIgnoreCase))
            {
                Debug.LogWarning("No Font:" + AnimationUtility.CalculateTransformPath(g.transform, null));
                return;
            }
            var reassign = g.GetOrAddComponent <TextFontReassign>();

            var path = AssetDatabase.GetAssetPath(font);

            path = UIUpdateUtil.GetResourcePath(path);
            reassign.fontPath = path;
            if (removeReference)
            {
                text.font = null;
            }
        }
コード例 #2
0
        public static void RecordAndRemoveReference(GameObject g, bool removeReference)
        {
            Image image = g.GetComponent <Image>();

            if (image == null)
            {
                return;
            }
            Sprite spt = image.sprite;

            if (spt == null)
            {
                return;
            }
            var             path     = AssetDatabase.GetAssetPath(spt);
            TextureImporter importer = TextureImporter.GetAtPath(path) as TextureImporter;

            if (importer == null)
            {
                return;
            }
            var atlasName = importer.spritePackingTag;
            var sptName   = spt.name;

            if (string.IsNullOrEmpty(atlasName))
            { //不在图集中
                sptName = UIUpdateUtil.GetResourcePath(path);
                if (sptName == null)
                {
                    return;
                }
            }
            else
            {
                if (atlasName.Contains("/"))
                { //可能使用/来处理本地化图集等变种
                    atlasName = atlasName.Substring(atlasName.LastIndexOf('/') + 1);
                }
            }
            var reassign = g.GetOrAddComponent <ImageSpriteReassign>();

            reassign.atlasPath  = atlasName;
            reassign.spriteName = sptName;
            if (removeReference)
            {
                image.sprite = null;
            }
        }