예제 #1
0
    static void ShowWindow()
    {
        if (Selection.activeObject == null)
        {
            return;
        }

        Texture2D t = Selection.activeObject as Texture2D;

        if (t == null)
        {
            EditorUtility.DisplayDialog("错误", "只能转换Png文件!", "ok");
            return;
        }

        TexturePackerImporterEditor tpie = new TexturePackerImporterEditor();

        tpie.texFile = t;

        string path     = AssetDatabase.GetAssetPath(tpie.texFile);
        var    jsonFile = AssetDatabase.LoadAssetAtPath(System.IO.Path.ChangeExtension(path, "txt"), typeof(TextAsset)) as TextAsset;

        if (jsonFile == null)
        {
            EditorUtility.DisplayDialog("提示", "Json 文件必须放在 Png 文件同目录下", "ok");
            return;
        }
        tpie.frames = JsonUtility.FromJson <Frames> (jsonFile.text);
        tpie.ImportTexture();
    }
예제 #2
0
    public static void ShowWindow()
    {
        if (Selection.activeObject == null)
        {
            return;
        }

        Texture2D t = Selection.activeObject as Texture2D;

        if (t == null)
        {
            EditorUtility.DisplayDialog("错误", "只能转换Png文件!", "ok");
            return;
        }

        TexturePackerImporterEditor tpie = new TexturePackerImporterEditor
        {
            texFile = t
        };

        string path     = AssetDatabase.GetAssetPath(tpie.texFile);
        var    jsonFile = AssetDatabase.LoadAssetAtPath(System.IO.Path.ChangeExtension(path, "txt"), typeof(TextAsset)) as TextAsset;

        if (jsonFile == null)
        {
            EditorUtility.DisplayDialog("提示", "Json 文件必须放在 Png 文件同目录下", "ok");
            return;
        }
        EditorHelper.RunPython(Application.dataPath + "/../tools/texturePackerJsonFormat.py");
        AssetDatabase.Refresh();

        tpie.frames = JsonUtility.FromJson <Frames> (jsonFile.text);
        tpie.ImportTexture();
    }