Seanba / Tiled2Unity

Export Tiled Map Editor (TMX) files into Unity
Other
497 stars 120 forks source link

Read-only export errors when using .NET 4.6 scripting runtime #117

Closed jpur closed 7 years ago

jpur commented 7 years ago

When using the .NET 4.6 runtime available in the newest Unity version, Tiled2Unity seems unable to export tilemaps and throws errors like this:

UnityException: Assets/Tiled2Unity/Textures/test.png is read-only Tiled2Unity.ImportUtils.ReadyToWrite (System.String path) (at Assets/Tiled2Unity/Scripts/Editor/ImportUtils.cs:167) Tiled2Unity.ImportTiled2Unity.ImportAllTextures (Tiled2Unity.ImportBehaviour importComponent) (at Assets/Tiled2Unity/Scripts/Editor/ImportTiled2Unity.Texture.cs:53) ...

Reproduction: Make a new Unity project, set the Scripting Runtime Version to .NET 4.6 and try exporting a tilemap to get an error. Switch it back and it imports fine.

Seanba commented 7 years ago

Thanks for the bug report. I was able to reproduce and fix. It will be available (hopefully soon) in the next version of Tiled2Unity.

FWIW, replacing the ReadyToWrite method in ImportUtils.cs with this will get .NET 4.6 working for you if you don't want to wait ...

        public static void ReadyToWrite(string path)
        {
            // Creates directories in path if they don't exist
            FileInfo info = new FileInfo(path);
            info.Directory.Create();

            // Make sure file is not readonly
            if (info.Exists)
            {
                if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    throw new UnityException(String.Format("{0} is read-only", path));
                }
            }
        }
Seanba commented 7 years ago

FYI: Version 1.0.12.4 of Tiled2Unity contains the fix for this.