Skip to content

Commit

Permalink
Update to Tiled2Unity version 1.0.12.4
Browse files Browse the repository at this point in the history
Logging has been reduced to make exporting much faster. If you want
verbose output for debugging back on you can use the -V or --verbose
command line switch.
Older versions of Unity 5.x fixed.
Fixed crash when referenced TSX file cannot be found.
  • Loading branch information
Seanba committed Aug 28, 2017
1 parent 02399cd commit f493dee
Show file tree
Hide file tree
Showing 25 changed files with 309 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private XElement CreateCollisionElementForLayer(TmxLayer layer)
LayerClipper.ProgressFunc progFunc =
delegate(string prog)
{
Logger.WriteLine(prog);
Logger.WriteInfo(prog);
};

ClipperLib.PolyTree solution = LayerClipper.ExecuteClipper(this.tmxMap, layer, xfFunc, progFunc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ from mesh in tmxTileObject.Tile.Meshes
assetPath = "Assets" + assetPath;
assetPath = assetPath.Replace("\\", "/");

Logger.WriteLine("InternalTexture : {0}", assetPath);
Logger.WriteInfo("InternalTexture : {0}", assetPath);

// Path to texture in the asset directory
xmlInternalTexture.SetAttributeValue("assetPath", assetPath);
Expand Down Expand Up @@ -145,7 +145,7 @@ from mesh in tmxTileObject.Tile.Meshes
XElement xmlImportTexture = new XElement("ImportTexture");

// Note that compression is not available in Unity. Go with Base64 string. Blerg.
Logger.WriteLine("ImportTexture : will import '{0}' to {1}", image.AbsolutePath, Path.Combine(exportToUnityProjectPath, "Textures"));
Logger.WriteInfo("ImportTexture : will import '{0}' to {1}", image.AbsolutePath, Path.Combine(exportToUnityProjectPath, "Textures"));

// Is there a color key for transparency?
if (!String.IsNullOrEmpty(image.TransparentColor))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Vertex3 V3
// Enumerate all our meshes and bake them into OBJ Wavefront format
private IEnumerable<Tuple<string, StringWriter>> EnumerateWavefrontData()
{
Logger.WriteLine("Enumerate map layers for mesh-build.");
Logger.WriteVerbose("Enumerate map layers for mesh-build.");
foreach (var layer in this.tmxMap.EnumerateTileLayers())
{
if (layer.Visible != true)
Expand All @@ -70,19 +70,19 @@ private IEnumerable<Tuple<string, StringWriter>> EnumerateWavefrontData()
yield return Tuple.Create(mesh.UniqueMeshName, BuildWavefrontStringForLayerMesh(layer, mesh, horizontalRange, verticalRange));
}
}
Logger.WriteLine("Finished enumeration.");
Logger.WriteVerbose("Finished enumeration.");

Logger.WriteLine("Enumerate tile objects for mesh-build.");
Logger.WriteVerbose("Enumerate tile objects for mesh-build.");
foreach (var mesh in this.tmxMap.GetUniqueListOfVisibleObjectTileMeshes())
{
yield return Tuple.Create(mesh.UniqueMeshName, BuildWavefrontStringForTileObjectMesh(mesh));
}
Logger.WriteLine("Finished enumeration.");
Logger.WriteVerbose("Finished enumeration.");
}

