public string getStateSprite(WXHierarchyContext context, UISprite uiSprite, string spriteName)
        {
            string uuid = WXSpriteFrame.getSprite(uiSprite.atlas as UIAtlas, spriteName, context.preset);

            context.AddResource(uuid);
            return(uuid);
        }
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            Texture2D texture2D = (Texture2D)(uiAtlas.spriteMaterial).GetTexture("_MainTex");

            if (texture2D != null)
            {
                string path        = AssetDatabase.GetAssetPath(texture2D.GetInstanceID());
                string texturePath = new WXTexture(texture2D).Export(context.preset);
                context.AddResource(texturePath);

                for (int i = 0; i < uiAtlas.spriteList.Count; i++)
                {
                    string spriteframePath = new WXSpriteFrame(uiAtlas.spriteList[i], texturePath, path).Export(context.preset);
                    context.AddResource(spriteframePath);
                }
            }
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", "UIAtlas");
            return(json);
        }
Example #3
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);
        }
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            if (uiSprite != null)
            {
                //if (uiSprite.isAnchored)
                //{
                //    JSONObject anchorJson = new JSONObject(JSONObject.Type.OBJECT);
                //    anchorJson.AddField("type", "UIWidget");
                //    JSONObject anchorSubJSON = new JSONObject(JSONObject.Type.OBJECT);
                //    anchorSubJSON.AddField("leftMargin", uiSprite.leftAnchor.absolute);
                //    anchorSubJSON.AddField("rightMargin", uiSprite.rightAnchor.absolute);
                //    anchorSubJSON.AddField("topMargin", uiSprite.topAnchor.absolute);
                //    anchorSubJSON.AddField("bottomMargin", uiSprite.bottomAnchor.absolute);
                //    anchorJson.AddField("data", anchorSubJSON);

                //}

                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 * uiSprite.color.r);
                color.Add(255f * uiSprite.color.g);
                color.Add(255f * uiSprite.color.b);
                color.Add(255f * uiSprite.color.a);
                subJSON.AddField("color", color);
                subJSON.AddField("colorBlendType", 0);

                //if (uiSprite.name == "PageBagChecked")
                //{
                //    Debug.Log("++==++==++");

                //    Debug.Log(uiSprite.isAnchored);
                //    Debug.Log(uiSprite.bottomAnchor.absolute);
                //    Debug.Log(uiSprite.bottomAnchor.target.name);
                //}

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

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

                if (uiSprite.atlas != null)
                {
                    string uuid = WXSpriteFrame.getSprite(uiSprite.atlas, uiSprite.spriteName, context.preset);
                    if (uuid == null)
                    {
                        Debug.LogWarning("获取sprite失败: " + uiSprite.spriteName);
                    }
                    else
                    {
                        context.AddResource(uuid);
                    }

                    if (uuid != null)
                    {
                        subJSON.AddField("spriteFrame", uuid);
                    }
                    else
                    {
                        JSONObject nullJSON = new JSONObject(JSONObject.Type.NULL);
                        subJSON.AddField("spriteFrame", nullJSON);
                    }
                }
                else
                {
                    JSONObject nullJSON = new JSONObject(JSONObject.Type.NULL);
                    subJSON.AddField("spriteFrame", nullJSON);
                }

                subJSON.AddField("active", uiSprite.enabled);
                json.AddField("data", subJSON);

                return(json);
            }
            else
            {
                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);
                color.Add(255f);
                color.Add(255f);
                color.Add(255f);
                subJSON.AddField("color", color);
                subJSON.AddField("colorBlendType", 0);
                subJSON.AddField("type", (int)UI2DSprite.Type.Simple);
                subJSON.AddField("flip", (int)UI2DSprite.Flip.Nothing);
                subJSON.AddField("fillCenter", false);
                subJSON.AddField("fillDir", (int)UI2DSprite.FillDirection.Horizontal);
                subJSON.AddField("fillAmount", 0);
                subJSON.AddField("invertFill", false);

                JSONObject nullJSON = new JSONObject(JSONObject.Type.NULL);
                subJSON.AddField("spriteFrame", nullJSON);

                subJSON.AddField("active", true);
                json.AddField("data", subJSON);

                return(json);
            }
        }
Example #5
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);
        }