internal static string getSprite(Sprite sprite, ExportPreset preset)
        {
            Texture2D texture2D = sprite.texture as Texture2D;
            string    res       = null;

            if (texture2D != null)
            {
                string picturePath = AssetDatabase.GetAssetPath(texture2D.GetInstanceID());

                string texturePath = new WXTexture(texture2D).Export(preset);

                WXUGUISpriteFrame spriteConverter = new WXUGUISpriteFrame(sprite, texturePath, picturePath);
                string            uuid            = spriteConverter.Export(preset);
                return(uuid);
            }
            return(res);
        }
        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);
        }
Esempio n. 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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        // 导出一个资源
        private void DequeueAndExport(int maxCount)
        {
            string guid      = exportQueue.Dequeue();
            string assetPath = AssetDatabase.GUIDToAssetPath(guid);

            EditorUtility.DisplayProgressBar(
                "资源导出",
                assetPath,
                (float)(maxCount - exportQueue.Count - 1) / maxCount
                );

            // texture2d
            if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(Texture2D))
            {
                Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, AssetDatabase.GetMainAssetTypeAtPath(assetPath));

                try
                {
                    WXTexture converter = new WXTexture(texture);
                    PresetUtil.writeGroup(converter, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/);
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                    Debug.LogError(e.StackTrace);
                }
                finally
                {
                    if (exportQueue.Count == 0)
                    {
                        EditorUtility.ClearProgressBar();
                    }
                    else
                    {
                        DequeueAndExport(maxCount);
                    }
                }
                return;
            }

            // texturecube
            if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(Cubemap))
            {
                Cubemap textureCube = (Cubemap)AssetDatabase.LoadAssetAtPath(assetPath, AssetDatabase.GetMainAssetTypeAtPath(assetPath));

                try
                {
                    WXTextureCube converter = new WXTextureCube(textureCube);
                    PresetUtil.writeGroup(converter, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/);
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                    Debug.LogError(e.StackTrace);
                }
                finally
                {
                    if (exportQueue.Count == 0)
                    {
                        EditorUtility.ClearProgressBar();
                    }
                    else
                    {
                        DequeueAndExport(maxCount);
                    }
                }
                return;
            }

            // gameObject
            if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(GameObject))
            {
                GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(
                    assetPath,
                    AssetDatabase.GetMainAssetTypeAtPath(assetPath)
                    );
                // prefab
                // 忘了为什么要加这句判断了,资源管理器里的prefab理论上这里返回都是null
                if (WXUtility.GetPrefabSource(prefab))
                {
                    DequeueAndExport(maxCount);
                    return;
                }


                // 资源管理器里的prefab,GetPrefabSource是null,这里就要实例化之后再取。
                prefab = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
                Selection.activeObject    = prefab;
                prefab.transform.position = Vector3.zero;
                prefab.SetActive(true);
                //RichText.StaticTextCreator[] staicTextCreators = prefabRoot.GetComponentsInChildren<RichText.StaticTextCreator>();
                //if (staicTextCreators != null && staicTextCreators.Length > 0)
                //{
                //    for (int k = 0; k < staicTextCreators.Length; k++)
                //    {
                //        RichText.StaticTextCreator stc = staicTextCreators[k];
                //        stc.ParseStaticText(true);
                //    }
                //}

                WXPrefab wxPrefab = new WXPrefab(prefab, assetPath);
                PresetUtil.writeGroup(wxPrefab, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/);

                UnityEngine.Object.DestroyImmediate(prefab);
            }

            if (exportQueue.Count == 0)
            {
                EditorUtility.ClearProgressBar();
            }
            else
            {
                DequeueAndExport(maxCount);
            }
        }