/// <summary>
    /// 利用Unity打包的图集
    /// </summary>
    void CustomPackGUI()
    {
        EditorGUI.BeginChangeCheck();
        SettingAsset = (EditorGUILayout.ObjectField("图集信息", this.SettingAsset, typeof(UnityPackSetting), false,
                                                    new GUILayoutOption[0]) as UnityPackSetting);
        if (EditorGUI.EndChangeCheck())
        {
            this.ConsoleContent = string.Empty;
        }

        if (SettingAsset == null)
        {
            return;
        }


        if (GUILayout.Button("生成", new GUILayoutOption[0]))
        {
            TextureSource          = SettingAsset.Atlas as Texture2D;
            RichTextAnimateDic     = new Dictionary <string, RichTextAnimate>();
            RichTextSpriteInfoList = CreateSpriteFromCustomPackSetting(SettingAsset);


            string text = string.Empty;
            text = EditorUtility.SaveFilePanel("保存富文本数据", SettingAsset.OutputAbsolutelyPath, SettingAsset.Name, "asset");
            if (text.Length == 0)
            {
                return;
            }
            this.SaveSpriteAsset(text);
        }

        GUILayout.Space(5f);
    }
    private List <TexturePackSprite> CreateSpriteFromCustomPackSetting(UnityPackSetting setting)
    {
        List <TexturePackSprite> list = new List <TexturePackSprite>();

        RichTextAnimateDic.Clear();
        for (int i = 0; i < setting.TexturePackSprite.Count; i++)
        {
            UnityPackSprite frame = setting.TexturePackSprite[i];

            TexturePackSprite spriteData = new TexturePackSprite();
            spriteData.id       = i;
            spriteData.name     = frame.filename;
            spriteData.hashCode = spriteData.name.GetHashCode();

            spriteData.x        = frame.x;
            spriteData.y        = frame.y;
            spriteData.width    = frame.width;
            spriteData.height   = frame.height;
            spriteData.pivot    = frame.pivot;
            spriteData.rotated  = frame.rotated;
            spriteData.xAdvance = spriteData.width;
            spriteData.scale    = 1f;
            spriteData.xOffset  = 0f - spriteData.width * spriteData.pivot.x;
            spriteData.yOffset  = spriteData.height - spriteData.height * spriteData.pivot.y;

            list.Add(spriteData);

            int pos = spriteData.name.LastIndexOf("_");

            if (pos > 0)
            {
                string key      = spriteData.name.Substring(0, pos);
                string aniIndex = spriteData.name.Substring(pos + 1, spriteData.name.Length - pos - 1);

                if (!RichTextAnimateDic.ContainsKey(key))
                {
                    RichTextAnimate richTextAnimate = new RichTextAnimate();
                    RichTextAnimateDic.Add(key, richTextAnimate);
                }

                spriteData.animatGroup = key;
                spriteData.animatIndex = int.Parse(aniIndex);

                RichTextAnimateDic[key].animateName = key;
                RichTextAnimateDic[key].frameCount++;
                RichTextAnimateDic[key].spriteList.Add(spriteData);
            }
        }

        return(list);
    }
Beispiel #3
0
    private List <BMFontSprite> CreateSpriteFromCustomPackSetting(UnityPackSetting setting)
    {
        List <BMFontSprite> list = new List <BMFontSprite>();

        for (int i = 0; i < setting.TexturePackSprite.Count; i++)
        {
            UnityPackSprite frame = setting.TexturePackSprite[i];

            BMFontSprite spriteData = new BMFontSprite();
            spriteData.id       = i;
            spriteData.name     = frame.filename;
            spriteData.hashCode = spriteData.name.GetHashCode();

            string key = string.Empty;
            int    pos = spriteData.name.LastIndexOf("_");

            if (pos == -1)
            {
                key = spriteData.name;
                pos = spriteData.name.Length;
            }
            else
            {
                key = spriteData.name.Substring(pos + 1, spriteData.name.Length - pos - 1);
            }


            spriteData.key     = key;
            spriteData.group   = spriteData.name.Substring(0, pos);
            spriteData.x       = frame.x;
            spriteData.y       = frame.y;
            spriteData.width   = frame.width;
            spriteData.height  = frame.height;
            spriteData.pivot   = frame.pivot;
            spriteData.scale   = 1f;
            spriteData.xOffset = 0f - spriteData.width * spriteData.pivot.x;
            spriteData.yOffset = spriteData.height - spriteData.height * spriteData.pivot.y;

            list.Add(spriteData);
        }

        return(list);
    }