private StringWriter BuildWavefrontStringForLayerMesh(TmxLayer layer, TmxMesh mesh, IEnumerable<int> horizontalRange, IEnumerable<int> verticalRange)
{
Logger.WriteLine("Building mesh obj file for '{0}'", mesh.UniqueMeshName);
Logger.WriteVerbose("Building mesh obj file for '{0}'", mesh.UniqueMeshName);
GenericListDatabase<Vertex3> vertexDatabase = new GenericListDatabase<Vertex3>();
HashIndexOf<PointF> uvDatabase = new HashIndexOf<PointF>();
StringBuilder faces = new StringBuilder();
Expand Down Expand Up @@ -134,7 +134,7 @@ private StringWriter BuildWavefrontStringForLayerMesh(TmxLayer layer, TmxMesh me

private StringWriter BuildWavefrontStringForTileObjectMesh(TmxMesh mesh)
{
Logger.WriteLine("Building mesh obj file for tile: '{0}.obj'", mesh.UniqueMeshName);
Logger.WriteVerbose("Building mesh obj file for tile: '{0}.obj'", mesh.UniqueMeshName);
GenericListDatabase<Vertex3> vertexDatabase = new GenericListDatabase<Vertex3>();
HashIndexOf<PointF> uvDatabase = new HashIndexOf<PointF>();
StringBuilder faces = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private List<XElement> CreateObjectElementList(TmxObjectGroup objectGroup)
}
else
{
Logger.WriteLine("Object '{0}' has been added for use with custom importers", tmxObject);
Logger.WriteInfo("Object '{0}' has been added for use with custom importers", tmxObject);
}

if (objElement != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public void Export(string exportToTiled2UnityPath)
// Create an Xml file to be imported by a Unity project
// The unity project will have code that turns the Xml into Unity objects and prefabs
string fileToSave = this.tmxMap.GetExportedFilename();
Logger.WriteLine("Compiling tiled2unity file: {0}", fileToSave);
Logger.WriteInfo("Compiling tiled2unity file: {0}", fileToSave);

// Need an element for embedded file data that will be imported into Unity
// These are models and textures
List<XElement> importFiles = CreateImportFilesElements(exportToTiled2UnityPath);
List<XElement> assignMaterials = CreateAssignMaterialsElements();

Logger.WriteLine("Gathering prefab data ...");
Logger.WriteVerbose("Gathering prefab data ...");
XElement prefab = CreatePrefabElement();

// Create the Xml root and populate it
Logger.WriteLine("Writing as Xml ...");
Logger.WriteVerbose("Writing as Xml ...");

string version = Tiled2Unity.Info.GetVersion();
XElement root = new XElement("Tiled2Unity", new XAttribute("version", version));
Expand Down Expand Up @@ -100,7 +100,7 @@ public void Export(string exportToTiled2UnityPath)

// Save the file (which is importing it into Unity)
string pathToSave = Path.Combine(exportDir, fileToSave);
Logger.WriteLine("Exporting to: {0}", pathToSave);
Logger.WriteInfo("Exporting to: {0}", pathToSave);
doc.Save(pathToSave);
Logger.WriteSuccess("Succesfully exported: {0}\n Vertex Scale = {1}\n Object Type Xml = {2}",
pathToSave,
Expand Down
46 changes: 37 additions & 9 deletions tool/Tiled2Unity/Tiled2UnityLib/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ namespace Tiled2Unity
{
public class Logger
{
public delegate void WriteLineDelegate(string line);
public static event WriteLineDelegate OnWriteLine;
// Only to be printed in verbose mode. Useful for debugging.
public delegate void WriteVerboseDelegate(string line);
public static event WriteVerboseDelegate OnWriteVerbose;

// These are always printed out whether verbose is enabled or not
public delegate void WriteInfoDelegate(string line);
public static event WriteInfoDelegate OnWriteInfo;

public delegate void WriteSuccessDelegate(string line);
public static event WriteSuccessDelegate OnWriteSuccess;
Expand All @@ -19,22 +24,45 @@ public class Logger
public delegate void WriteErrorDelegate(string line);
public static event WriteErrorDelegate OnWriteError;

public static void WriteLine()
public static void WriteVerbose()
{
WriteVerbose("");
}

public static void WriteVerbose(string line)
{
if (Tiled2Unity.Settings.Verbose)
{
line += "\n";
if (OnWriteVerbose != null)
OnWriteVerbose(line);
}
}

public static void WriteVerbose(string fmt, params object[] args)
{
if (Tiled2Unity.Settings.Verbose)
{
WriteVerbose(String.Format(fmt, args));
}
}

public static void WriteInfo()
{
WriteLine("");
WriteInfo("");
}

public static void WriteLine(string line)
public static void WriteInfo(string line)
{
line += "\n";
if (OnWriteLine != null)
OnWriteLine(line);
if (OnWriteInfo != null)
OnWriteInfo(line);
Console.Write(line);
}

public static void WriteLine(string fmt, params object[] args)
public static void WriteInfo(string fmt, params object[] args)
{
WriteLine(String.Format(fmt, args));
WriteInfo(String.Format(fmt, args));
}

public static void WriteSuccess(string success)
Expand Down
4 changes: 2 additions & 2 deletions tool/Tiled2Unity/Tiled2UnityLib/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.12.3")]
[assembly: AssemblyFileVersion("1.0.12.3")]
[assembly: AssemblyVersion("1.0.12.4")]
[assembly: AssemblyFileVersion("1.0.12.4")]
63 changes: 32 additions & 31 deletions tool/Tiled2Unity/Tiled2UnityLib/Session.Args.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ private void ParseEnvironmentVariables()
string tmxPath = Environment.GetEnvironmentVariable("TILED2UNITY_TMXPATH");
if (!String.IsNullOrEmpty(tmxPath))
{
Logger.WriteLine("Found TILED2UNITY_TMXPATH environment variable: {0}", tmxPath);
Logger.WriteInfo("Found TILED2UNITY_TMXPATH environment variable: {0}", tmxPath);
this.TmxFilePath = tmxPath;
}

string unityDir = Environment.GetEnvironmentVariable("TILED2UNITY_UNITYDIR");
if (!String.IsNullOrEmpty(unityDir))
{
Logger.WriteLine("Found TILED2UNITY_UNITYDIR environment variable: {0}", unityDir);
Logger.WriteInfo("Found TILED2UNITY_UNITYDIR environment variable: {0}", unityDir);
this.TmxFilePath = tmxPath;
}
}
Expand All @@ -43,6 +43,7 @@ private bool ParseOptions(string[] args)
{ "d|depth-buffer", "Uses a depth buffer to render the layers of the map in order. Useful for sprites that may be drawn below or above map layers depending on location.", d => Tiled2Unity.Settings.DepthBufferEnabled = true },
{ "a|auto-export", "Automatically run exporter and exit. TMXPATH and UNITYDIR are not optional in this case.", a => Tiled2Unity.Settings.IsAutoExporting = true },
{ "v|version", "Display version information.", v => displayVersion = true },
{ "V|verbose", "Display verbose logging for debugging.", b => Tiled2Unity.Settings.Verbose = true },
{ "h|help", "Display this help message.", h => displayHelp = true },
};

Expand All @@ -52,7 +53,7 @@ private bool ParseOptions(string[] args)
// Are we displaying the version?
if (displayVersion)
{
Logger.WriteLine("{0} ({1}) version {2}", Tiled2Unity.Info.GetLibraryName(), Tiled2Unity.Info.GetPlatform(), Tiled2Unity.Info.GetVersion());
Logger.WriteInfo("{0} ({1}) version {2}", Tiled2Unity.Info.GetLibraryName(), Tiled2Unity.Info.GetPlatform(), Tiled2Unity.Info.GetVersion());
return false;
}

Expand All @@ -65,7 +66,7 @@ private bool ParseOptions(string[] args)

if (Tiled2Unity.Settings.IsAutoExporting)
{
Logger.WriteLine("Running automatic export.");
Logger.WriteInfo("Running automatic export.");
}

bool success = true;
Expand All @@ -74,10 +75,10 @@ private bool ParseOptions(string[] args)
// First left over option is the TMX file we are exporting
if (extra.Count() == 0)
{
Logger.WriteLine("Missing TMXPATH argument.");
Logger.WriteLine(" If using the GUI, try opening a TMX file now");
Logger.WriteLine(" If using the command line, provide a path to a TMX file");
Logger.WriteLine(" If using from Tiled Map Editor, try adding %mapfile to the command");
Logger.WriteInfo("Missing TMXPATH argument.");
Logger.WriteInfo(" If using the GUI, try opening a TMX file now");
Logger.WriteInfo(" If using the command line, provide a path to a TMX file");
Logger.WriteInfo(" If using from Tiled Map Editor, try adding %mapfile to the command");
}
else
{
Expand Down Expand Up @@ -139,32 +140,32 @@ private bool ParseOptions(string[] args)

private static void PrintHelp(NDesk.Options.OptionSet options)
{
Logger.WriteLine("{0} Utility, Version: {1}", Tiled2Unity.Info.GetLibraryName(), Tiled2Unity.Info.GetVersion());
Logger.WriteLine("Usage: {0} [OPTIONS]+ TMXPATH [UNITYDIR]", Tiled2Unity.Info.GetLibraryName());
Logger.WriteLine("Example: {0} -s=0.01 MyTiledMap.tmx ../../MyUnityProjectFolder/Assets/Tiled2Unity", Tiled2Unity.Info.GetLibraryName());
Logger.WriteLine("");
Logger.WriteLine("Options:");
Logger.WriteInfo("{0} Utility, Version: {1}", Tiled2Unity.Info.GetLibraryName(), Tiled2Unity.Info.GetVersion());
Logger.WriteInfo("Usage: {0} [OPTIONS]+ TMXPATH [UNITYDIR]", Tiled2Unity.Info.GetLibraryName());
Logger.WriteInfo("Example: {0} -s=0.01 MyTiledMap.tmx ../../MyUnityProjectFolder/Assets/Tiled2Unity", Tiled2Unity.Info.GetLibraryName());
Logger.WriteInfo("");
Logger.WriteInfo("Options:");

TextWriter writer = new StringWriter();
options.WriteOptionDescriptions(writer);
Logger.WriteLine(writer.ToString());

Logger.WriteLine("Prefab object properties (set in TMX file for map or Tile/Object layer properties)");
Logger.WriteLine(" unity:sortingLayerName");
Logger.WriteLine(" unity:sortingOrder");
Logger.WriteLine(" unity:layer");
Logger.WriteLine(" unity:tag");
Logger.WriteLine(" unity:scale");
Logger.WriteLine(" unity:isTrigger");
Logger.WriteLine(" unity:convex");
Logger.WriteLine(" unity:ignore (value = [false|true|collision|visual])");
Logger.WriteLine(" unity:resource (value = [false|true])");
Logger.WriteLine(" unity:resourcePath");
Logger.WriteLine(" unity:namePrefix (Add to tileset properties to prefix material names with this string.");
Logger.WriteLine(" unity:namePostfix (Add to tileset properties to postfix material names with this string.");
Logger.WriteLine(" (Other properties are exported for custom scripting in your Unity project)");
Logger.WriteLine("Support Tiled Map Editor on Patreon: https://www.patreon.com/bjorn");
Logger.WriteLine("Make a donation for Tiled2Unity: http://www.seanba.com/donate");
Logger.WriteInfo(writer.ToString());

Logger.WriteInfo("Prefab object properties (set in TMX file for map or Tile/Object layer properties)");
Logger.WriteInfo(" unity:sortingLayerName");
Logger.WriteInfo(" unity:sortingOrder");
Logger.WriteInfo(" unity:layer");
Logger.WriteInfo(" unity:tag");
Logger.WriteInfo(" unity:scale");
Logger.WriteInfo(" unity:isTrigger");
Logger.WriteInfo(" unity:convex");
Logger.WriteInfo(" unity:ignore (value = [false|true|collision|visual])");
Logger.WriteInfo(" unity:resource (value = [false|true])");
Logger.WriteInfo(" unity:resourcePath");
Logger.WriteInfo(" unity:namePrefix (Add to tileset properties to prefix material names with this string.");
Logger.WriteInfo(" unity:namePostfix (Add to tileset properties to postfix material names with this string.");
Logger.WriteInfo(" (Other properties are exported for custom scripting in your Unity project)");
Logger.WriteInfo("Support Tiled Map Editor on Patreon: https://www.patreon.com/bjorn");
Logger.WriteInfo("Make a donation for Tiled2Unity: http://www.seanba.com/donate");
}

// Removes unwanted cruft from arguments
Expand Down
16 changes: 13 additions & 3 deletions tool/Tiled2Unity/Tiled2UnityLib/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void SetCulture()

public bool InitializeWithArgs(string[] args, bool summary)
{
Logger.WriteLine("Command: {0}", String.Join(" ", args));
Logger.WriteInfo("Command: {0}", String.Join(" ", args));

// Create our map instance (which is empty/unloaded at first)
this.TmxMap = new TmxMap();
Expand All @@ -39,7 +39,17 @@ public bool InitializeWithArgs(string[] args, bool summary)
}

ParseEnvironmentVariables();
bool success = ParseOptions(args);
bool success = false;

try
{
success = ParseOptions(args);
}
catch (Exception e)
{
Logger.WriteError("Error parsing arguments. Exception: {0}", e.Message);
success = false;
}

if (summary)
{
Expand Down Expand Up @@ -110,7 +120,7 @@ public void ExportTmxMap()
{
try
{
Logger.WriteLine("Exporting '{0}' to '{1}'", this.TmxFilePath, this.UnityExportFolderPath);
Logger.WriteInfo("Exporting '{0}' to '{1}'", this.TmxFilePath, this.UnityExportFolderPath);
TiledMapExporter exporter = new TiledMapExporter(this.TmxMap);
exporter.Export(this.UnityExportFolderPath);
}
Expand Down
2 changes: 2 additions & 0 deletions tool/Tiled2Unity/Tiled2UnityLib/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class Settings
// If we're automatically opening, exporting, and closing then there are some code paths we don't want to take
public static bool IsAutoExporting = false;

public static bool Verbose = false;

// Some old operating systems (like Windows 7) are incompatible with the Skia library and throw exceptions
// We want to try to handle those execptions and disable previewing when that happens
public static event EventHandler PreviewingDisabled;
Expand Down
10 changes: 5 additions & 5 deletions tool/Tiled2Unity/Tiled2UnityLib/SummaryReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,31 @@ public void Report()

// Write out the summary report
string separator = new string('-', 80);
Logger.WriteLine(separator);
Logger.WriteInfo(separator);
func("{0} summary", this.name);

// Add successes
Logger.WriteLine("Succeeded: {0}", this.successes.Count);
Logger.WriteInfo("Succeeded: {0}", this.successes.Count);
foreach (var success in this.successes)
{
Logger.WriteSuccess(" {0}", success);
}

// Add warnings
Logger.WriteLine("Warnings: {0}", this.warnings.Count);
Logger.WriteInfo("Warnings: {0}", this.warnings.Count);
foreach (var warn in this.warnings)
{
Logger.WriteWarning(" {0}", warn);
}

// Add errors
Logger.WriteLine("Errors: {0}", this.errors.Count);
Logger.WriteInfo("Errors: {0}", this.errors.Count);
foreach (var error in this.errors)
{
Logger.WriteError(" {0}", error);
}

Logger.WriteLine(separator);
Logger.WriteInfo(separator);
}

private void Listen()
Expand Down
Loading

0 comments on commit f493dee

Please sign in to comment.