Пример #1
0
        internal static string getSprite(UIAtlas atlas, string uispriteName, ExportPreset preset)
        {
            Material  atlasMaterial = atlas.spriteMaterial;
            Texture2D texture2D     = (Texture2D)atlasMaterial.GetTexture("_MainTex");
            string    res           = null;

            if (texture2D != null)
            {
                string picturePath = AssetDatabase.GetAssetPath(texture2D.GetInstanceID());
                //Texture2D copyTexture = DuplicateTexture(texture2D);

                //picturePath = path.Split('.')[0] + ".png";
                string texturePath = new WXTexture(texture2D).Export(preset);

                JSONObject metadata = TextureUtil.getMeta(texture2D);

                BetterList <string> allSpriteList = atlas.GetListOfSprites();
                string[]            list          = allSpriteList.ToArray();
                foreach (string spriteName in list)
                {
                    UISpriteData  currentData     = atlas.GetSprite(spriteName);
                    WXSpriteFrame spriteConverter = new WXSpriteFrame(currentData, texturePath, picturePath);
                    string        uuid            = spriteConverter.Export(preset);
                    // 这里不需要了,外部去给hierarchyContext addResource就好
                    if (spriteName == uispriteName)
                    {
                        res = uuid;
                        return(res);
                        //    WXBeefBallExportContext.addDep(uuid);
                    }
                    //else
                    //{
                    //    WXBeefBallExportContext.addNoDependence(uuid);
                    //}
                }
            }
            return(res);
        }
Пример #2
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", "UISprite");

            JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT);

            JSONObject color = new JSONObject(JSONObject.Type.ARRAY);

            color.Add(255f * uiTexture.color.r);
            color.Add(255f * uiTexture.color.g);
            color.Add(255f * uiTexture.color.b);
            color.Add(255f * uiTexture.color.a);
            subJSON.AddField("color", color);
            subJSON.AddField("colorBlendType", 0);

            UI2DSprite.Type type = uiTexture.type;
            subJSON.AddField("type", (int)type);

            UI2DSprite.Flip flipType = uiTexture.flip;
            subJSON.AddField("flip", (int)flipType);
            subJSON.AddField("fillCenter", uiTexture.centerType == UI2DSprite.AdvancedType.Sliced);
            subJSON.AddField("fillDir", (int)uiTexture.fillDirection);
            subJSON.AddField("fillAmount", uiTexture.fillAmount);
            subJSON.AddField("invertFill", uiTexture.invert);

            string texturePath = "";

            if (uiTexture.mainTexture != null)
            {
                Texture2D texture2D = (Texture2D)uiTexture.mainTexture;
                if (texture2D != null)
                {
                    string path = AssetDatabase.GetAssetPath(texture2D.GetInstanceID());

                    texturePath = new WXTexture(texture2D).Export(context.preset);// MaterialUtil.SaveTextureFile(texture2D);
                    context.AddResource(texturePath);

                    UISpriteData data = new UISpriteData();
                    data.width  = uiTexture.mainTexture.width;
                    data.height = uiTexture.mainTexture.height;

                    WXSpriteFrame spriteFrame = new WXSpriteFrame(data, texturePath, path);
                    string        key         = spriteFrame.Export(context.preset);

                    subJSON.AddField("spriteFrame", key);
                    context.AddResource(key);
                }
            }
            else
            {
                JSONObject nullJSON = new JSONObject(JSONObject.Type.NULL);
                subJSON.AddField("spriteFrame", nullJSON);
            }

            subJSON.AddField("active", uiTexture.enabled);

            json.AddField("data", subJSON);

            return(json);
        }