├── doc
├── img
│ ├── batman-seams.png
│ ├── help-import.png
│ ├── unity-import.png
│ ├── mega-dad-stand.png
│ ├── rygar-tileset.png
│ ├── rygar-tile-16x16.png
│ ├── rygar-tile-18x18.png
│ ├── rygar-with-seams.gif
│ ├── tiled-command-mac.png
│ ├── rygar-tileset-seams.png
│ ├── rygar-without-seams.gif
│ ├── tiled-edit-commands.png
│ ├── tiled2unity-windows.png
│ ├── tiled-command-windows.png
│ ├── tiled-postprefix-props.png
│ ├── tiled-tileset-spacing.png
│ ├── t2u-preview-mother-brain.png
│ ├── unity-disable-antialiasing.png
│ └── unity-warning-antialiasing.png
├── index.md
├── prepostfix.md
└── getting-started.md
├── tool
└── Tiled2Unity
│ ├── icons
│ ├── icon_16x16.png
│ ├── icon_32x32.png
│ ├── icon_128x128.ico
│ ├── icon_128x128.png
│ ├── icon_256x256.png
│ ├── icon_512x512.png
│ ├── icon_128x128@2x.png
│ ├── icon_16x16@2x.png
│ ├── icon_256x256@2x.png
│ ├── icon_32x32@2x.png
│ └── icon_512x512@2x.png
│ ├── src
│ ├── icon_128x128.ico
│ ├── t2u-icon-bw.ico
│ ├── Resources
│ │ ├── mega-dad-stand.png
│ │ ├── LaunchTip.rtf
│ │ ├── TiledOnPatreon.rtf
│ │ └── About.rtf
│ ├── packages.config
│ ├── SupportTiledForm.cs
│ ├── Program.cs
│ ├── ThirdParty
│ │ └── NDesk
│ │ │ └── License.txt
│ ├── Tiled2UnityAbout.cs
│ ├── Properties
│ │ ├── Settings.settings
│ │ ├── AssemblyInfo.cs
│ │ └── Resources.Designer.cs
│ ├── License.rtf
│ └── app.config
│ ├── TestData
│ ├── mini-tiles.png
│ ├── hex-flat-60x39.png
│ ├── hex-pointy-60x52.png
│ ├── iso-64x64-outside.png
│ ├── license.txt
│ ├── hex-pointy.tmx
│ ├── hex-flat.tmx
│ ├── mini-tiles.tsx
│ └── mini-tiles-collision.tsx
│ ├── Tiled2UnityMac
│ ├── Tiled2UnityMac
│ │ ├── Resources
│ │ │ ├── Tiled2Unity.unitypackage
│ │ │ ├── Images.xcassets
│ │ │ │ └── AppIcons.appiconset
│ │ │ │ │ ├── AppIcon-16.png
│ │ │ │ │ ├── AppIcon-32.png
│ │ │ │ │ ├── icon_16x16.png
│ │ │ │ │ ├── icon_32x32.png
│ │ │ │ │ ├── AppIcon-128.png
│ │ │ │ │ ├── AppIcon-256.png
│ │ │ │ │ ├── AppIcon-512.png
│ │ │ │ │ ├── icon_128x128.png
│ │ │ │ │ ├── icon_256x256.png
│ │ │ │ │ ├── icon_512x512.png
│ │ │ │ │ ├── AppIcon-128@2x.png
│ │ │ │ │ ├── AppIcon-16@2x.png
│ │ │ │ │ ├── AppIcon-256@2x.png
│ │ │ │ │ ├── AppIcon-32@2x.png
│ │ │ │ │ ├── AppIcon-512@2x.png
│ │ │ │ │ ├── icon_128x128@2x.png
│ │ │ │ │ ├── icon_16x16@2x.png
│ │ │ │ │ ├── icon_256x256@2x.png
│ │ │ │ │ ├── icon_32x32@2x.png
│ │ │ │ │ └── icon_512x512@2x.png
│ │ │ └── LaunchTipMac.rtf
│ │ ├── packages.config
│ │ ├── Tiled2UnityWindowController.designer.cs
│ │ ├── Tiled2UnityWindowController.cs
│ │ ├── Info.plist
│ │ ├── AppDelegate.cs
│ │ ├── Main.cs
│ │ └── ViewController.designer.cs
│ ├── Info.plist
│ ├── build
│ │ ├── build.sh
│ │ └── replace-unitypackage.rb
│ └── Tiled2UnityMac.sln
│ ├── Tiled2UnityLib
│ ├── packages.config
│ ├── TmxClasses
│ │ ├── TmxHasProperties.cs
│ │ ├── TmxHasPoints.cs
│ │ ├── TmxPropertyType.cs
│ │ ├── TmxProperty.cs
│ │ ├── TmxImage.cs
│ │ ├── ITmxVisitor.cs
│ │ ├── TmxFrame.cs
│ │ ├── TmxObjectRectangle.cs
│ │ ├── TmxException.cs
│ │ ├── TmxObjectEllipse.cs
│ │ ├── TmxObjectType.cs
│ │ ├── TmxGroupLayer.cs
│ │ ├── TmxObjectGroup.Xml.cs
│ │ ├── TmxAnimation.cs
│ │ ├── TmxProperties.Xml.cs
│ │ ├── TmxObjectTypeProperty.cs
│ │ ├── TmxObjectGroup.cs
│ │ ├── TmxObjectTypes.cs
│ │ ├── TmxDisplayOrderVisitor.cs
│ │ ├── TmxTile.cs
│ │ ├── TmxRotationMatrix.cs
│ │ ├── TmxLayer.cs
│ │ ├── TmxObjectPolyline.cs
│ │ ├── TmxProperties.cs
│ │ ├── TmxObject.cs
│ │ ├── TmxObject.Xml.cs
│ │ ├── TmxLayerNode.Xml.cs
│ │ ├── TmxTile.Xml.cs
│ │ ├── TmxObjectPolygon.cs
│ │ ├── TmxLayerNode.cs
│ │ └── TmxObjectTile.cs
│ ├── Geometry
│ │ ├── Math.cs
│ │ ├── PolygonEdgeGroup.cs
│ │ ├── TriangulateClipperSolution.cs
│ │ ├── ComposeConvexPolygons.cs
│ │ └── CompositionPolygon.cs
│ ├── IGenericDatabase.cs
│ ├── GenericListDatabase.cs
│ ├── ChDir.cs
│ ├── HashIndexOf.cs
│ ├── Settings.cs
│ ├── Info.cs
│ ├── Tiled2UnityLite.Main.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ThirdParty
│ │ ├── LibTessDotNet
│ │ │ ├── LICENSE.txt
│ │ │ └── Sources
│ │ │ │ └── Dict.cs
│ │ └── Clipper
│ │ │ └── License.txt
│ ├── ExportClasses
│ │ └── TiledMapExporter.AssignMaterials.cs
│ ├── Logger.cs
│ └── SummaryReport.cs
│ ├── build
│ ├── re-export-single-map.bat
│ ├── Tiled2UnityLite-examples.bat
│ ├── re-export-megadad-maps.bat
│ ├── zip-tiled2unity.rb
│ ├── build-installer.bat
│ └── ReadMe.txt
│ └── Tiled2Unity.sln
├── unity
└── Tiled2Unity
│ ├── Meshes
│ └── _ReadMe.txt
│ ├── Materials
│ └── _ReadMe.txt
│ ├── Prefabs
│ └── _ReadMe.txt
│ ├── Scripts
│ ├── Runtime
│ │ ├── CircleObject.cs
│ │ ├── PolylineObject.cs
│ │ ├── RectangleObject.cs
│ │ ├── PolygonObject.cs
│ │ ├── TileLayer.cs
│ │ ├── ObjectLayer.cs
│ │ ├── GroupLayer.cs
│ │ ├── SortingLayerExposed.cs
│ │ ├── Layer.cs
│ │ ├── GameObjectExtensions.cs
│ │ ├── TileObject.cs
│ │ ├── TmxObject.cs
│ │ ├── GPUInstancing.cs
│ │ ├── Log.cs
│ │ ├── TileAnimator.cs
│ │ ├── SpriteDepthInMap.cs
│ │ └── TiledMap.cs
│ └── Editor
│ │ ├── CustomTiledImporterAttribute.cs
│ │ ├── SpriteDepthInMapEditor.cs
│ │ ├── ICustomTiledImporter.cs
│ │ ├── ImportTiled2Unity.Texture.cs
│ │ ├── ImportTiled2Unity.Mesh.cs
│ │ └── Tiled2UnityMenuItems.cs
│ ├── Textures
│ └── _ReadMe.txt
│ ├── Imported
│ └── _ReadMe.txt
│ ├── Tiled2Unity.export.txt
│ ├── License.txt
│ └── Shaders
│ └── shaTiledMap.shader
├── mkdocs.yml
├── README.md
├── .gitattributes
├── .gitignore
└── license.txt
/doc/img/batman-seams.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/batman-seams.png
--------------------------------------------------------------------------------
/doc/img/help-import.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/help-import.png
--------------------------------------------------------------------------------
/doc/img/unity-import.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/unity-import.png
--------------------------------------------------------------------------------
/doc/img/mega-dad-stand.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/mega-dad-stand.png
--------------------------------------------------------------------------------
/doc/img/rygar-tileset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/rygar-tileset.png
--------------------------------------------------------------------------------
/doc/img/rygar-tile-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/rygar-tile-16x16.png
--------------------------------------------------------------------------------
/doc/img/rygar-tile-18x18.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/rygar-tile-18x18.png
--------------------------------------------------------------------------------
/doc/img/rygar-with-seams.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/rygar-with-seams.gif
--------------------------------------------------------------------------------
/doc/img/tiled-command-mac.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/tiled-command-mac.png
--------------------------------------------------------------------------------
/doc/img/rygar-tileset-seams.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/rygar-tileset-seams.png
--------------------------------------------------------------------------------
/doc/img/rygar-without-seams.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/rygar-without-seams.gif
--------------------------------------------------------------------------------
/doc/img/tiled-edit-commands.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/tiled-edit-commands.png
--------------------------------------------------------------------------------
/doc/img/tiled2unity-windows.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/tiled2unity-windows.png
--------------------------------------------------------------------------------
/doc/img/tiled-command-windows.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/tiled-command-windows.png
--------------------------------------------------------------------------------
/doc/img/tiled-postprefix-props.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/tiled-postprefix-props.png
--------------------------------------------------------------------------------
/doc/img/tiled-tileset-spacing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/tiled-tileset-spacing.png
--------------------------------------------------------------------------------
/doc/img/t2u-preview-mother-brain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/t2u-preview-mother-brain.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_16x16.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_32x32.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/icon_128x128.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/src/icon_128x128.ico
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/t2u-icon-bw.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/src/t2u-icon-bw.ico
--------------------------------------------------------------------------------
/doc/img/unity-disable-antialiasing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/unity-disable-antialiasing.png
--------------------------------------------------------------------------------
/doc/img/unity-warning-antialiasing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/doc/img/unity-warning-antialiasing.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_128x128.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_128x128.ico
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_128x128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_128x128.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_256x256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_256x256.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_512x512.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/TestData/mini-tiles.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/TestData/mini-tiles.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_128x128@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_128x128@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_16x16@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_16x16@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_256x256@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_256x256@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_32x32@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_32x32@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/icons/icon_512x512@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/icons/icon_512x512@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/TestData/hex-flat-60x39.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/TestData/hex-flat-60x39.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/TestData/hex-pointy-60x52.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/TestData/hex-pointy-60x52.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/TestData/iso-64x64-outside.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/TestData/iso-64x64-outside.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/Resources/mega-dad-stand.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/src/Resources/mega-dad-stand.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Meshes/_ReadMe.txt:
--------------------------------------------------------------------------------
1 | Meshes directory
2 |
3 | Tiled2Unity scripts will create meshes here. These meshes are packed into the
4 | prefab objects that represent your Tiled Map Editor maps.
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Materials/_ReadMe.txt:
--------------------------------------------------------------------------------
1 | Material directory
2 |
3 | Tiled2Unity scripts will create materials here. These materials are referenced
4 | by the meshes that represent your Tiled Map Editor layers.
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Tiled2Unity.unitypackage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Tiled2Unity.unitypackage
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Prefabs/_ReadMe.txt:
--------------------------------------------------------------------------------
1 | Prefabs directory
2 |
3 | Tiled2Unity scripts will build prefabs here. These prefabs can be easily placed
4 | in your Unity scenes. These prefabs are the end products of Tiled2Unity
5 | exporting.
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/mkdocs.yml:
--------------------------------------------------------------------------------
1 | site_name: Tiled2Unity
2 | docs_dir: doc
3 | pages:
4 | - 'index.md'
5 | - 'Getting Started' : 'getting-started.md'
6 | - 'Fixing Seams' : 'fixing-seams.md'
7 | - 'Dealing With Texture Name Collisions' : 'prepostfix.md'
8 | theme: readthedocs
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-16.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-32.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_16x16.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_32x32.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-128.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-256.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-512.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_128x128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_128x128.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_256x256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_256x256.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_512x512.png
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/CircleObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | public class CircleObject : TmxObject
9 | {
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-128@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-128@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-16@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-16@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-256@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-256@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-32@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-32@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-512@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/AppIcon-512@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_128x128@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_128x128@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_16x16@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_16x16@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_256x256@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_256x256@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_32x32@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_32x32@2x.png
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_512x512@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seanba/Tiled2Unity/HEAD/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/Images.xcassets/AppIcons.appiconset/icon_512x512@2x.png
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/PolylineObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | public class PolylineObject : TmxObject
9 | {
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Textures/_ReadMe.txt:
--------------------------------------------------------------------------------
1 | Textures directory
2 |
3 | Tiled2Unity scripts will create textures here. In the case where Tiled tilesets
4 | already reference textures in your Unity project then the materials will use
5 | those textures instead of creating new textures here.
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/RectangleObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | public class RectangleObject : Tiled2Unity.TmxObject
9 | {
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/PolygonObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public class PolygonObject : TmxObject
11 | {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Imported/_ReadMe.txt:
--------------------------------------------------------------------------------
1 | Here is where the Tiled2Unity Utility will export *.tiled2unity.xml files to.
2 |
3 | Unity scripts in the Tiled2Unity namespace will import these files and from
4 | them create the meshes, textures, materials, and prefabs needed to place
5 | your Tiled maps in Unity scenes.
6 |
7 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/TileLayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | public class TileLayer : Tiled2Unity.Layer
9 | {
10 | // No special properties (yet) on TileLayer
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Tiled2Unity.export.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxHasProperties.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | public interface TmxHasProperties
9 | {
10 | Tiled2Unity.TmxProperties Properties { get; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/ObjectLayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public class ObjectLayer : Tiled2Unity.Layer
11 | {
12 | public Color Color;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/GroupLayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public class GroupLayer : Tiled2Unity.Layer
11 | {
12 | // No special properties on GroupLayer
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/SortingLayerExposed.cs:
--------------------------------------------------------------------------------
1 | // Code provided by: Nick Gravelyn
2 | // from: https://gist.github.com/nickgravelyn/7460288
3 |
4 | using UnityEngine;
5 |
6 | namespace Tiled2Unity
7 | {
8 | // Component does nothing; editor script does all the magic
9 | public class SortingLayerExposed : MonoBehaviour
10 | {
11 | }
12 | }
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxHasPoints.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Tiled2Unity
8 | {
9 | public interface TmxHasPoints
10 | {
11 | List Points { get; set; }
12 | bool ArePointsClosed();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxPropertyType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | public enum TmxPropertyType
9 | {
10 | String,
11 | Int,
12 | Float,
13 | Bool,
14 | Color,
15 | File,
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/Layer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | // Base class for Layer types (Tile, Object) from Tiled
11 | public abstract class Layer : MonoBehaviour
12 | {
13 | public Vector2 Offset;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxProperty.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | public class TmxProperty
9 | {
10 | public string Name { get; set; }
11 | public string Value { get; set; }
12 | public TmxPropertyType Type { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Tiled2Unity
2 |
3 | **Tiled2Unity** is made up of two parts:
4 | - The [utility](tool/Tiled2Unity) that exports TMX files into Unity.
5 | - The [Unity scripts](unity/Tiled2Unity) that import the output of the Tiled2Unity Utility.
6 |
7 | See documenation on the [Tiled2Unity ReadTheDocs page](http://tiled2unity.readthedocs.io).
8 |
9 | **Tiled2Unity** is distributed with the [MIT License](https://en.wikipedia.org/wiki/MIT_License).
10 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/Resources/LaunchTip.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}{\f1\fnil\fcharset0 Courier New;}}
2 | {\*\generator Riched20 10.0.10586}\viewkind4\uc1
3 | \pard\sl240\slmult1\b\f0\fs22\lang9 To launch from Tiled Map Editor\b0 add this command to the Edit Commands UI in Tiled\par
4 | \f1\fs20\tab "c:\\Program Files\\Tiled2Unity\\Tiled2Unity.exe" %mapfile \f0\fs22\par
5 | }
6 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Editor/CustomTiledImporterAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEditor;
7 | using UnityEngine;
8 |
9 | namespace Tiled2Unity
10 | {
11 | [AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false)]
12 | public class CustomTiledImporterAttribute : System.Attribute
13 | {
14 | public int Order { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/build/re-export-single-map.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | pushd %~dp0
3 | rem This is hardcoded to expect the Tiled2Unity test project at location ..\..\..\
4 |
5 | set TiledTmx=%1
6 | set ObjectTypeXml="..\..\..\unity\Tiled2Unity\tiled\objecttypes.xml"
7 | set Tiled2UnityDir="..\..\..\unity\Tiled2Unity\unity\Assets\Tiled2Unity"
8 |
9 |
10 | echo command: cscs Tiled2UnityLite.cs --object-type-xml=%ObjectTypeXml% %TiledTmx% %Tiled2UnityDir%
11 | cscs Tiled2UnityLite.cs --object-type-xml=%ObjectTypeXml% %TiledTmx% %Tiled2UnityDir%
12 |
13 | popd
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Resources/LaunchTipMac.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf470
2 | {\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fmodern\fcharset0 CourierNewPSMT;}
3 | {\colortbl;\red255\green255\blue255;}
4 | \margl1440\margr1440\vieww10800\viewh8400\viewkind0
5 | \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
6 |
7 | \f0\b\fs24 \cf0 To launch from Tiled Map Editor
8 | \b0 add this command to the Edit Commands UI in Tiled\
9 |
10 | \f1 open -a /Applications/Tiled2UnityMac.app --args %mapfile}
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Tiled2UnityWindowController.designer.cs:
--------------------------------------------------------------------------------
1 | // WARNING
2 | //
3 | // This file has been generated automatically by Xamarin Studio Community to store outlets and
4 | // actions made in the UI designer. If it is removed, they will be lost.
5 | // Manual changes to this file may not be handled correctly.
6 | //
7 | using Foundation;
8 | using System.CodeDom.Compiler;
9 |
10 | namespace Tiled2UnityMac
11 | {
12 | [Register ("Tiled2UnityWindowController")]
13 | partial class Tiled2UnityWindowController
14 | {
15 |
16 | void ReleaseDesignerOutlets ()
17 | {
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxImage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using SkiaSharp;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public partial class TmxImage
11 | {
12 | public string AbsolutePath { get; private set; }
13 | public Size Size { get; private set; }
14 | public String TransparentColor { get; set; }
15 | public string ImageName { get; private set; }
16 |
17 | #if !TILED_2_UNITY_LITE
18 | public SKBitmap ImageBitmap { get; private set; }
19 | #endif
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Geometry/Math.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Tiled2Unity.Geometry
9 | {
10 | class Math
11 | {
12 | // Points are ordered CCW with B as the junction
13 | public static float Cross(PointF A, PointF B, PointF C)
14 | {
15 | PointF lhs = new PointF(B.X - A.X, B.Y - A.Y);
16 | PointF rhs = new PointF(C.X - B.X, C.Y - B.Y);
17 | return (lhs.X * rhs.Y) - (lhs.Y * rhs.X);
18 | }
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/IGenericDatabase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Tiled2Unity
8 | {
9 | // This is really just a cheap interface that adds "stuff" to a container, returning an index
10 | // You can access the items (that may be unique or there may be repeats) through the List property
11 | // (We just want to be able to have unique or repeated collection of items polymorphically)
12 | interface IGenericDatabase
13 | {
14 | List List { get; }
15 | int AddToDatabase(T value);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/build/Tiled2UnityLite-examples.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | pushd %~dp0
3 | rem This is hardcoded to expect the Tiled2Unity test project at location ..\..\..\
4 |
5 | rem set ObjectTypeXml=""
6 | set ObjectTypeXml="..\..\..\unity\Tiled2Unity\tiled\objecttypes.xml"
7 | set TiledTmx="..\..\..\unity\Tiled2Unity\tiled\collision-layers\Cutman-CollisionLayers.tmx"
8 | set Tiled2UnityDir="..\..\..\unity\Tiled2Unity\unity\Assets\Tiled2Unity"
9 |
10 | cscs Tiled2UnityLite.cs --help
11 |
12 | echo Command: cscs Tiled2UnityLite.cs --object-type-xml=%ObjectTypeXml% %TiledTmx% %Tiled2UnityDir%
13 | cscs Tiled2UnityLite.cs --object-type-xml=%ObjectTypeXml% %TiledTmx% %Tiled2UnityDir%
14 |
15 | popd
--------------------------------------------------------------------------------
/tool/Tiled2Unity/TestData/license.txt:
--------------------------------------------------------------------------------
1 | Orthographic example tileset artwork is appropriated to Blarget2 (http://opengameart.org/content/minimalist-pixel-tileset) and is distributed with the Creative Commons 3.0 license.
2 | Isometric example tileset artwork is appropriated to Yar (http://opengameart.org/content/isometric-64x64-outside-tileset) and is distributed with the Creative Commons 3.0 license.
3 | Hexagonal example tileset artwork is appropriated to Steffan (http://tilemapkit.com/2015/05/create-hexagonal-tilemaps-in-tiled/)
4 |
5 | http://creativecommons.org/licenses/by/3.0/
6 |
7 | For Unity2Tiled examples, this artwork was expanded through building Tiled Map Editor files (TMX) containing the artwork.
8 |
9 |
10 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/GameObjectExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public static class GameObjectExtensions
11 | {
12 | public static T GetOrAddComponent(this GameObject gameObject) where T : UnityEngine.Component
13 | {
14 | // Get the component if it exists
15 | T component = gameObject.GetComponent();
16 | if (component != null)
17 | return component;
18 |
19 | // Add the component
20 | return gameObject.AddComponent();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/TileObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public class TileObject : Tiled2Unity.TmxObject
11 | {
12 | [Header("Tmx Tile Object Properties (Raw Data)")]
13 | public bool TmxFlippingHorizontal;
14 | public bool TmxFlippingVertical;
15 |
16 | [Header("Tile Object Properties")]
17 | [Tooltip("Imported Tile Width (after scaling and transforms applied)")]
18 | public float TileWidth = 0.0f;
19 |
20 | [Tooltip("Imported Tile Height (after scaling and transforms applied)")]
21 | public float TileHeight = 0.0f;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/GenericListDatabase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Tiled2Unity
8 | {
9 | // A simple list acting as our "database"
10 | // Similar items are found multiple times in this collection (as opposed to HashIndexOf)
11 | class GenericListDatabase : IGenericDatabase
12 | {
13 | public List List { get; private set; }
14 |
15 | public GenericListDatabase()
16 | {
17 | this.List = new List();
18 | }
19 |
20 | public int AddToDatabase(T value)
21 | {
22 | this.List.Add(value);
23 | return this.List.Count - 1;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/ITmxVisitor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Tiled2Unity
8 | {
9 | // The object that does the visiting implements this interface
10 | public interface ITmxVisitor
11 | {
12 | void VisitMap(TmxMap map);
13 | void VisitGroupLayer(TmxGroupLayer groupLayer);
14 | void VisitTileLayer(TmxLayer tileLayer);
15 | void VisitObjectLayer(TmxObjectGroup groupLayer);
16 | void VisitObject(TmxObject obj);
17 | }
18 |
19 | // An object that is visited implements this interface
20 | public interface ITmxVisit
21 | {
22 | void Visit(ITmxVisitor visitor);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # =========================
18 | # Operating System Files
19 | # =========================
20 |
21 | # OSX
22 | # =========================
23 |
24 | .DS_Store
25 | .AppleDouble
26 | .LSOverride
27 |
28 | # Icon must end with two \r
29 | Icon
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear on external disk
35 | .Spotlight-V100
36 | .Trashes
37 |
38 | # Directories potentially created on remote AFP share
39 | .AppleDB
40 | .AppleDesktop
41 | Network Trash Folder
42 | Temporary Items
43 | .apdisk
44 |
--------------------------------------------------------------------------------
/doc/index.md:
--------------------------------------------------------------------------------
1 | # Tiled2Unity Documentation
2 |
3 |  By [Sean Barton](http://www.seanba.com)
4 |
5 | **Tiled2Unity** is a free utlity that helps you export maps from the popular [Tiled Map Editor](http://www.mapeditor.org) to your Unity projects.
6 |
7 | * **Windows** users will want the default **Tiled2Unity** utility
8 | * For **Mac** users there a full-featured **Tiled2UnityMac** app
9 | * For **Linux** users there is a **Tiled2UnityLite** command line utility which requires [Mono](http://www.mono-project.com/download) and [CS-Script](http://www.csscript.net) to run.
10 |
11 | Tiled2Unity (and variants) are availble for download on my [game development blog](http://www.seanba.com/tiled2unity).
12 |
13 | [](http://www.seanba.com/tiled2unity)
14 |
15 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Tiled2UnityWindowController.cs:
--------------------------------------------------------------------------------
1 | // This file has been autogenerated from a class added in the UI designer.
2 |
3 | using System;
4 |
5 | using Foundation;
6 | using AppKit;
7 |
8 | namespace Tiled2UnityMac
9 | {
10 | public class Tiled2UnityWindowControllerDelegate : NSWindowDelegate
11 | {
12 | public override void WillClose (NSNotification notification)
13 | {
14 | NSApplication.SharedApplication.Terminate (NSApplication.SharedApplication);
15 | }
16 | }
17 |
18 | public partial class Tiled2UnityWindowController : NSWindowController
19 | {
20 | public Tiled2UnityWindowController (IntPtr handle) : base (handle)
21 | {
22 | }
23 |
24 | public override void AwakeFromNib ()
25 | {
26 | base.AwakeFromNib ();
27 |
28 | this.Window.Delegate = new Tiled2UnityWindowControllerDelegate ();
29 | }
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/build/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # All work is in *this* directory
4 | THIS_DIR=`dirname $0`
5 | pushd $THIS_DIR > /dev/null 2>&1
6 |
7 | # Make sure the right unity package is in the build
8 | ruby replace-unitypackage.rb
9 | if [ "$?" != "0" ]; then
10 | echo "Could not replace the unity package"
11 | popd > /dev/null 2<&1
12 | exit 1
13 | fi
14 |
15 | # Build the project in Release
16 | xbuild /p:Configuration=Release ../Tiled2UnityMac.sln
17 | if [ "$?" != "0" ]; then
18 | echo "Error building Tiled2UnityMac.sln"
19 | popd > /dev/null 2<&1
20 | exit 1
21 | fi
22 |
23 | # Zip it all up
24 | version=$(cat t2u_version.txt)
25 | echo version="$version"
26 |
27 | t2u="Tiled2UnityMac-"
28 | ext=".zip"
29 |
30 | zipped=$t2u$version$ext
31 | echo Zipping to $zipped
32 |
33 | pushd ../Tiled2UnityMac/bin/Release
34 | zip -r ../../../build/$zipped Tiled2UnityMac.app
35 | popd
36 |
37 | # Done. Pop the directory.
38 | popd > /dev/null 2<&1
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/Resources/TiledOnPatreon.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}}
2 | {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\nowidctlpar\sl276\slmult1\lang9\b\f0\fs28 Help Bj\'f8rn make Tiled even better!\par
3 | \par
4 | \b0\fs22 As a fan of old-school 2D games I'm enthusiastic about people \i just like you\i0 making the kind of games that are largely ignored by AAA publishers.\par
5 | \par
6 | That is why I made \b Tiled2Unity\b0 free for everyone to use, with source.\par
7 | \par
8 | But I couldn't make Tiled2Unity without there first being the \b Tiled Map Editor\b0 -- which is why I ask you to join me in supporting the author of Tiled on Patreon.\par
9 | \par
10 | Even a couple of bucks a month is a big help towards his goal of making us more and better tools. \b Please consider giving.\par
11 | \b0\par
12 | Best wishes,\par
13 | Sean Barton (aka Seanba)\fs20\par
14 | }
15 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/build/re-export-megadad-maps.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | pushd %~dp0
3 |
4 | call re-export-single-map.bat "..\..\..\unity\Tiled2Unity\tiled\animation\FlashmanLair.tmx"
5 | call re-export-single-map.bat "..\..\..\unity\Tiled2Unity\tiled\collision-layers\Cutman-CollisionLayers.tmx"
6 | call re-export-single-map.bat "..\..\..\unity\Tiled2Unity\tiled\collision-layers\Cutman-ObjectTypes.tmx"
7 | call re-export-single-map.bat "..\..\..\unity\Tiled2Unity\tiled\custom\HeatManBlocks.tmx"
8 | call re-export-single-map.bat "..\..\..\unity\Tiled2Unity\tiled\ladder\CutMan-WithLadders.tmx"
9 | call re-export-single-map.bat "..\..\..\unity\Tiled2Unity\tiled\simple\MagmaManLair-NoCollision.tmx"
10 | call re-export-single-map.bat "..\..\..\unity\Tiled2Unity\tiled\simple\MagmaManLair-WithCollision.tmx"
11 | call re-export-single-map.bat "..\..\..\unity\Tiled2Unity\tiled\slopes\RedDragon-WithSlopes.tmx"
12 | call re-export-single-map.bat "..\..\..\unity\Tiled2Unity\tiled\water\DiveMan-water.tmx"
13 |
14 | popd
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Editor/SpriteDepthInMapEditor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEditor;
7 | using UnityEngine;
8 |
9 | namespace Tiled2Unity
10 | {
11 | [CustomEditor(typeof(SpriteDepthInMap))]
12 | public class SpriteDepthInMapEditor : UnityEditor.Editor
13 | {
14 | public override void OnInspectorGUI()
15 | {
16 | DrawDefaultInspector();
17 |
18 | SpriteDepthInMap depthSprite = (SpriteDepthInMap)target;
19 | if (GUILayout.Button("Set Depth (Changes Transform Z Position)"))
20 | {
21 | if (depthSprite.AttachedMap == null)
22 | {
23 | Debug.LogError("Cannot set sprite depth without an Attached Map");
24 | }
25 | else
26 | {
27 | depthSprite.UpdateSpriteDepth();
28 | }
29 | }
30 | }
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/TestData/hex-pointy.tmx:
--------------------------------------------------------------------------------
1 |
2 |
30 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/TmxObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | // Represents an object within an Object Layer. Contains common object data as it is represented in the TMX file (before scaling and other transformations are applied).
11 | public class TmxObject : MonoBehaviour
12 | {
13 | [Header("Tmx Object Properties (Raw Data)")]
14 |
15 | [Tooltip("Id of object in Tiled TMX file")]
16 | public int TmxId;
17 |
18 | [Tooltip("Name of object in Tiled TMX file")]
19 | public string TmxName;
20 |
21 | [Tooltip("Type of object in Tiled TMX file")]
22 | public string TmxType;
23 |
24 | [Tooltip("Position of object in Tiled TMX file")]
25 | public Vector2 TmxPosition;
26 |
27 | [Tooltip("Size of object in Tiled TMX file")]
28 | public Vector2 TmxSize;
29 |
30 | [Tooltip("Rotation of object in Tiled TMX file")]
31 | public float TmxRotation;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | Tiled2Unity
2 | Copyright (C) 2016 Sean Barton (http://www.seanba.com)
3 |
4 | MIT License
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/SupportTiledForm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Reflection;
9 | using System.Text;
10 | using System.Windows.Forms;
11 |
12 | namespace Tiled2Unity
13 | {
14 | public partial class SupportTiledForm : Form
15 | {
16 | public SupportTiledForm()
17 | {
18 | InitializeComponent();
19 | LoadSupportText();
20 | }
21 |
22 | private void LoadSupportText()
23 | {
24 | using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Tiled2Unity.Resources.TiledOnPatreon.rtf"))
25 | {
26 | this.pleaRichTextBox.LoadFile(stream, RichTextBoxStreamType.RichText);
27 | }
28 | }
29 |
30 | private void patreonLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
31 | {
32 | System.Diagnostics.Process.Start(this.patreonLinkLabel.Text);
33 | }
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxFrame.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Xml;
6 | using System.Xml.Linq;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public partial class TmxFrame
11 | {
12 | public uint GlobalTileId { get; private set; }
13 | public int DurationMs { get; private set; }
14 |
15 | public static TmxFrame FromTileId(uint tileId)
16 | {
17 | TmxFrame tmxFrame = new TmxFrame();
18 | tmxFrame.GlobalTileId = tileId;
19 | tmxFrame.DurationMs = 0;
20 |
21 | return tmxFrame;
22 | }
23 |
24 | public static TmxFrame FromXml(XElement xml, uint globalStartId)
25 | {
26 | TmxFrame tmxFrame = new TmxFrame();
27 |
28 | uint localTileId = TmxHelper.GetAttributeAsUInt(xml, "tileid");
29 | tmxFrame.GlobalTileId = localTileId + globalStartId;
30 | tmxFrame.DurationMs = TmxHelper.GetAttributeAsInt(xml, "duration", 100);
31 |
32 | return tmxFrame;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectRectangle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Tiled2Unity
8 | {
9 | public class TmxObjectRectangle : TmxObjectPolygon
10 | {
11 | protected override void InternalFromXml(System.Xml.Linq.XElement xml, TmxMap tmxMap)
12 | {
13 | this.Points = new List();
14 | this.Points.Add(new PointF(0, 0));
15 | this.Points.Add(new PointF(this.Size.Width, 0));
16 | this.Points.Add(new PointF(this.Size.Width, this.Size.Height));
17 | this.Points.Add(new PointF(0, this.Size.Height));
18 |
19 | if (this.Size.Width == 0 || this.Size.Height == 0)
20 | {
21 | Logger.WriteWarning("Warning: Rectangle has zero width or height in object group\n{0}", xml.Parent.ToString());
22 | }
23 | }
24 |
25 | protected override string InternalGetDefaultName()
26 | {
27 | return "RectangleObject";
28 | }
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Reflection;
7 | using System.Windows.Forms;
8 |
9 |
10 | namespace Tiled2Unity
11 | {
12 | static class Program
13 | {
14 | [STAThread]
15 | static int Main(string[] args)
16 | {
17 | bool isAuto = false;
18 | NDesk.Options.OptionSet options = new NDesk.Options.OptionSet()
19 | {
20 | { "a|auto-export", "Automatic export", a => isAuto = true }
21 | };
22 |
23 | options.Parse(args);
24 | if (isAuto)
25 | {
26 | return Tiled2UnityLite.Run(args);
27 | }
28 |
29 | Application.EnableVisualStyles();
30 | Application.SetCompatibleTextRenderingDefault(false);
31 | using (Tiled2UnityForm form = new Tiled2UnityForm())
32 | {
33 | Application.Run(form);
34 | }
35 |
36 | return 0;
37 | }
38 |
39 | } // end class
40 | } // end namespace
41 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/TestData/hex-flat.tmx:
--------------------------------------------------------------------------------
1 |
2 |
29 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/ChDir.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Tiled2Unity
8 | {
9 | public class ChDir : IDisposable
10 | {
11 | private string directoryOld = "";
12 | private string directoryNow = "";
13 |
14 | public ChDir(string path)
15 | {
16 | this.directoryOld = Directory.GetCurrentDirectory();
17 | if (Directory.Exists(path))
18 | {
19 | this.directoryNow = path;
20 | }
21 | else if (File.Exists(path))
22 | {
23 | this.directoryNow = Path.GetDirectoryName(path);
24 | }
25 | else
26 | {
27 | throw new DirectoryNotFoundException(String.Format("Cannot set current directory. Does not exist: {0}", path));
28 | }
29 |
30 | Directory.SetCurrentDirectory(this.directoryNow);
31 | }
32 |
33 | public void Dispose()
34 | {
35 | Directory.SetCurrentDirectory(this.directoryOld);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleName
6 | Tiled2UnityMac
7 | CFBundleIdentifier
8 | com.seanba.tiled2unitymac
9 | CFBundleVersion
10 | 1
11 | LSMinimumSystemVersion
12 | 10.10
13 | CFBundleDevelopmentRegion
14 | en
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundlePackageType
18 | APPL
19 | CFBundleSignature
20 | ????
21 | NSHumanReadableCopyright
22 | seanba
23 | NSPrincipalClass
24 | NSApplication
25 | NSMainStoryboardFile
26 | Main
27 | CFBundleShortVersionString
28 | 1.0.12.3
29 | XSAppIconAssets
30 | Resources/Images.xcassets/AppIcons.appiconset
31 |
32 |
33 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/GPUInstancing.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | [ExecuteInEditMode]
11 | public class GPUInstancing : MonoBehaviour
12 | {
13 | [Range(0, 1)]
14 | public float Opacity = 1.0f;
15 |
16 | private void Awake()
17 | {
18 | SetPropertyBlock();
19 | }
20 |
21 | private void OnValidate()
22 | {
23 | SetPropertyBlock();
24 | }
25 |
26 | private void SetPropertyBlock()
27 | {
28 | // Allows us to share a material with different opacity settings
29 | #if UNITY_5_6_OR_NEWER
30 | MeshRenderer meshRenderer = this.gameObject.GetComponent();
31 | if (meshRenderer != null)
32 | {
33 | MaterialPropertyBlock props = new MaterialPropertyBlock();
34 | props.SetColor("_Color", new Color(1, 1, 1, this.Opacity));
35 | meshRenderer.SetPropertyBlock(props);
36 | }
37 | #endif
38 | }
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Xml;
6 | using System.Xml.Linq;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public class TmxException : Exception
11 | {
12 | public TmxException(string message)
13 | : base(message)
14 | {
15 | }
16 |
17 | public TmxException(string message, Exception inner)
18 | : base(message, inner)
19 | {
20 | }
21 |
22 | public static void ThrowFormat(string fmt, params object[] args)
23 | {
24 | string msg = String.Format(fmt, args);
25 | throw new TmxException(msg);
26 | }
27 |
28 | public static void FromAttributeException(Exception inner, XElement element)
29 | {
30 | StringBuilder builder = new StringBuilder(inner.Message);
31 | Array.ForEach(element.Attributes().ToArray(), a => builder.AppendFormat("\n {0}", a.ToString()));
32 | TmxException.ThrowFormat("Error parsing {0} attributes\n{1}", element.Name, builder.ToString());
33 | }
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectEllipse.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Tiled2Unity
8 | {
9 | public class TmxObjectEllipse : TmxObject
10 | {
11 | public bool IsCircle()
12 | {
13 | return (this.Size.Width == this.Size.Height);
14 | }
15 |
16 | public float Radius
17 | {
18 | get
19 | {
20 | Debug.Assert(IsCircle());
21 | return this.Size.Width * 0.5f;
22 | }
23 | }
24 |
25 | public override System.Drawing.RectangleF GetWorldBounds()
26 | {
27 | return new System.Drawing.RectangleF(this.Position, this.Size);
28 | }
29 |
30 | protected override void InternalFromXml(System.Xml.Linq.XElement xml, TmxMap tmxMap)
31 | {
32 | // No extra data for ellipses
33 | }
34 |
35 | protected override string InternalGetDefaultName()
36 | {
37 | if (IsCircle())
38 | return "CircleObject";
39 | return "EllipseObject";
40 | }
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/License.txt:
--------------------------------------------------------------------------------
1 | Tiled2Unity
2 | Copyright (C) 2014 Sean Barton (http://www.seanba.com)
3 |
4 |
5 |
6 | MIT License
7 |
8 |
9 |
10 | Permission is hereby granted, free of charge, to any person obtaining
11 | a copy of this software and associated documentation files (the
12 | "Software"), to deal in the Software without restriction, including
13 | without limitation the rights to use, copy, modify, merge, publish,
14 | distribute, sublicense, and/or sell copies of the Software, and to
15 | permit persons to whom the Software is furnished to do so, subject to
16 | the following conditions:
17 |
18 | The above copyright notice and this permission notice shall be
19 | included in all copies or substantial portions of the Software.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/ThirdParty/NDesk/License.txt:
--------------------------------------------------------------------------------
1 | Authors:
2 | Jonathan Pryor
3 |
4 | Copyright (C) 2008 Novell (http://www.novell.com)
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining
7 | a copy of this software and associated documentation files (the
8 | "Software"), to deal in the Software without restriction, including
9 | without limitation the rights to use, copy, modify, merge, publish,
10 | distribute, sublicense, and/or sell copies of the Software, and to
11 | permit persons to whom the Software is furnished to do so, subject to
12 | the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be
15 | included in all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using AppKit;
2 | using Foundation;
3 |
4 | using System;
5 |
6 | namespace Tiled2UnityMac
7 | {
8 | [Register ("AppDelegate")]
9 | public class AppDelegate : NSApplicationDelegate
10 | {
11 | public AppDelegate ()
12 | {
13 | }
14 |
15 | public override void DidFinishLaunching (NSNotification notification)
16 | {
17 | // Insert code here to initialize your application
18 | }
19 |
20 | public override void WillTerminate (NSNotification notification)
21 | {
22 | // Insert code here to tear down your application
23 | }
24 |
25 | /* Having this code here attempts to open a file for each command line argument given
26 | public override bool OpenFile (NSApplication sender, string filename)
27 | {
28 | // Trap all errors
29 | try {
30 | filename = filename.Replace (" ", "%20");
31 | return OpenFile(filename);
32 | } catch {
33 | return false;
34 | }
35 | }
36 |
37 | public bool OpenFile (string tmxPath)
38 | {
39 | Tiled2UnityMac.ViewController controller = NSApplication.SharedApplication.MainWindow.ContentViewController as Tiled2UnityMac.ViewController;
40 | return controller.OpenTmxFile(tmxPath);
41 | }*/
42 |
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Xml.Linq;
7 |
8 | namespace Tiled2Unity
9 | {
10 | // Has data for a single object type
11 | public class TmxObjectType
12 | {
13 | public string Name { get; private set; }
14 | public Color Color { get; private set; }
15 | public Dictionary Properties { get; private set; }
16 |
17 | public TmxObjectType()
18 | {
19 | this.Name = "";
20 | this.Color = Color.FromArgb(128, 128, 128);
21 | this.Properties = new Dictionary();
22 | }
23 |
24 | public static TmxObjectType FromXml(XElement xml)
25 | {
26 | TmxObjectType tmxObjectType = new TmxObjectType();
27 |
28 | tmxObjectType.Name = TmxHelper.GetAttributeAsString(xml, "name", "");
29 | tmxObjectType.Color = TmxHelper.GetAttributeAsColor(xml, "color", Color.FromArgb(128, 128, 128));
30 | tmxObjectType.Properties = TmxObjectTypeProperty.FromObjectTypeXml(xml);
31 |
32 | return tmxObjectType;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/HashIndexOf.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | // Generic collection class that gives us O(1) insertion with distinct values and O(1) IndexOf
9 | public class HashIndexOf : IGenericDatabase
10 | {
11 | private Dictionary dictionary = new Dictionary();
12 |
13 | public List List { get; private set; }
14 |
15 | public HashIndexOf()
16 | {
17 | this.List = new List();
18 | }
19 |
20 | public int Add(T value)
21 | {
22 | if (this.dictionary.ContainsKey(value))
23 | {
24 | return this.dictionary[value];
25 | }
26 | else
27 | {
28 | int index = this.dictionary.Count;
29 | this.List.Add(value);
30 | this.dictionary[value] = index;
31 | return index;
32 | }
33 | }
34 |
35 | public int IndexOf(T value)
36 | {
37 | return this.dictionary[value];
38 | }
39 |
40 | public int AddToDatabase(T value)
41 | {
42 | return Add(value);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxGroupLayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using System.Xml.Linq;
9 |
10 | namespace Tiled2Unity
11 | {
12 | // A group layer is a composite of other layer types (i.e. tiled, object, other groups)
13 | public class TmxGroupLayer : TmxLayerNode
14 | {
15 | public TmxGroupLayer(TmxLayerNode parent, TmxMap tmxMap) : base(parent, tmxMap)
16 | {
17 | }
18 |
19 | public override void Visit(ITmxVisitor visitor)
20 | {
21 | // Visit ourselves
22 | visitor.VisitGroupLayer(this);
23 |
24 | // Visit our children
25 | foreach (var node in this.LayerNodes)
26 | {
27 | node.Visit(visitor);
28 | }
29 | }
30 |
31 | public static TmxGroupLayer FromXml(XElement xml, TmxLayerNode parent, TmxMap tmxMap)
32 | {
33 | Debug.Assert(xml.Name == "group");
34 |
35 | TmxGroupLayer tmxGroupLayer = new TmxGroupLayer(parent, tmxMap);
36 | tmxGroupLayer.FromXmlInternal(xml);
37 | return tmxGroupLayer;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/Log.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | // Helper class to write to Editor.log file
11 | public static class Log
12 | {
13 | private static readonly bool Enabled = true;
14 |
15 | public static void Report(string msg)
16 | {
17 | if (Enabled)
18 | {
19 | System.Console.WriteLine(msg);
20 | }
21 | }
22 |
23 | public static void Report(string fmt, params object[] args)
24 | {
25 | string msg = String.Format(fmt, args);
26 | Report(msg);
27 | }
28 | }
29 |
30 | public class Logger : IDisposable
31 | {
32 | private readonly string message;
33 |
34 | public Logger(string fmt, params object[] args) : this(String.Format(fmt, args))
35 | {
36 | }
37 |
38 | public Logger(string message)
39 | {
40 | this.message = message;
41 | Log.Report("[Tiled2Unity]Begin: {0}", this.message);
42 | }
43 |
44 | public void Dispose()
45 | {
46 | Log.Report("[Tiled2Unity]End: {0}", this.message);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/doc/prepostfix.md:
--------------------------------------------------------------------------------
1 | # Dealing with Texture Name Collisions
2 |
3 | **Note:** This feature was added with Tiled2Unity 1.0.11.0
4 |
5 | It is always a good idea to give all your resources (textures, map files, etc.) a unique name. This will ensure Tiled2Unity cleanly imports your Tiled Map Editor maps into a funtional prefab when exported.
6 |
7 | One common problem occurs when you have *different* textures that share the *same* filename. By default, Tiled2Unity will export those textures over each other leading to some visual bugs.
8 |
9 | To fix this problem you can use one (or both) of the following custom properties on your tileset:
10 |
11 | * `unity:namePrefix`
12 | * `unity:namePostfix`
13 |
14 | **As an example:** Say you have multiple tilesets that both reference different textures that share the same `blocks.png` filename. In Tiled edit the tileset with custom properties like so:
15 |
16 | 
17 |
18 | Now, when a map using this tileset is exported the texture will be exported as `MyPrefix-blocks-MyPostfix.png` instead of `blocks.png`. Similarly, the material asset created will be named `MyPrefix-blocks-MyPostfix.mat`.
19 |
20 | **Note:** Normally you wouldn't use *both* a prefix and postfix. All that matters is that the resulting texture and material assets in your Unity project are uniquely named once importing is completed.
21 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/Tiled2UnityAbout.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Reflection;
9 | using System.Runtime.InteropServices;
10 | using System.Text;
11 | using System.Windows.Forms;
12 |
13 | namespace Tiled2Unity
14 | {
15 | public partial class Tiled2UnityAbout : Form
16 | {
17 | public Tiled2UnityAbout()
18 | {
19 | InitializeComponent();
20 | this.labelVersion.Text = String.Format("Tiled2Unity, {0} ({1})", Tiled2Unity.Info.GetVersion(), Tiled2Unity.Info.GetPlatform());
21 | LoadAboutText();
22 | }
23 |
24 | private void LoadAboutText()
25 | {
26 | using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Tiled2Unity.Resources.About.rtf"))
27 | {
28 | this.richTextBoxAbout.LoadFile(stream, RichTextBoxStreamType.RichText);
29 | }
30 | }
31 |
32 | private void buttonOkay_Click(object sender, EventArgs e)
33 | {
34 | Close();
35 | }
36 |
37 | private void richTextBoxAbout_LinkClicked(object sender, LinkClickedEventArgs e)
38 | {
39 | System.Diagnostics.Process.Start(e.LinkText);
40 | }
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectGroup.Xml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Xml;
8 | using System.Xml.Linq;
9 |
10 | namespace Tiled2Unity
11 | {
12 | public partial class TmxObjectGroup
13 | {
14 | public static TmxObjectGroup FromXml(XElement xml, TmxLayerNode parent, TmxMap tmxMap)
15 | {
16 | Debug.Assert(xml.Name == "objectgroup");
17 |
18 | TmxObjectGroup tmxObjectGroup = new TmxObjectGroup(parent, tmxMap);
19 | tmxObjectGroup.FromXmlInternal(xml);
20 |
21 | // Color is specific to object group
22 | tmxObjectGroup.Color = TmxHelper.GetAttributeAsColor(xml, "color", Color.FromArgb(128, 128, 128));
23 |
24 | // Get all the objects
25 | Logger.WriteVerbose("Parsing objects in object group '{0}'", tmxObjectGroup.Name);
26 | var objects = from obj in xml.Elements("object")
27 | select TmxObject.FromXml(obj, tmxObjectGroup, tmxMap);
28 |
29 | // The objects are ordered "visually" by Y position
30 | tmxObjectGroup.Objects = objects.OrderBy(o => TmxMath.ObjectPointFToMapSpace(tmxMap, o.Position).Y).ToList();
31 |
32 | return tmxObjectGroup;
33 | }
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Settings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | // Setttings for compiling and export Tiled maps into Unity
9 | public class Settings
10 | {
11 | public static string ObjectTypeXml = "";
12 |
13 | public static float Scale = 1.0f;
14 | public static bool PreferConvexPolygons = false;
15 | public static bool DepthBufferEnabled = false;
16 |
17 | public static readonly float DefaultTexelBias = 0.0f;
18 | public static float TexelBias = DefaultTexelBias;
19 |
20 | // If we're automatically opening, exporting, and closing then there are some code paths we don't want to take
21 | public static bool IsAutoExporting = false;
22 |
23 | public static bool Verbose = false;
24 |
25 | // Some old operating systems (like Windows 7) are incompatible with the Skia library and throw exceptions
26 | // We want to try to handle those execptions and disable previewing when that happens
27 | public static event EventHandler PreviewingDisabled;
28 |
29 | public static void DisablePreviewing()
30 | {
31 | if (PreviewingDisabled != null)
32 | {
33 | PreviewingDisabled.Invoke(null, EventArgs.Empty);
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Editor/ICustomTiledImporter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public interface ICustomTiledImporter
11 | {
12 | // A game object within the prefab has some custom properites assigned through Tiled that are not consumed by Tiled2Unity
13 | // This callback gives customized importers a chance to react to such properites.
14 | void HandleCustomProperties(GameObject gameObject, IDictionary customProperties);
15 |
16 | // Called just before the prefab is saved to the asset database
17 | // A last chance opporunity to modify it through script
18 | void CustomizePrefab(GameObject prefab);
19 | }
20 | }
21 |
22 | // Examples
23 | /*
24 | [Tiled2Unity.CustomTiledImporter]
25 | class CustomImporterAddComponent : Tiled2Unity.ICustomTiledImporter
26 | {
27 | public void HandleCustomProperties(UnityEngine.GameObject gameObject,
28 | IDictionary props)
29 | {
30 | // Simply add a component to our GameObject
31 | if (props.ContainsKey("AddComp"))
32 | {
33 | gameObject.AddComponent(props["AddComp"]);
34 | }
35 | }
36 |
37 |
38 | public void CustomizePrefab(GameObject prefab)
39 | {
40 | // Do nothing
41 | }
42 | }
43 | */
44 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Info.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Text;
6 |
7 | #if TILED2UNITY_MAC
8 | using Foundation;
9 | #endif
10 |
11 | namespace Tiled2Unity
12 | {
13 | // Get information about this library
14 | public class Info
15 | {
16 | public static string GetLibraryName()
17 | {
18 | return "Tiled2Unity";
19 | }
20 |
21 | public static string GetVersion()
22 | {
23 | #if TILED2UNITY_MAC
24 | var info = NSBundle.MainBundle.ObjectForInfoDictionary ("CFBundleShortVersionString");
25 | return info.ToString();
26 | #else
27 | var thisAss = Assembly.GetExecutingAssembly();
28 | AssemblyName name = new AssemblyName(thisAss.FullName);
29 | return name.Version.ToString();
30 | #endif
31 | }
32 |
33 | public static string GetPlatform()
34 | {
35 | var thisAss = Assembly.GetExecutingAssembly();
36 | PortableExecutableKinds peKind;
37 | ImageFileMachine ifMachine;
38 | thisAss.ManifestModule.GetPEKind(out peKind, out ifMachine);
39 |
40 | if (peKind.HasFlag(PortableExecutableKinds.PE32Plus))
41 | {
42 | return "Win64";
43 | }
44 |
45 | return "Win32";
46 | }
47 |
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxAnimation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Xml;
6 | using System.Xml.Linq;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public partial class TmxAnimation
11 | {
12 | public List Frames { get; private set; }
13 | public int TotalTimeMs { get; private set; }
14 |
15 | public TmxAnimation()
16 | {
17 | this.Frames = new List();
18 | }
19 |
20 | public static TmxAnimation FromXml(XElement xml, uint globalStartId)
21 | {
22 | TmxAnimation tmxAnimation = new TmxAnimation();
23 |
24 | foreach (var xmlFrame in xml.Elements("frame"))
25 | {
26 | TmxFrame tmxFrame = TmxFrame.FromXml(xmlFrame, globalStartId);
27 | tmxAnimation.Frames.Add(tmxFrame);
28 | tmxAnimation.TotalTimeMs += tmxFrame.DurationMs;
29 | }
30 |
31 | return tmxAnimation;
32 | }
33 |
34 | // Returns an single frame animation
35 | public static TmxAnimation FromTileId(uint globalTileId)
36 | {
37 | TmxAnimation tmxAnimation = new TmxAnimation();
38 |
39 | TmxFrame tmxFrame = TmxFrame.FromTileId(globalTileId);
40 | tmxAnimation.Frames.Add(tmxFrame);
41 |
42 | return tmxAnimation;
43 | }
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxProperties.Xml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Xml;
6 | using System.Xml.Linq;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public partial class TmxProperties
11 | {
12 | public static TmxProperties FromXml(XElement elem)
13 | {
14 | TmxProperties tmxProps = new TmxProperties();
15 |
16 | var props = from elem1 in elem.Elements("properties")
17 | from elem2 in elem1.Elements("property")
18 | select new
19 | {
20 | Name = TmxHelper.GetAttributeAsString(elem2, "name"),
21 | Type = TmxHelper.GetAttributeAsEnum(elem2, "type", TmxPropertyType.String),
22 |
23 | // Value may be attribute or inner text
24 | Value = TmxHelper.GetAttributeAsString(elem2, "value", null) ?? elem2.Value,
25 | };
26 |
27 | if (props.Count() > 0)
28 | {
29 | Logger.WriteVerbose("Parse properites ...");
30 | }
31 |
32 | foreach (var p in props)
33 | {
34 | tmxProps.PropertyMap[p.Name] = new TmxProperty { Name = p.Name, Type = p.Type, Value = p.Value };
35 | }
36 |
37 | return tmxProps;
38 | }
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | 0
16 |
17 |
18 | 1
19 |
20 |
21 | False
22 |
23 |
24 |
25 |
26 |
27 | False
28 |
29 |
30 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/License.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil Consolas;}}
2 | {\colortbl ;\red0\green0\blue255;}
3 | {\*\generator Riched20 10.0.10586}\viewkind4\uc1
4 | \pard\sa200\sl276\slmult1\b\f0\fs19\lang9 Tiled2Unity\b0\par
5 | Copyright (C) 2016 Sean Barton ({{\field{\*\fldinst{HYPERLINK http://www.seanba.com }}{\fldrslt{http://www.seanba.com\ul0\cf0}}}}\f0\fs19 )\par
6 | MIT License\par
7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\par
8 | \par
9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\par
10 | \par
11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\par
12 | }
13 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/build/replace-unitypackage.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # This script looks for the right Tiled2Unity unitypackage file and packs it into the Tiled2UnityMac solution to be distributed
3 | require 'nokogiri'
4 | require 'FileUtils'
5 |
6 | def get_version()
7 | # Open the Info.plist file to find out what version of Tiled2UnityMac we should be building
8 | plist = File.read("../Tiled2UnityMac/Info.plist")
9 | xml = Nokogiri::XML(plist)
10 |
11 | xml.css("key").each do |item|
12 | return item.next_element.text if item.text == "CFBundleShortVersionString"
13 | end
14 | end
15 |
16 |
17 | dir = File.dirname(__FILE__)
18 | Dir.chdir(dir) do
19 |
20 | # Get the version of Tiled2UnityMac we are building
21 | version = get_version()
22 |
23 | # Look for the Unity package we want to embed in the build
24 | package = "Tiled2Unity.#{version}.unitypackage"
25 |
26 | puts "Error: Could not find package: #{package}. Select 'Tiled2Unity -> Export Tiled2Unity Library...' from Unity and export to this directory and try again." if not File.exist?(package)
27 | exit(1) if not File.exist?(package)
28 |
29 | puts "Copying package #{package} to Tiled2UnityMac solution (resources)"
30 | FileUtils.cp(package, "../Tiled2UnityMac/Resources/Tiled2Unity.unitypackage")
31 |
32 | # Write the version to disk so other parts of the build system can get it
33 | `echo #{version} > t2u_version.txt`
34 |
35 | exit(0)
36 | end
37 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Tiled2UnityLite.Main.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | // Tiled2UnityLite is the 'automated export' version of Tiled2Unity
7 | // It is expected to open a TMX file, export, and close on its own as a command-line utility
8 | namespace Tiled2Unity
9 | {
10 | public class Tiled2UnityLite
11 | {
12 | public static int Run(string[] args)
13 | {
14 | int error = 0;
15 |
16 | // If we get an error then that changes our error code
17 | Tiled2Unity.Logger.OnWriteError += delegate (string line)
18 | {
19 | error = 1;
20 | };
21 |
22 | // Tiled2UnityLite is always auto-exporting
23 | Tiled2Unity.Settings.IsAutoExporting = true;
24 |
25 | // Run the session
26 | Tiled2Unity.Session tmxSession = new Session();
27 | tmxSession.SetCulture();
28 |
29 | if (tmxSession.InitializeWithArgs(args, false))
30 | {
31 | // Load the Tiled file (TMX)
32 | if (error == 0)
33 | {
34 | tmxSession.LoadInitialTmxFile();
35 | }
36 |
37 | // Export the Tiled file to Unity
38 | if (error == 0)
39 | {
40 | tmxSession.ExportTmxMap();
41 | }
42 | }
43 |
44 | return error;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectTypeProperty.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Xml.Linq;
6 |
7 | namespace Tiled2Unity
8 | {
9 | public class TmxObjectTypeProperty
10 | {
11 | public string Name { get; private set; }
12 | public TmxPropertyType Type { get; private set; }
13 | public string Default { get; set; }
14 |
15 | // Create a dictionary collection of Object Type Property instances from the parent xml element
16 | public static Dictionary FromObjectTypeXml(XElement xmlObjectType)
17 | {
18 | Dictionary tmxObjectTypeProperties = new Dictionary();
19 |
20 | foreach (var xmlProperty in xmlObjectType.Elements("property"))
21 | {
22 | TmxObjectTypeProperty tmxObjectTypeProperty = new TmxObjectTypeProperty();
23 |
24 | tmxObjectTypeProperty.Name = TmxHelper.GetAttributeAsString(xmlProperty, "name", "");
25 | tmxObjectTypeProperty.Type = TmxHelper.GetAttributeAsEnum(xmlProperty, "type", TmxPropertyType.String);
26 | tmxObjectTypeProperty.Default = TmxHelper.GetAttributeAsString(xmlProperty, "default", "");
27 |
28 | tmxObjectTypeProperties.Add(tmxObjectTypeProperty.Name, tmxObjectTypeProperty);
29 | }
30 |
31 | return tmxObjectTypeProperties;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Tiled2Unity")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Seanba Dev Tools")]
12 | [assembly: AssemblyProduct("Tiled2Unity")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("620bc538-4445-444b-b84d-300e35a512a9")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.7.0")]
36 | [assembly: AssemblyFileVersion("1.0.7.0")]
37 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Tiled2UnityLib")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Tiled2UnityLib")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ecc813b3-0a2d-4173-b16a-8c026247302c")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.12.4")]
36 | [assembly: AssemblyFileVersion("1.0.12.4")]
37 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/TestData/mini-tiles.tsx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/ThirdParty/LibTessDotNet/LICENSE.txt:
--------------------------------------------------------------------------------
1 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
2 | ** Copyright (C) 2011 Silicon Graphics, Inc.
3 | ** All Rights Reserved.
4 | **
5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 | ** of this software and associated documentation files (the "Software"), to deal
7 | ** in the Software without restriction, including without limitation the rights
8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 | ** of the Software, and to permit persons to whom the Software is furnished to do so,
10 | ** subject to the following conditions:
11 | **
12 | ** The above copyright notice including the dates of first publication and either this
13 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be
14 | ** included in all copies or substantial portions of the Software.
15 | **
16 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC.
19 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 | ** OR OTHER DEALINGS IN THE SOFTWARE.
22 | **
23 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not
24 | ** be used in advertising or otherwise to promote the sale, use or other dealings in
25 | ** this Software without prior written authorization from Silicon Graphics, Inc.
26 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/ThirdParty/Clipper/License.txt:
--------------------------------------------------------------------------------
1 | The Clipper Library (including Delphi, C++ & C# source code, other accompanying
2 | code, examples and documentation), hereafter called "the Software", has been
3 | released under the following license, terms and conditions:
4 |
5 | Boost Software License - Version 1.0 - August 17th, 2003
6 | http://www.boost.org/LICENSE_1_0.txt
7 |
8 | Permission is hereby granted, free of charge, to any person or organization
9 | obtaining a copy of the Software covered by this license to use, reproduce,
10 | display, distribute, execute, and transmit the Software, and to prepare
11 | derivative works of the Software, and to permit third-parties to whom the
12 | Software is furnished to do so, all subject to the following:
13 |
14 | The copyright notices in the Software and this entire statement, including the
15 | above license grant, this restriction and the following disclaimer, must be
16 | included in all copies of the Software, in whole or in part, and all derivative
17 | works of the Software, unless such copies or derivative works are solely in the
18 | form of machine-executable object code generated by a source language processor.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
23 | THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY
24 | DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING
25 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 | THE SOFTWARE.
27 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectGroup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Tiled2Unity
8 | {
9 | public partial class TmxObjectGroup : TmxLayerNode
10 | {
11 | public List Objects { get; private set; }
12 | public Color Color { get; private set; }
13 |
14 | public TmxObjectGroup(TmxLayerNode parent, TmxMap tmxMap) : base(parent, tmxMap)
15 | {
16 | this.Objects = new List();
17 | }
18 |
19 | public RectangleF GetWorldBounds(PointF translation)
20 | {
21 | RectangleF bounds = new RectangleF();
22 | foreach (var obj in this.Objects)
23 | {
24 | RectangleF objBounds = obj.GetWorldBounds();
25 | objBounds.Offset(translation);
26 | bounds = RectangleF.Union(bounds, objBounds);
27 | }
28 | return bounds;
29 | }
30 |
31 | public RectangleF GetWorldBounds()
32 | {
33 | return GetWorldBounds(new PointF(0, 0));
34 | }
35 |
36 | public override string ToString()
37 | {
38 | return String.Format("{{ ObjectGroup name={0}, numObjects={1} }}", this.Name, this.Objects.Count());
39 | }
40 |
41 | public override void Visit(ITmxVisitor visitor)
42 | {
43 | // Visit ourselves
44 | visitor.VisitObjectLayer(this);
45 |
46 | // Visit all our objects
47 | foreach (var obj in this.Objects)
48 | {
49 | visitor.VisitObject(obj);
50 | }
51 | }
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/build/zip-tiled2unity.rb:
--------------------------------------------------------------------------------
1 | # Zip up a Tiled2Unity install
2 | require 'colorize'
3 | require 'FileUtils'
4 | require 'rubygems'
5 | require 'win32console'
6 | require 'zip'
7 |
8 | t2uVersion = ARGV.shift
9 | if t2uVersion == nil
10 | puts "Need version string"
11 | exit
12 | end
13 |
14 | # Check for version file
15 | if !File.exists? "t2u-version.txt"
16 | puts "t2u-version.txt file not created"
17 | exit
18 | end
19 |
20 | # Check for mathcing version
21 | installedVersion = IO.read("t2u-version.txt")
22 | if installedVersion != t2uVersion then
23 | puts "Error zipping Tiled2Unity installation".red
24 | puts " Installed version is: #{installedVersion}"
25 | puts " Version we asked for: #{t2uVersion}"
26 | exit
27 | end
28 |
29 | # Create the zip file for Tiled2Unity
30 | zipName = "Tiled2Unity-#{t2uVersion}.zip"
31 | puts "Creating zip file: #{zipName}"
32 |
33 | FileUtils.rm(zipName) if File.exists? zipName
34 |
35 | # Zip up all the files (but do not include the uninstaller)
36 | dir = "C:/Program Files (x86)/Tiled2Unity/"
37 | Zip::File.open(zipName, Zip::File::CREATE) do |zipfile|
38 | Dir[File.join(dir, '**', '**')].each do |file|
39 | next if File.basename(file) == "uninstall.exe"
40 | puts File.basename(file)
41 | zipfile.add(file.sub(dir, ''), file)
42 | end
43 | end
44 |
45 | # Create the zip fle for Tiled2UnityLite
46 | zipName = "Tiled2UnityLite-#{t2uVersion}.zip"
47 | puts "Creating zip file: #{zipName}"
48 |
49 | FileUtils.rm(zipName) if File.exists? zipName
50 | dir = "C:/Program Files (x86)/Tiled2Unity/"
51 | Zip::File.open(zipName, Zip::File::CREATE) do |zipfile|
52 | # Copy .unitypackage and .cs files
53 | Dir[File.join(dir, '*.{unitypackage,cs}')].each do |file|
54 | puts File.basename(file)
55 | zipfile.add(file.sub(dir, ''), file)
56 | end
57 | end
58 |
59 |
60 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectTypes.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Xml.Linq;
7 |
8 | namespace Tiled2Unity
9 | {
10 | // The "objecttypes.xml" file has project-specific data to be used with the TmxObject instances
11 | public class TmxObjectTypes
12 | {
13 | public Dictionary TmxObjectTypeMapping { get; private set; }
14 |
15 | public TmxObjectTypes()
16 | {
17 | this.TmxObjectTypeMapping = new Dictionary(StringComparer.InvariantCultureIgnoreCase);
18 | }
19 |
20 | public TmxObjectType GetValueOrDefault(string key)
21 | {
22 | if (this.TmxObjectTypeMapping.ContainsKey(key))
23 | {
24 | return this.TmxObjectTypeMapping[key];
25 | }
26 |
27 | return new TmxObjectType();
28 | }
29 |
30 | public TmxObjectType GetValueOrNull(string key)
31 | {
32 | if (key != null && this.TmxObjectTypeMapping.ContainsKey(key))
33 | {
34 | return this.TmxObjectTypeMapping[key];
35 | }
36 |
37 | return null;
38 | }
39 |
40 |
41 | public static TmxObjectTypes FromXmlFile(string xmlPath)
42 | {
43 | TmxObjectTypes xmlObjectTypes = new TmxObjectTypes();
44 |
45 | XDocument doc = XDocument.Load(xmlPath);
46 |
47 | foreach (var xml in doc.Element("objecttypes").Elements("objecttype"))
48 | {
49 | TmxObjectType tmxObjectType = TmxObjectType.FromXml(xml);
50 | xmlObjectTypes.TmxObjectTypeMapping[tmxObjectType.Name] = tmxObjectType;
51 | }
52 |
53 | return xmlObjectTypes;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/TileAnimator.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0
2 | #undef T2U_USE_ASSERTIONS
3 | #else
4 | // Assertion library introduced with Unity 5.1
5 | #define T2U_USE_ASSERTIONS
6 | #endif
7 |
8 | using System;
9 | using System.Collections;
10 | using System.Collections.Generic;
11 | using System.Linq;
12 | using System.Text;
13 |
14 | using UnityEngine;
15 |
16 | #if T2U_USE_ASSERTIONS
17 | using UnityEngine.Assertions;
18 | #endif
19 |
20 | namespace Tiled2Unity
21 | {
22 | public class TileAnimator : MonoBehaviour
23 | {
24 | public float StartTime = -1;
25 | public float Duration = -1;
26 | public float TotalAnimationTime = -1;
27 |
28 | private float timer = 0;
29 |
30 | private MeshRenderer meshRenderer = null;
31 |
32 | private void Awake()
33 | {
34 | this.meshRenderer = this.GetComponent();
35 | }
36 |
37 | private void Start()
38 | {
39 | #if T2U_USE_ASSERTIONS
40 | Assert.IsTrue(this.StartTime >= 0, "StartTime cannot be negative");
41 | Assert.IsTrue(this.Duration > 0, "Duration must be positive and non-zero.");
42 | Assert.IsTrue(this.TotalAnimationTime > 0, "Total time of animation must be positive non-zero");
43 | #endif
44 | this.timer = 0.0f;
45 | }
46 |
47 | private void Update()
48 | {
49 | this.timer += Time.deltaTime;
50 |
51 | // Roll around the time if needed
52 | while (this.timer > this.TotalAnimationTime)
53 | {
54 | this.timer -= this.TotalAnimationTime;
55 | }
56 |
57 | this.meshRenderer.enabled = timer >= this.StartTime && timer < (this.StartTime + this.Duration);
58 | }
59 |
60 | }
61 | }
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 0
21 |
22 |
23 | 1
24 |
25 |
26 | False
27 |
28 |
29 |
30 |
31 |
32 | False
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/ExportClasses/TiledMapExporter.AssignMaterials.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Xml.Linq;
7 |
8 | namespace Tiled2Unity
9 | {
10 | partial class TiledMapExporter
11 | {
12 | private List CreateAssignMaterialsElements()
13 | {
14 | // Each mesh in each viewable layer needs to have its material assigned to it
15 | List elements = new List();
16 | foreach (var layer in this.tmxMap.EnumerateTileLayers())
17 | {
18 | if (layer.Visible == false)
19 | continue;
20 | if (layer.Ignore == TmxLayer.IgnoreSettings.Visual)
21 | continue;
22 |
23 | foreach (TmxMesh mesh in layer.Meshes)
24 | {
25 | XElement assignment =
26 | new XElement("AssignMaterial",
27 | new XAttribute("mesh", mesh.UniqueMeshName),
28 | new XAttribute("material", Path.GetFileNameWithoutExtension(mesh.TmxImage.AbsolutePath)));
29 |
30 | elements.Add(assignment);
31 | }
32 | }
33 |
34 | // Each mesh for each TileObject needs its material assigned
35 | foreach (var tmxMesh in this.tmxMap.GetUniqueListOfVisibleObjectTileMeshes())
36 | {
37 | XElement assignment =
38 | new XElement("AssignMaterial",
39 | new XAttribute("mesh", tmxMesh.UniqueMeshName),
40 | new XAttribute("material", Path.GetFileNameWithoutExtension(tmxMesh.TmxImage.AbsolutePath)));
41 |
42 | elements.Add(assignment);
43 | }
44 |
45 | return elements;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tiled2UnityMac", "Tiled2UnityMac\Tiled2UnityMac.csproj", "{5847689A-008D-4933-8524-0C5CAC5B9829}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | Debug|x86 = Debug|x86
11 | Release|x86 = Release|x86
12 | Debug|x64 = Debug|x64
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Debug|x64.ActiveCfg = Debug|Any CPU
19 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Debug|x64.Build.0 = Debug|Any CPU
20 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Debug|x86.ActiveCfg = Debug|Any CPU
21 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Debug|x86.Build.0 = Debug|Any CPU
22 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Release|x64.ActiveCfg = Release|Any CPU
25 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Release|x64.Build.0 = Release|Any CPU
26 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Release|x86.ActiveCfg = Release|Any CPU
27 | {5847689A-008D-4933-8524-0C5CAC5B9829}.Release|x86.Build.0 = Release|Any CPU
28 | EndGlobalSection
29 | GlobalSection(MonoDevelopProperties) = preSolution
30 | Policies = $0
31 | $0.DotNetNamingPolicy = $1
32 | $1.DirectoryNamespaceAssociation = None
33 | $1.ResourceNamePolicy = FileFormatDefault
34 | description = Mac OSX Version of Tiled2Unity Utility
35 | version = 1.0.0.0
36 | BaseDirectory = Tiled2UnityMac
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/doc/getting-started.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Tiled2Unity
2 |
3 | First, [download Tiled2Unity](http://www.seanba.com/tiled2unity) and install it on your computer.
4 |
5 | * **Windows**: The MSI installer is recommended.
6 | * **Mac**: Unzip the `Tiled2UnityMac[version].zip` file and drag the **Tiled2UnityMac.app** archive into your `Applications` folder.
7 |
8 | Tiled2Unity requires a number of scripts and shaders to be installed on any Unity project you wish to export to. This is best achieved by running Tiled2Unity and selecting the `Help -> Import Unity Package to Project` menu item.
9 |
10 | 
11 |
12 | This will prompt you to import the Tiled2Unity package into your project.
13 |
14 | 
15 |
16 | **Remember:** Run this import step every time you update Tiled2Unity so that the latest scripts are in your Unity project.
17 |
18 | ## Running Tiled2Unity
19 |
20 | Launching Tiled2Unity will show you this GUI ...
21 |
22 | 
23 |
24 | Everything you need to export a Tiled map to a Unity project should be explained there. You can also preview your map before exporting if you want to see how colliders will be created for you.
25 |
26 | ## Launching Tiled2Unity from Tiled
27 |
28 | For convenience you can add a command to Tiled that will launch Tiled2Unity for you with the currently selected map.
29 |
30 | Open the `Edit Commands...` dialog in Tiled ...
31 |
32 | 
33 |
34 | Here you can add a command to Tiled that will open Tiled2Unity, passing the current map as an argument. This command is platform specific.
35 |
36 | ### Windows
37 |
38 | ```bat
39 | "C:\Program Files\Tiled2Unity\Tiled2Unity.exe" %mapfile
40 | ```
41 | 
42 |
43 | ### Mac OS X
44 |
45 | ```bat
46 | open -a /Applications/Tiled2UnityMac.app --args %mapfile
47 | ```
48 | 
49 |
50 | With this set you can make changes to your map in Tiled Map Editor, press `F5` and easily export to your Unity project.
51 |
52 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxDisplayOrderVisitor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Tiled2Unity
8 | {
9 | // Visits the tmx map and gathers information used for sorting, depth and draw order
10 | class TmxDisplayOrderVisitor : ITmxVisitor
11 | {
12 | private int drawOrderIndex = 0;
13 | private int depthBufferIndex = 0;
14 |
15 | public void VisitMap(TmxMap map)
16 | {
17 | }
18 |
19 | public void VisitGroupLayer(TmxGroupLayer groupLayer)
20 | {
21 | // Group layer does not advance draw index
22 | groupLayer.DrawOrderIndex = this.drawOrderIndex;
23 |
24 | // But does advance buffer index
25 | groupLayer.DepthBufferIndex = this.depthBufferIndex++;
26 | }
27 |
28 |
29 | public void VisitObject(TmxObject obj)
30 | {
31 | // Objects only increase draw order if they are tiles
32 | if (obj is TmxObjectTile)
33 | {
34 | TmxObjectTile tile = obj as TmxObjectTile;
35 | tile.DrawOrderIndex = this.drawOrderIndex++;
36 | }
37 | }
38 |
39 | public void VisitObjectLayer(TmxObjectGroup objectLayer)
40 | {
41 | // Object layer does not advance draw index
42 | objectLayer.DrawOrderIndex = this.drawOrderIndex;
43 |
44 | // Children don't have a depth buffer index. Their parent sets the depth.
45 | objectLayer.DepthBufferIndex = (objectLayer.ParentNode != null) ? 0 : this.depthBufferIndex++;
46 | }
47 |
48 | public void VisitTileLayer(TmxLayer tileLayer)
49 | {
50 | // Tile layer does render something and therefore increases draw order index
51 | tileLayer.DrawOrderIndex = this.drawOrderIndex++;
52 |
53 | // Children don't have a depth buffer index. Their parent sets the depth.
54 | tileLayer.DepthBufferIndex = (tileLayer.ParentNode != null) ? 0 : this.depthBufferIndex++;
55 | }
56 |
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/build/build-installer.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | pushd %~dp0
3 | setlocal
4 |
5 | rem Build Tiled2Unity
6 | rem Note we're hardcoding Visual Studio 2015 here
7 |
8 | call "%VS140COMNTOOLS%vsvars32.bat"
9 |
10 | if defined WIXSHARP_DIR (
11 | echo WIXSHARP_DIR path: %WIXSHARP_DIR%
12 | ) else (
13 | echo Error: Install WixSharp and add WIXSHARP_DIR environment variable
14 | goto InstallFailed
15 | )
16 |
17 | if defined WIXSHARP_WIXDIR (
18 | echo WIXSHARP_WIXDIR path: %WIXSHARP_WIXDIR%
19 | ) else (
20 | echo Error: Install WixSharp and add WIXSHARP_WIXDIR environment variable. Example: C:\WixSharp\Wix_bin\bin
21 | goto InstallFailed
22 | )
23 |
24 | if defined CSSCRIPT_DIR (
25 | echo CSSCRIPT_DIR path: %CSSCRIPT_DIR%
26 | ) else (
27 | echo Error: Install CS-Script and add CSSCRIPT_DIR environment variable
28 | goto InstallFailed
29 | )
30 |
31 | rem Build Win64/x64
32 | echo -- Building Tiled2Unity x64
33 | devenv /rebuild "Release|x64" ..\Tiled2Unity.sln
34 | if ERRORLEVEL 1 goto BuildFailed
35 | echo -- Successfully built Tiled2Unity x64
36 |
37 | rem Build Win32/x86
38 | echo -- Building Tiled2Unity x86
39 | devenv /rebuild "Release|x86" ..\Tiled2Unity.sln
40 | if ERRORLEVEL 1 goto BuildFailed
41 | echo -- Successfully built Tiled2Unity x86
42 |
43 | rem Use CS-Script to build Tiled2UnityLite
44 | echo -- Building Tiled2UnityLite.cs
45 | "%CSSCRIPT_DIR%"\cscs build-tiled2unitylite.cs
46 | if ERRORLEVEL 1 goto LiteFailed
47 | echo -- Successfully built Tiled2UnityLite
48 |
49 | echo -- Building installer for Tiled2Unity x64
50 | "%CSSCRIPT_DIR%"\cscs build-msi-installer.cs x64
51 | if ERRORLEVEL 1 goto MSIFailed
52 |
53 | echo -- Building installer for Tiled2Unity x86
54 | "%CSSCRIPT_DIR%"\cscs build-msi-installer.cs x86
55 | if ERRORLEVEL 1 goto MSIFailed
56 |
57 | goto :Done
58 |
59 | endlocal
60 | popd
61 |
62 | rem Exit conditions
63 | :BuildFailed
64 | echo Tiled2Unity failed to build in Dev Studio
65 | exit /B 1
66 |
67 | :LiteFailed
68 | echo Failed to build Tiled2UnityLite
69 | exit /B 1
70 |
71 | :MSIFailed
72 | echo Failed to build MSI installer
73 | exit /B 1
74 |
75 | :InstallFailed
76 | echo Tile2Unity MSI installation failed or was canceled
77 | exit /B 1
78 |
79 | :Done
80 | echo Success
81 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Geometry/PolygonEdgeGroup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 |
8 |
9 | namespace Tiled2Unity.Geometry
10 | {
11 | // Keeps a collection of polygon edges that are shared bewteen two polygons
12 | // Assumes that all polygons have CCW winding to them
13 | public class PolygonEdgeGroup
14 | {
15 | public List PolygonEdges { get; set; }
16 |
17 |
18 | public void Initialize(List polygons)
19 | {
20 | this.PolygonEdges = new List();
21 |
22 | int polygonId = 0;
23 | foreach (var polygon in polygons)
24 | {
25 | // Our polygon will be added to each edge
26 | CompositionPolygon compPolygon = new CompositionPolygon(polygon, polygonId++);
27 |
28 | // Process all edges of the polygon
29 | for (int p = polygon.Length - 1, q = 0; q < polygon.Length; p = q++)
30 | {
31 | PointF P = polygon[p];
32 | PointF Q = polygon[q];
33 |
34 | // The clockwise edge may already exist if it was added by an earlier polygon as the counter-clockwise edge
35 | // If so, add this polygon as the CW partner of that edge
36 | PolygonEdge edge = this.PolygonEdges.FirstOrDefault(e => e.P == Q && e.Q == P);
37 | if (edge != null)
38 | {
39 | // Add ourselves as the Minor/CW partner
40 | edge.AssignMinorPartner(compPolygon);
41 | compPolygon.AddEdge(edge);
42 | }
43 | else
44 | {
45 | // If this edge is new to the collection then add it with this polygon being the CCW partner
46 | PolygonEdge newEdge = new PolygonEdge(compPolygon, p);
47 | compPolygon.AddEdge(newEdge);
48 | this.PolygonEdges.Add(newEdge);
49 | }
50 | }
51 | }
52 | }
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxTile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Tiled2Unity
8 | {
9 | public partial class TmxTile : TmxHasProperties
10 | {
11 | public TmxMap TmxMap { get; private set; }
12 | public uint GlobalId { get; private set; }
13 | public uint LocalId { get; private set; }
14 | public Size TileSize { get; private set; }
15 | public PointF Offset { get; set; }
16 | public TmxImage TmxImage { get; private set; }
17 | public Point LocationOnSource { get; private set; }
18 | public TmxProperties Properties { get; private set; }
19 | public TmxObjectGroup ObjectGroup { get; private set; }
20 | public TmxAnimation Animation { get; private set; }
21 |
22 | // Some tiles may be represented as a mesh for tile objects (a list is needed for animations)
23 | public List Meshes { get; set; }
24 |
25 |
26 | public TmxTile(TmxMap tmxMap, uint globalId, uint localId, string tilesetName, TmxImage tmxImage)
27 | {
28 | this.TmxMap = TmxMap;
29 | this.GlobalId = globalId;
30 | this.LocalId = localId;
31 | this.TmxImage = tmxImage;
32 | this.Properties = new TmxProperties();
33 | this.ObjectGroup = new TmxObjectGroup(null, this.TmxMap);
34 | this.Animation = TmxAnimation.FromTileId(globalId);
35 | this.Meshes = new List();
36 | }
37 |
38 | public bool IsEmpty
39 | {
40 | get
41 | {
42 | return this.GlobalId == 0 && this.LocalId == 0;
43 | }
44 | }
45 |
46 | public void SetTileSize(int width, int height)
47 | {
48 | this.TileSize = new Size(width, height);
49 | }
50 |
51 | public void SetLocationOnSource(int x, int y)
52 | {
53 | this.LocationOnSource = new Point(x, y);
54 | }
55 |
56 | public override string ToString()
57 | {
58 | return String.Format("{{id = {0}, source({1})}}", this.GlobalId, this.LocationOnSource);
59 | }
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2Unity.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tiled2Unity", "src\Tiled2Unity.csproj", "{5100C1BE-DF46-447A-8D7F-0376CABC85B1}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {ECC813B3-0A2D-4173-B16A-8C026247302C} = {ECC813B3-0A2D-4173-B16A-8C026247302C}
9 | EndProjectSection
10 | EndProject
11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tiled2UnityLib", "Tiled2UnityLib\Tiled2UnityLib.csproj", "{ECC813B3-0A2D-4173-B16A-8C026247302C}"
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|x64 = Debug|x64
16 | Debug|x86 = Debug|x86
17 | Release|x64 = Release|x64
18 | Release|x86 = Release|x86
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {5100C1BE-DF46-447A-8D7F-0376CABC85B1}.Debug|x64.ActiveCfg = Debug|x64
22 | {5100C1BE-DF46-447A-8D7F-0376CABC85B1}.Debug|x64.Build.0 = Debug|x64
23 | {5100C1BE-DF46-447A-8D7F-0376CABC85B1}.Debug|x86.ActiveCfg = Debug|x86
24 | {5100C1BE-DF46-447A-8D7F-0376CABC85B1}.Debug|x86.Build.0 = Debug|x86
25 | {5100C1BE-DF46-447A-8D7F-0376CABC85B1}.Release|x64.ActiveCfg = Release|x64
26 | {5100C1BE-DF46-447A-8D7F-0376CABC85B1}.Release|x64.Build.0 = Release|x64
27 | {5100C1BE-DF46-447A-8D7F-0376CABC85B1}.Release|x86.ActiveCfg = Release|x86
28 | {5100C1BE-DF46-447A-8D7F-0376CABC85B1}.Release|x86.Build.0 = Release|x86
29 | {ECC813B3-0A2D-4173-B16A-8C026247302C}.Debug|x64.ActiveCfg = Debug|x64
30 | {ECC813B3-0A2D-4173-B16A-8C026247302C}.Debug|x64.Build.0 = Debug|x64
31 | {ECC813B3-0A2D-4173-B16A-8C026247302C}.Debug|x86.ActiveCfg = Debug|x86
32 | {ECC813B3-0A2D-4173-B16A-8C026247302C}.Debug|x86.Build.0 = Debug|x86
33 | {ECC813B3-0A2D-4173-B16A-8C026247302C}.Release|x64.ActiveCfg = Release|x64
34 | {ECC813B3-0A2D-4173-B16A-8C026247302C}.Release|x64.Build.0 = Release|x64
35 | {ECC813B3-0A2D-4173-B16A-8C026247302C}.Release|x86.ActiveCfg = Release|x86
36 | {ECC813B3-0A2D-4173-B16A-8C026247302C}.Release|x86.Build.0 = Release|x86
37 | EndGlobalSection
38 | GlobalSection(SolutionProperties) = preSolution
39 | HideSolutionNode = FALSE
40 | EndGlobalSection
41 | EndGlobal
42 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxRotationMatrix.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | // This is a working man's rotation matrix
8 | // This keeps us from invoking the .NET GDI+ Matrix which causes issues on Mac builds
9 | namespace Tiled2Unity
10 | {
11 | class TmxRotationMatrix
12 | {
13 | private float[,] m = new float[2,2] { { 1, 0 },
14 | { 0, 1 } };
15 |
16 | public TmxRotationMatrix()
17 | {
18 | }
19 |
20 | public TmxRotationMatrix(float degrees)
21 | {
22 | double rads = degrees * Math.PI / 180.0f;
23 | float cos = (float)Math.Cos(rads);
24 | float sin = (float)Math.Sin(rads);
25 |
26 | m[0, 0] = cos;
27 | m[0, 1] = -sin;
28 | m[1, 0] = sin;
29 | m[1, 1] = cos;
30 | }
31 |
32 | public TmxRotationMatrix(float m00, float m01, float m10, float m11)
33 | {
34 | m[0, 0] = m00;
35 | m[0, 1] = m01;
36 | m[1, 0] = m10;
37 | m[1, 1] = m11;
38 | }
39 |
40 | public float this[int i, int j]
41 | {
42 | get { return m[i, j]; }
43 | set { m[i, j] = value; }
44 | }
45 |
46 | static public TmxRotationMatrix Multiply(TmxRotationMatrix M1, TmxRotationMatrix M2)
47 | {
48 | float m00 = M1[0, 0] * M2[0, 0] + M1[0, 1] * M2[1, 0];
49 | float m01 = M1[0, 0] * M2[0, 1] + M1[0, 1] * M2[1, 1];
50 | float m10 = M1[1, 0] * M2[0, 0] + M1[1, 1] * M2[1, 0];
51 | float m11 = M1[1, 0] * M2[0, 1] + M1[1, 1] * M2[1, 1];
52 | return new TmxRotationMatrix(m00, m01, m10, m11);
53 | }
54 |
55 | public void TransformPoint(ref PointF pt)
56 | {
57 | float x = pt.X * m[0, 0] + pt.Y * m[1, 0];
58 | float y = pt.X * m[0, 1] + pt.Y * m[1, 1];
59 | pt.X = x;
60 | pt.Y = y;
61 | }
62 |
63 | public void TransformPoints(PointF[] points)
64 | {
65 | for (int i = 0; i < points.Length; ++i)
66 | {
67 | TransformPoint(ref points[i]);
68 | }
69 | }
70 |
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxLayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public partial class TmxLayer : TmxLayerNode
11 | {
12 | public int Width { get; private set; }
13 | public int Height { get; private set; }
14 | public uint[] TileIds { get; private set; }
15 | public List Meshes { get; private set; }
16 | public List CollisionLayers { get; private set; }
17 |
18 | public TmxLayer(TmxLayerNode parent, TmxMap map) : base(parent, map)
19 | {
20 | this.Visible = true;
21 | this.Opacity = 1.0f;
22 | this.CollisionLayers = new List();
23 | }
24 |
25 | public uint GetTileIdAt(int x, int y)
26 | {
27 | uint tileId = GetRawTileIdAt(x, y);
28 | return TmxMath.GetTileIdWithoutFlags(tileId);
29 | }
30 |
31 | public uint GetRawTileIdAt(int x, int y)
32 | {
33 | Debug.Assert(x < this.Width && y < this.Height);
34 | Debug.Assert(x >= 0 && y >= 0);
35 | int index = GetTileIndex(x, y);
36 | return this.TileIds[index];
37 | }
38 |
39 | public int GetTileIndex(int x, int y)
40 | {
41 | return y * this.Width + x;
42 | }
43 |
44 | public Point CoordinatesFromIndex(int index)
45 | {
46 | return new Point(index % this.Width, index / this.Width);
47 | }
48 |
49 | public bool IsExportingConvexPolygons()
50 | {
51 | // Always obey layer first
52 | if (this.Properties.PropertyMap.ContainsKey("unity:convex"))
53 | {
54 | return this.Properties.GetPropertyValueAsBoolean("unity:convex", true);
55 | }
56 |
57 | // Use the map next
58 | if (this.TmxMap.Properties.PropertyMap.ContainsKey("unity:convex"))
59 | {
60 | return this.TmxMap.Properties.GetPropertyValueAsBoolean("unity:convex", true);
61 | }
62 |
63 | // Use the program setting last
64 | return Tiled2Unity.Settings.PreferConvexPolygons;
65 | }
66 |
67 | public override void Visit(ITmxVisitor visitor)
68 | {
69 | visitor.VisitTileLayer(this);
70 | }
71 |
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/Main.cs:
--------------------------------------------------------------------------------
1 | using AppKit;
2 |
3 | using System;
4 | using System.Diagnostics;
5 | using System.Drawing;
6 | using System.IO;
7 |
8 | namespace Tiled2UnityMac
9 | {
10 | static class MainClass
11 | {
12 | static int Main (string[] args)
13 | {
14 | bool isAuto = false;
15 | NDesk.Options.OptionSet options = new NDesk.Options.OptionSet () {
16 | { "a|auto-export", "Automatic export", a => isAuto = true }
17 | };
18 |
19 | options.Parse (args);
20 | if (isAuto)
21 | {
22 | // Note: We still have to initialize and terminate the application correctly
23 | NSApplication.Init();
24 |
25 | // Capture output to a log since we can't print out to the command line
26 | // The log file location is an Apple standard
27 | string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Library");
28 | logPath = Path.Combine(logPath, "Logs/Tiled2UnityMac/auto-export.log");
29 |
30 | // Create the directory if it doesn't exist
31 | var pathInfo = new FileInfo(logPath);
32 | pathInfo.Directory.Create();
33 |
34 | // If we get an error then that changes our error code
35 | Tiled2Unity.Logger.OnWriteError += delegate (string line)
36 | {
37 | using (StreamWriter log = File.AppendText(logPath))
38 | {
39 | log.Write(line);
40 | }
41 | };
42 |
43 | // Also print out warnings
44 | Tiled2Unity.Logger.OnWriteWarning += delegate (string line)
45 | {
46 | using (StreamWriter log = File.AppendText(logPath))
47 | {
48 | log.Write(line);
49 | }
50 | };
51 |
52 | // Also write out success
53 | Tiled2Unity.Logger.OnWriteSuccess += delegate (string line)
54 | {
55 | using (StreamWriter log = File.AppendText(logPath))
56 | {
57 | log.Write(line);
58 | }
59 | };
60 |
61 | // And also write out general usage to log
62 | Tiled2Unity.Logger.OnWriteLine += delegate (string line)
63 | {
64 | using (StreamWriter log = File.AppendText(logPath))
65 | {
66 | log.Write(line);
67 | }
68 | };
69 |
70 | // Run Tiled2UnityLite with no GUI
71 | int error = Tiled2Unity.Tiled2UnityLite.Run (args);
72 |
73 | // Shutdown the "application" and return error to the command line
74 | NSApplication.SharedApplication.Terminate(NSApplication.SharedApplication);
75 | return error;
76 | }
77 |
78 | // Run the utility as normal with a full GUI
79 | NSApplication.Init ();
80 | NSApplication.Main (args);
81 |
82 | return 0;
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectPolyline.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public class TmxObjectPolyline : TmxObject, TmxHasPoints
11 | {
12 | public List Points { get; set; }
13 |
14 | public TmxObjectPolyline()
15 | {
16 | this.Points = new List();
17 | }
18 |
19 | public override RectangleF GetWorldBounds()
20 | {
21 | float xmin = float.MaxValue;
22 | float xmax = float.MinValue;
23 | float ymin = float.MaxValue;
24 | float ymax = float.MinValue;
25 |
26 | foreach (var p in this.Points)
27 | {
28 | xmin = Math.Min(xmin, p.X);
29 | xmax = Math.Max(xmax, p.X);
30 | ymin = Math.Min(ymin, p.Y);
31 | ymax = Math.Max(ymax, p.Y);
32 | }
33 |
34 | RectangleF bounds = new RectangleF(xmin, ymin, xmax - xmin, ymax - ymin);
35 | bounds.Offset(this.Position);
36 | return bounds;
37 | }
38 |
39 | protected override void InternalFromXml(System.Xml.Linq.XElement xml, TmxMap tmxMap)
40 | {
41 | Debug.Assert(xml.Name == "object");
42 | Debug.Assert(xml.Element("polyline") != null);
43 |
44 | var points = from pt in xml.Element("polyline").Attribute("points").Value.Split(' ')
45 | let x = float.Parse(pt.Split(',')[0])
46 | let y = float.Parse(pt.Split(',')[1])
47 | select new PointF(x, y);
48 |
49 | // If there are only 2 points in the polyline then we force a midpoint between them
50 | // This is because the clipper library is rejecting polylines unless there is 3 or more points
51 | if (points.Count() == 2)
52 | {
53 | var A = points.First();
54 | var B = points.Last();
55 | var M = TmxMath.MidPoint(A, B);
56 | this.Points = new List() { A, M, B };
57 | }
58 | else
59 | {
60 | this.Points = points.ToList();
61 | }
62 | }
63 |
64 | protected override string InternalGetDefaultName()
65 | {
66 | return "PolylineObject";
67 | }
68 |
69 | public bool ArePointsClosed()
70 | {
71 | // Lines are open
72 | return false;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/Resources/About.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033\deflangfe1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\fnil\fcharset2 Symbol;}}
2 | {\colortbl ;\red0\green0\blue255;}
3 | {\*\generator Riched20 10.0.10586}\viewkind4\uc1
4 | \pard\nowidctlpar\sl276\slmult1\b\f0\fs28\lang9 About Tiled2Unity\fs24\par
5 | \b0\fs20 Copyright 2015 Sean Barton (aka Seanba)\par
6 |
7 | \pard {{\field{\*\fldinst{HYPERLINK http://www.seanba.com/IntroTiled2Unity.html }}{\fldrslt{http://www.seanba.com/IntroTiled2Unity.html\ul0\cf0}}}}\f0\fs20\par
8 | \par
9 | \b Tiled2Unity\b0 is free software distributed under the MIT License (MIT). A copy of the MIT is contained in the 'License.Tiled2Unity.txt' file distributed with Tiled2Unity.\par
10 | \par
11 | Orthographic example artwork attributed to \b Blarget2\par
12 | \b0 ({{\field{\*\fldinst{HYPERLINK http://opengameart.org/content/minimalist-pixel-tileset }}{\fldrslt{http://opengameart.org/content/minimalist-pixel-tileset\ul0\cf0}}}}\f0\fs20 )\par
13 | \par
14 | Isometric example artwork attributed to \b Yar\par
15 | \b0 ({{\field{\*\fldinst{HYPERLINK http://opengameart.org/content/isometric-64x64-outside-tileset }}{\fldrslt{http://opengameart.org/content/isometric-64x64-outside-tileset\ul0\cf0}}}}\f0\fs20 )\par
16 | \par
17 | Hexagonal example artwork attributed to \b Steffen\par
18 | \b0 ({{\field{\*\fldinst{HYPERLINK http://tilemapkit.com/2015/05/create-hexagonal-tilemaps-in-tiled/ }}{\fldrslt{http://tilemapkit.com/2015/05/create-hexagonal-tilemaps-in-tiled/\ul0\cf0}}}}\f0\fs20 )\par
19 | \par
20 | Tiled2Unity was created with thanks and appreciation to the authors of these libraries:\par
21 |
22 | \pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnindent0{\pntxtb\'B7}}\fi-360\li720\b Clipper\b0 , Angus Johnson ({{\field{\*\fldinst{HYPERLINK http://www.angusj.com/delphi/clipper.php }}{\fldrslt{http://www.angusj.com/delphi/clipper.php\ul0\cf0}}}}\f0\fs20 )\par
23 | {\pntext\f1\'B7\tab}\b NDesk.Options\b0 , Jonathan Pryor ({{\field{\*\fldinst{HYPERLINK http://www.ndesk.org/Options }}{\fldrslt{http://www.ndesk.org/Options\ul0\cf0}}}}\f0\fs20 )\par
24 | {\pntext\f1\'B7\tab}\b LibTessDotNet\b0 , R\'e9mi Gillig ({{\field{\*\fldinst{HYPERLINK https://github.com/speps/LibTessDotNet }}{\fldrslt{https://github.com/speps/LibTessDotNet\ul0\cf0}}}}\f0\fs20 )\par
25 |
26 | \pard\li360\par
27 |
28 | \pard\b Tiled Map Editor\b0 is copyright Thorbj\'f8rn Lindeijer ({{\field{\*\fldinst{HYPERLINK http://www.mapeditor.org }}{\fldrslt{http://www.mapeditor.org\ul0\cf0}}}}\f0\fs20 ) \par
29 | \b Unity\b0 is copyright Unity Technologies ({{\field{\*\fldinst{HYPERLINK http://www.unity3d.com }}{\fldrslt{http://www.unity3d.com\ul0\cf0}}}}\f0\fs20 )\par
30 |
31 | \pard\li360\par
32 | \par
33 | \par
34 | }
35 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Geometry/TriangulateClipperSolution.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 |
7 |
8 | namespace Tiled2Unity.Geometry
9 | {
10 | // Input is a ClipperLib solution and output is a collection of triangles
11 | public class TriangulateClipperSolution
12 | {
13 | public List Triangulate(ClipperLib.PolyTree solution)
14 | {
15 | List triangles = new List();
16 |
17 | var tess = new LibTessDotNet.Tess();
18 | tess.NoEmptyPolygons = true;
19 |
20 | // Transformation function from ClipperLip Point to LibTess contour vertex
21 | Func xfToContourVertex = (p) => new LibTessDotNet.ContourVertex() { Position = new LibTessDotNet.Vec3 { X = p.X, Y = p.Y, Z = 0 } };
22 |
23 | // Add a contour for each part of the solution tree
24 | ClipperLib.PolyNode node = solution.GetFirst();
25 | while (node != null)
26 | {
27 | // Only interested in closed paths
28 | if (!node.IsOpen)
29 | {
30 | // Add a new countor. Holes are automatically generated.
31 | var vertices = node.Contour.Select(xfToContourVertex).ToArray();
32 | tess.AddContour(vertices);
33 | }
34 | node = node.GetNext();
35 | }
36 |
37 | // Do the tessellation
38 | tess.Tessellate(LibTessDotNet.WindingRule.EvenOdd, LibTessDotNet.ElementType.Polygons, 3);
39 |
40 | // Extract the triangles
41 | int numTriangles = tess.ElementCount;
42 | for (int i = 0; i < numTriangles; i++)
43 | {
44 | var v0 = tess.Vertices[tess.Elements[i * 3 + 0]].Position;
45 | var v1 = tess.Vertices[tess.Elements[i * 3 + 1]].Position;
46 | var v2 = tess.Vertices[tess.Elements[i * 3 + 2]].Position;
47 |
48 | List triangle = new List()
49 | {
50 | new PointF(v0.X, v0.Y),
51 | new PointF(v1.X, v1.Y),
52 | new PointF(v2.X, v2.Y),
53 | };
54 |
55 | // Assume each triangle needs to be CCW
56 | float cross = Geometry.Math.Cross(triangle[0], triangle[1], triangle[2]);
57 | if (cross > 0)
58 | {
59 | triangle.Reverse();
60 | }
61 |
62 | triangles.Add(triangle.ToArray());
63 | }
64 |
65 | return triangles;
66 | }
67 |
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Geometry/ComposeConvexPolygons.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 |
8 |
9 | namespace Tiled2Unity.Geometry
10 | {
11 | // Input is a collection of triangles and output is a collection of convex polygons
12 | // We remove shared edges along triangles were we can using the Hertel-Mehlhorn Algorithm
13 | public class ComposeConvexPolygons
14 | {
15 | public PolygonEdgeGroup PolygonEdgeGroup { get; private set; }
16 | public List ConvexPolygons { get; private set; }
17 |
18 | public ComposeConvexPolygons()
19 | {
20 | this.PolygonEdgeGroup = new PolygonEdgeGroup();
21 | }
22 |
23 | public List Compose(List triangles)
24 | {
25 | this.PolygonEdgeGroup.Initialize(triangles);
26 | CombinePolygons();
27 | return this.ConvexPolygons;
28 | }
29 |
30 | private void CombinePolygons()
31 | {
32 | // Before we start merging polygons keep a list of all the ones we have
33 | List convexPolygons = new List();
34 | foreach (var edge in this.PolygonEdgeGroup.PolygonEdges)
35 | {
36 | if (edge.MajorPartner != null)
37 | {
38 | convexPolygons.Add(edge.MajorPartner);
39 | }
40 |
41 | if (edge.MinorPartner != null)
42 | {
43 | convexPolygons.Add(edge.MinorPartner);
44 | }
45 | }
46 | convexPolygons = convexPolygons.Distinct().ToList();
47 |
48 | // Remove edges that don't have both partners since we can't possibly merge on them
49 | this.PolygonEdgeGroup.PolygonEdges.RemoveAll(e => e.MinorPartner == null || e.MajorPartner == null);
50 |
51 | // Now try to remove edges by merging the polygons on both sides
52 | // We try to remove the longest edges first as, in general, it gives us solutions that avoid long splinters
53 | var edgesByLength = this.PolygonEdgeGroup.PolygonEdges.OrderByDescending(edge => edge.Length2);
54 |
55 | foreach (var edge in edgesByLength)
56 | {
57 | if (edge.CanMergePolygons())
58 | {
59 | // Remove the minor polygon from our list of convex polygons and merge
60 | convexPolygons.Remove(edge.MinorPartner);
61 |
62 | edge.MergePolygons();
63 | }
64 | }
65 |
66 | this.ConvexPolygons = convexPolygons.Select(cp => cp.Points.ToArray()).ToList();
67 | }
68 |
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Editor/ImportTiled2Unity.Texture.cs:
--------------------------------------------------------------------------------
1 | #if !UNITY_WEBPLAYER
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | using UnityEditor;
9 | using UnityEngine;
10 |
11 | namespace Tiled2Unity
12 | {
13 | // Handled a texture being imported
14 | partial class ImportTiled2Unity
15 | {
16 | public void TextureImported(string texturePath)
17 | {
18 | // Find the import behaviour that was waiting on this texture to be imported
19 | string asset = System.IO.Path.GetFileName(texturePath);
20 | foreach (var importComponent in ImportBehaviour.EnumerateImportBehaviors_ByWaitingTexture(asset))
21 | {
22 | // The texture has finished loading. Keep track of that status.
23 | if (!importComponent.ImportComplete_Textures.Contains(asset, StringComparer.OrdinalIgnoreCase))
24 | {
25 | importComponent.ImportComplete_Textures.Add(asset);
26 | }
27 |
28 | // Are we done importing all textures? If so then start importing materials.
29 | if (importComponent.IsTextureImportingCompleted())
30 | {
31 | ImportAllMaterials(importComponent);
32 | }
33 | }
34 | }
35 |
36 | private void ImportAllTextures(Tiled2Unity.ImportBehaviour importComponent)
37 | {
38 | // Textures need to be imported before we can create or import materials
39 | foreach (var xmlImportTexture in importComponent.XmlDocument.Root.Elements("ImportTexture"))
40 | {
41 | string filename = ImportUtils.GetAttributeAsString(xmlImportTexture, "filename");
42 | string data = xmlImportTexture.Value;
43 | byte[] bytes = ImportUtils.Base64ToBytes(data);
44 |
45 | // Keep track that we are importing this texture
46 | if (!importComponent.ImportWait_Textures.Contains(filename, StringComparer.OrdinalIgnoreCase))
47 | {
48 | importComponent.ImportWait_Textures.Add(filename);
49 | }
50 |
51 | // Start the import process for this texture
52 | string pathToSave = GetTextureAssetPath(filename);
53 | ImportUtils.ReadyToWrite(pathToSave);
54 | File.WriteAllBytes(pathToSave, bytes);
55 | importComponent.ImportTiled2UnityAsset(pathToSave);
56 | }
57 |
58 | // If we have no textures too import then go to next stage (materials)
59 | if (importComponent.ImportWait_Textures.Count() == 0)
60 | {
61 | ImportAllMaterials(importComponent);
62 | }
63 | }
64 | }
65 | }
66 | #endif
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/SpriteDepthInMap.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | // Helper class to figure out how a sprite's z component should be set as they traverse a Tiled map
9 | // Can use as a behvaior that will do the work for you each update. Note this will change your sprite's z-component value on you which may collide with other behaviours.
10 | namespace Tiled2Unity
11 | {
12 | public class SpriteDepthInMap : MonoBehaviour
13 | {
14 | [Tooltip("The TiledMap instance our sprite is interacting with.")]
15 | public Tiled2Unity.TiledMap AttachedMap = null;
16 |
17 | [Tooltip("Which layer on the TiledMap our sprite is interacting with. Will render above lower layers and below higher layers. Render order of Tiles on same layer will depend on location.")]
18 | public int InteractWithLayer = 0;
19 |
20 | [Tooltip("For maps where tileset heights are different than map tile heights. Enter the tileset height here. Useful/crucial for isometric maps. Leave at default (0) if you don't care.")]
21 | public int TilesetHeight = 0;
22 |
23 | private void Start()
24 | {
25 | if (this.AttachedMap == null)
26 | {
27 | Debug.LogError(String.Format("Sprite must be attached to a TiledMap instance in order to calucluate the 'z-depth' on that map. Check the SpriteDepthInMap component in the Inspector."));
28 | return;
29 | }
30 | }
31 |
32 | private void Update()
33 | {
34 | UpdateSpriteDepth();
35 | }
36 |
37 | public void UpdateSpriteDepth()
38 | {
39 | // Put position into map space
40 | Vector3 spritePosition = this.gameObject.transform.position;
41 | spritePosition -= this.AttachedMap.gameObject.transform.position;
42 |
43 | // Some maps (like isometric) have a tileset height that is larger than the map tile height in order to get the isometric illusion. We need to know that difference in caluclating depth.
44 | if (TilesetHeight != 0)
45 | {
46 | int delta_y = this.AttachedMap.TileHeight - this.TilesetHeight;
47 | spritePosition.y += delta_y;
48 | }
49 |
50 | Rect mapRect = this.AttachedMap.GetMapRect();
51 | float depthPerLayer = -this.AttachedMap.TileHeight / mapRect.height;
52 |
53 | float depth_z = (spritePosition.y / this.AttachedMap.ExportScale / mapRect.height) + (depthPerLayer * this.InteractWithLayer);
54 |
55 | // Assign our depth value in the z component.
56 | this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y, depth_z);
57 | }
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxProperties.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | public partial class TmxProperties
9 | {
10 | public IDictionary PropertyMap { get; private set; }
11 |
12 | public TmxProperties()
13 | {
14 | this.PropertyMap = new Dictionary(StringComparer.InvariantCultureIgnoreCase);
15 | }
16 |
17 | public string GetPropertyValueAsString(string name)
18 | {
19 | return this.PropertyMap[name].Value;
20 | }
21 |
22 | public string GetPropertyValueAsString(string name, string defaultValue)
23 | {
24 | if (this.PropertyMap.ContainsKey(name))
25 | return this.PropertyMap[name].Value;
26 | return defaultValue;
27 | }
28 |
29 | public int GetPropertyValueAsInt(string name)
30 | {
31 | try
32 | {
33 | return Convert.ToInt32(this.PropertyMap[name].Value);
34 | }
35 | catch (System.FormatException inner)
36 | {
37 | string message = String.Format("Error evaulating property '{0}={1}'\n '{1}' is not an integer", name, this.PropertyMap[name].Value);
38 | throw new TmxException(message, inner);
39 | }
40 | }
41 |
42 | public int GetPropertyValueAsInt(string name, int defaultValue)
43 | {
44 | if (this.PropertyMap.ContainsKey(name))
45 | return GetPropertyValueAsInt(name);
46 | return defaultValue;
47 | }
48 |
49 | public bool GetPropertyValueAsBoolean(string name)
50 | {
51 | bool asBoolean = false;
52 | try
53 | {
54 | asBoolean = Convert.ToBoolean(this.PropertyMap[name].Value);
55 | }
56 | catch (FormatException)
57 | {
58 | Logger.WriteWarning("Property '{0}' value '{1}' cannot be converted to a boolean.", name, this.PropertyMap[name].Value);
59 | }
60 |
61 | return asBoolean;
62 | }
63 |
64 | public bool GetPropertyValueAsBoolean(string name, bool defaultValue)
65 | {
66 | if (this.PropertyMap.ContainsKey(name))
67 | return GetPropertyValueAsBoolean(name);
68 | return defaultValue;
69 | }
70 |
71 | public T GetPropertyValueAsEnum(string name)
72 | {
73 | return TmxHelper.GetStringAsEnum(this.PropertyMap[name].Value);
74 | }
75 |
76 | public T GetPropertyValueAsEnum(string name, T defaultValue)
77 | {
78 | if (this.PropertyMap.ContainsKey(name))
79 | return GetPropertyValueAsEnum(name);
80 | return defaultValue;
81 | }
82 |
83 | } // end class
84 | } // end namespace
85 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Xml.Linq;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public abstract partial class TmxObject : TmxHasProperties
11 | {
12 | public int Id { get; private set; }
13 | public string Name { get; private set; }
14 | public string Type { get; private set; }
15 | public bool Visible { get; private set; }
16 | public PointF Position { get; private set; }
17 | public SizeF Size { get; private set; }
18 | public float Rotation { get; private set; }
19 | public TmxProperties Properties { get; private set; }
20 | public TmxObjectGroup ParentObjectGroup { get; private set; }
21 |
22 | public string GetNonEmptyName()
23 | {
24 | if (String.IsNullOrEmpty(this.Name))
25 | return InternalGetDefaultName();
26 | return this.Name;
27 | }
28 |
29 | public override string ToString()
30 | {
31 | return String.Format("{0} {1} pos={2}, size={3} rot = {4}", GetType().Name, GetNonEmptyName(), this.Position, this.Size, this.Rotation);
32 | }
33 |
34 | public void BakeRotation()
35 | {
36 | // Rotate (0, 0)
37 | PointF[] pointfs = new PointF[1] { PointF.Empty };
38 | TmxMath.RotatePoints(pointfs, this);
39 |
40 | // Bake that rotation into our position, sanitizing the result
41 | float x = this.Position.X - pointfs[0].X;
42 | float y = this.Position.Y - pointfs[0].Y;
43 | this.Position = new PointF(x, y);
44 | this.Position = TmxMath.Sanitize(this.Position);
45 |
46 | // Null out our rotation
47 | this.Rotation = 0;
48 | }
49 |
50 | static protected void CopyBaseProperties(TmxObject from, TmxObject to)
51 | {
52 | to.Id = from.Id;
53 | to.Name = from.Name;
54 | to.Type = from.Type;
55 | to.Visible = from.Visible;
56 | to.Position = from.Position;
57 | to.Size = from.Size;
58 | to.Rotation = from.Rotation;
59 | to.Properties = from.Properties;
60 | to.ParentObjectGroup = from.ParentObjectGroup;
61 | }
62 |
63 | // Get the world boundary taking into account that the parent object group (and/or one of its ancestors) is offset
64 | public RectangleF GetOffsetWorldBounds()
65 | {
66 | RectangleF bounds = GetWorldBounds();
67 | PointF combinedOffset = this.ParentObjectGroup.GetCombinedOffset();
68 | bounds.Offset(combinedOffset);
69 | return bounds;
70 | }
71 |
72 | public abstract RectangleF GetWorldBounds();
73 | protected abstract void InternalFromXml(XElement xml, TmxMap tmxMap);
74 | protected abstract string InternalGetDefaultName();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityMac/Tiled2UnityMac/ViewController.designer.cs:
--------------------------------------------------------------------------------
1 | // WARNING
2 | //
3 | // This file has been generated automatically by Xamarin Studio to store outlets and
4 | // actions made in the UI designer. If it is removed, they will be lost.
5 | // Manual changes to this file may not be handled correctly.
6 | //
7 | using Foundation;
8 | using System.CodeDom.Compiler;
9 |
10 | namespace Tiled2UnityMac
11 | {
12 | [Register ("ViewController")]
13 | partial class ViewController
14 | {
15 | [Outlet]
16 | AppKit.NSButton CheckButtonDepthBufferEnabled { get; set; }
17 |
18 | [Outlet]
19 | AppKit.NSButton CheckButtonPreferConvexPolygons { get; set; }
20 |
21 | [Outlet]
22 | AppKit.NSTextField TextFieldExportTo { get; set; }
23 |
24 | [Outlet]
25 | AppKit.NSTextField TextFieldLaunchTip { get; set; }
26 |
27 | [Outlet]
28 | AppKit.NSTextField TextFieldScale { get; set; }
29 |
30 | [Outlet]
31 | AppKit.NSTextField TextViewObjectTypesXml { get; set; }
32 |
33 | [Outlet]
34 | AppKit.NSTextView TextViewOutput { get; set; }
35 |
36 | [Action ("ButtonClicked_BigAssExport:")]
37 | partial void ButtonClicked_BigAssExport (Foundation.NSObject sender);
38 |
39 | [Action ("ClickedButton_ClearObjectXml:")]
40 | partial void ClickedButton_ClearObjectXml (Foundation.NSObject sender);
41 |
42 | [Action ("ClickedButton_DepthBufferEnabled:")]
43 | partial void ClickedButton_DepthBufferEnabled (Foundation.NSObject sender);
44 |
45 | [Action ("ClickedButton_ExportTo:")]
46 | partial void ClickedButton_ExportTo (Foundation.NSObject sender);
47 |
48 | [Action ("ClickedButton_ObjectTypesXml:")]
49 | partial void ClickedButton_ObjectTypesXml (Foundation.NSObject sender);
50 |
51 | [Action ("ClickedButton_PreferConvexPolygons:")]
52 | partial void ClickedButton_PreferConvexPolygons (Foundation.NSObject sender);
53 |
54 | [Action ("ClickedButton_Preview:")]
55 | partial void ClickedButton_Preview (Foundation.NSObject sender);
56 |
57 | [Action ("TextChanged_Scale:")]
58 | partial void TextChanged_Scale (Foundation.NSObject sender);
59 |
60 | void ReleaseDesignerOutlets ()
61 | {
62 | if (CheckButtonDepthBufferEnabled != null) {
63 | CheckButtonDepthBufferEnabled.Dispose ();
64 | CheckButtonDepthBufferEnabled = null;
65 | }
66 |
67 | if (CheckButtonPreferConvexPolygons != null) {
68 | CheckButtonPreferConvexPolygons.Dispose ();
69 | CheckButtonPreferConvexPolygons = null;
70 | }
71 |
72 | if (TextFieldExportTo != null) {
73 | TextFieldExportTo.Dispose ();
74 | TextFieldExportTo = null;
75 | }
76 |
77 | if (TextFieldLaunchTip != null) {
78 | TextFieldLaunchTip.Dispose ();
79 | TextFieldLaunchTip = null;
80 | }
81 |
82 | if (TextFieldScale != null) {
83 | TextFieldScale.Dispose ();
84 | TextFieldScale = null;
85 | }
86 |
87 | if (TextViewObjectTypesXml != null) {
88 | TextViewObjectTypesXml.Dispose ();
89 | TextViewObjectTypesXml = null;
90 | }
91 |
92 | if (TextViewOutput != null) {
93 | TextViewOutput.Dispose ();
94 | TextViewOutput = null;
95 | }
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObject.Xml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using System.Xml;
7 | using System.Xml.Linq;
8 |
9 | namespace Tiled2Unity
10 | {
11 | partial class TmxObject
12 | {
13 | public static TmxObject FromXml(XElement xml, TmxObjectGroup tmxObjectGroup, TmxMap tmxMap)
14 | {
15 | Logger.WriteVerbose("Parsing object ...");
16 |
17 | // What kind of TmxObject are we creating?
18 | TmxObject tmxObject = null;
19 |
20 | if (xml.Element("ellipse") != null)
21 | {
22 | tmxObject = new TmxObjectEllipse();
23 | }
24 | else if (xml.Element("polygon") != null)
25 | {
26 | tmxObject = new TmxObjectPolygon();
27 | }
28 | else if (xml.Element("polyline") != null)
29 | {
30 | tmxObject = new TmxObjectPolyline();
31 | }
32 | else if (xml.Attribute("gid") != null)
33 | {
34 | uint gid = TmxHelper.GetAttributeAsUInt(xml, "gid");
35 | gid = TmxMath.GetTileIdWithoutFlags(gid);
36 | if (tmxMap.Tiles.ContainsKey(gid))
37 | {
38 | tmxObject = new TmxObjectTile();
39 | }
40 | else
41 | {
42 | // For some reason, the tile is not in any of our tilesets
43 | // Warn the user and use a rectangle
44 | Logger.WriteWarning("Tile Id {0} not found in tilesets. Using a rectangle instead.\n{1}", gid, xml.ToString());
45 | tmxObject = new TmxObjectRectangle();
46 | }
47 | }
48 | else
49 | {
50 | // Just a rectangle
51 | tmxObject = new TmxObjectRectangle();
52 | }
53 |
54 | // Data found on every object type
55 | tmxObject.Id = TmxHelper.GetAttributeAsInt(xml, "id", 0);
56 | tmxObject.Name = TmxHelper.GetAttributeAsString(xml, "name", "");
57 | tmxObject.Type = TmxHelper.GetAttributeAsString(xml, "type", "");
58 | tmxObject.Visible = TmxHelper.GetAttributeAsInt(xml, "visible", 1) == 1;
59 | tmxObject.ParentObjectGroup = tmxObjectGroup;
60 |
61 | float x = TmxHelper.GetAttributeAsFloat(xml, "x");
62 | float y = TmxHelper.GetAttributeAsFloat(xml, "y");
63 | float w = TmxHelper.GetAttributeAsFloat(xml, "width", 0);
64 | float h = TmxHelper.GetAttributeAsFloat(xml, "height", 0);
65 | float r = TmxHelper.GetAttributeAsFloat(xml, "rotation", 0);
66 | tmxObject.Position = new System.Drawing.PointF(x, y);
67 | tmxObject.Size = new System.Drawing.SizeF(w, h);
68 | tmxObject.Rotation = r;
69 |
70 | tmxObject.Properties = TmxProperties.FromXml(xml);
71 |
72 | tmxObject.InternalFromXml(xml, tmxMap);
73 |
74 | return tmxObject;
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxLayerNode.Xml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Linq;
8 |
9 | namespace Tiled2Unity
10 | {
11 | partial class TmxLayerNode : ITmxVisit
12 | {
13 | public static List ListFromXml(XElement xmlRoot, TmxLayerNode parent, TmxMap tmxMap)
14 | {
15 | List nodes = new List();
16 |
17 | foreach (var xmlNode in xmlRoot.Elements())
18 | {
19 | TmxLayerNode layerNode = null;
20 |
21 | if (xmlNode.Name == "layer" || xmlNode.Name == "imagelayer")
22 | {
23 | layerNode = TmxLayer.FromXml(xmlNode, parent, tmxMap);
24 | }
25 | else if (xmlNode.Name == "objectgroup")
26 | {
27 | layerNode = TmxObjectGroup.FromXml(xmlNode, parent, tmxMap);
28 | }
29 | else if (xmlNode.Name == "group")
30 | {
31 | layerNode = TmxGroupLayer.FromXml(xmlNode, parent, tmxMap);
32 | }
33 |
34 | // If the layer is visible then add it to our list
35 | if (layerNode != null && layerNode.Visible && layerNode.Ignore != IgnoreSettings.True)
36 | {
37 | nodes.Add(layerNode);
38 | }
39 | }
40 |
41 | return nodes;
42 | }
43 |
44 | protected void FromXmlInternal(XElement xml)
45 | {
46 | // Get common elements amoung layer nodes from xml
47 | this.Name = TmxHelper.GetAttributeAsString(xml, "name", "");
48 | this.Visible = TmxHelper.GetAttributeAsInt(xml, "visible", 1) == 1;
49 | this.Opacity = TmxHelper.GetAttributeAsFloat(xml, "opacity", 1);
50 |
51 | // Get the offset
52 | PointF offset = new PointF(0, 0);
53 | offset.X = TmxHelper.GetAttributeAsFloat(xml, "offsetx", 0);
54 | offset.Y = TmxHelper.GetAttributeAsFloat(xml, "offsety", 0);
55 | this.Offset = offset;
56 |
57 | // Get all the properties
58 | this.Properties = TmxProperties.FromXml(xml);
59 |
60 | // Set the "ignore" setting on this object group
61 | this.Ignore = this.Properties.GetPropertyValueAsEnum("unity:ignore", IgnoreSettings.False);
62 |
63 | // Explicit sorting properties
64 | this.ExplicitSortingLayerName = this.Properties.GetPropertyValueAsString("unity:sortingLayerName", "");
65 | if (this.Properties.PropertyMap.ContainsKey("unity:sortingOrder"))
66 | {
67 | this.ExplicitSortingOrder = this.Properties.GetPropertyValueAsInt("unity:sortingOrder");
68 | }
69 |
70 | // Are we using a unity:layer override?
71 | this.UnityLayerOverrideName = this.Properties.GetPropertyValueAsString("unity:layer", "");
72 |
73 | // Add all our children
74 | this.LayerNodes = TmxLayerNode.ListFromXml(xml, this, this.TmxMap);
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/build/ReadMe.txt:
--------------------------------------------------------------------------------
1 | Tiled2Unity Utility - http://www.seanba.com/IntroTiled2Unity.html
2 |
3 | About Tiled2Unity
4 | -------------------------------------------------------------------------------
5 |
6 | Tiled2Unity is a free utility that bridges the gap between Tiled Map Editor
7 | (http://www.mapeditor.org/) and the Unity Game Engine (http://www.unity3d.com/)
8 | for use in 2D Games.
9 |
10 | The purpose of Tiled2Unity is to provide 2D tiled-based level assets to your
11 | Unity game (collision supported) while being as simple as possible to use. For
12 | most users, you'll simply export your TMX files to your Unity project and drop
13 | the automatically generated prefabs into your scene.
14 |
15 | Collision geometry can be placed in your Tiled map as Polygon, Circle (note
16 | that ellipses are not supported), Rectangle, or Polyline objects in an Object
17 | Layer, but the real power comes from assigning Rectangles and/or Polygons to
18 | separate tiles which you place in your Tile Layers. The Tiled2Unity Utility
19 | will combine such geometry into one large PolygonCollider2D (per layer) in your
20 | Unity prefab.
21 |
22 | Note that polygons that are concave or contain holes *are* supported.
23 |
24 | Limitations
25 | -------------------------------------------------------------------------------
26 |
27 | Tiled Objects that are made of an ellipse must be circular (width and height
28 | equivalent) as Unity does not support elliptical colliders.
29 |
30 | As of build 0.9.10.0 Tiled2Unity supports isometric and hexagonal maps,
31 | however, Circle Tiled Objects are not supported in isometric map mode. They are
32 | supported in staggered isometric and hexagonal maps.
33 |
34 | Using Tiled2Unity
35 | -------------------------------------------------------------------------------
36 |
37 | 1. Get Tiled Map Editor
38 | http://www.mapeditor.org/
39 |
40 | 2. Import Tiled2Unity.unitypackage to your Unity project
41 | In Tiled2Unity, select "Help -> Import Unity Package to Project".
42 | Or, double-click on the Tiled2Unity.unitypackage found in your install
43 | directory.
44 |
45 | 3. Export a TMX File
46 | Run the Tiled2Unity Utility and open a Tiled TMX file. Select a Unity
47 | project to export to and hit the "Big Ass Export Button".
48 |
49 | 4. Use The Generated Prefab
50 | In Unity, find your new prefab in the Assets/Tiled2Unity/Prefabs folder. It
51 | will have the same name of your TMX file. Simply drop it into your Unity
52 | scene.
53 |
54 | Tips
55 | -------------------------------------------------------------------------------
56 |
57 | 1. For Tiled map files that contain collision, the Preview Exported Map button
58 | is handy for seeing how the Unity colliders will appear on the exported
59 | prefab.
60 |
61 | 2. Run Tiled2Unity from Tiled through the command feature within Tiled
62 | example command:
63 | "c:\Program Files (x86)\Tiled2Unity\Tiled2Unity.exe" %mapfile c:\my\project
64 | This will open Tiled2Unity from Tiled with the current map file. Prefabs
65 | will be exported to the Unity project at c:\my\project
66 |
67 | Support
68 | -------------------------------------------------------------------------------
69 |
70 | Found a bug? Let me know: sean@seanba.com
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Shaders/shaTiledMap.shader:
--------------------------------------------------------------------------------
1 | Shader "Tiled/TextureTintSnap"
2 | {
3 | Properties
4 | {
5 | [PerRendererData] _MainTex ("Tiled Texture", 2D) = "white" {}
6 | _Color ("Tint", Color) = (1,1,1,1)
7 | _AlphaColorKey ("Alpha Color Key", Color) = (0,0,0,0)
8 | [MaterialToggle] PixelSnap ("Pixel snap", Float) = 1
9 | }
10 |
11 | SubShader
12 | {
13 | Tags
14 | {
15 | "Queue"="Transparent"
16 | "IgnoreProjector"="True"
17 | "RenderType"="Transparent"
18 | "PreviewType"="Plane"
19 | "CanUseSpriteAtlas"="True"
20 | }
21 |
22 | Cull Off
23 | Lighting Off
24 | ZWrite Off
25 | Fog { Mode Off }
26 | Blend SrcAlpha OneMinusSrcAlpha
27 |
28 | Pass
29 | {
30 | CGPROGRAM
31 | #pragma vertex vert
32 | #pragma fragment frag
33 | #pragma multi_compile DUMMY PIXELSNAP_ON
34 | #include "UnityCG.cginc"
35 |
36 | struct appdata_t
37 | {
38 | float4 vertex : POSITION;
39 | float4 color : COLOR;
40 | float2 texcoord : TEXCOORD0;
41 | };
42 |
43 | struct v2f
44 | {
45 | float4 vertex : SV_POSITION;
46 | fixed4 color : COLOR;
47 | half2 texcoord : TEXCOORD0;
48 | };
49 |
50 |
51 | fixed4 _Color;
52 |
53 | v2f vert(appdata_t IN)
54 | {
55 | v2f OUT;
56 | OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
57 | OUT.texcoord = IN.texcoord;
58 | OUT.color = IN.color * _Color;
59 | #ifdef PIXELSNAP_ON
60 | OUT.vertex = UnityPixelSnap (OUT.vertex);
61 | #endif
62 |
63 | // Supports animations through z-component of tile
64 | if (IN.vertex.z < 0)
65 | {
66 | // "Hide" frames of a tile animation that are not active
67 | OUT.vertex.w = 0;
68 | }
69 | else
70 | {
71 | OUT.vertex.z = 0;
72 | }
73 |
74 | return OUT;
75 | }
76 |
77 | sampler2D _MainTex;
78 | float4 _AlphaColorKey;
79 |
80 | fixed4 frag(v2f IN) : COLOR
81 | {
82 | half4 texcol = tex2D(_MainTex, IN.texcoord);
83 |
84 | // The alpha color key is 'enabled' if it has solid alpha
85 | if (_AlphaColorKey.a == 1 &&
86 | _AlphaColorKey.r == texcol.r &&
87 | _AlphaColorKey.g == texcol.g &&
88 | _AlphaColorKey.b == texcol.b)
89 | {
90 | texcol.a = 0;
91 | }
92 | else
93 | {
94 | texcol = texcol * IN.color;
95 | }
96 |
97 | return texcol;
98 | }
99 | ENDCG
100 | }
101 | }
102 |
103 | Fallback "Sprites/Default"
104 | }
--------------------------------------------------------------------------------
/tool/Tiled2Unity/TestData/mini-tiles-collision.tsx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
40 |
41 |
42 |
45 |
46 |
47 |
48 |
49 |
52 |
53 |
54 |
55 |
56 |
59 |
60 |
61 |
62 |
63 |
66 |
67 |
68 |
69 |
70 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Editor/ImportTiled2Unity.Mesh.cs:
--------------------------------------------------------------------------------
1 | #if !UNITY_WEBPLAYER
2 | // Note: This parital class is not compiled in for WebPlayer builds.
3 | // The Unity Webplayer is deprecated. If you *must* use it then make sure Tiled2Unity assets are imported via another build target first.
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Xml;
10 | using System.Xml.Linq;
11 |
12 | using UnityEditor;
13 | using UnityEngine;
14 |
15 | using Path = System.IO.Path;
16 |
17 | namespace Tiled2Unity
18 | {
19 | // Handles a Mesh being imported.
20 | // At this point we should have everything we need to build out any prefabs for the tiled map object
21 | partial class ImportTiled2Unity
22 | {
23 | public void MeshImported(string objPath)
24 | {
25 | // Find the import behaviour that was waiting on this mesh to be imported
26 | string asset = Path.GetFileName(objPath);
27 | ImportBehaviour importComponent = ImportBehaviour.FindImportBehavior_ByWaitingMesh(asset);
28 | if (importComponent != null)
29 | {
30 | // The mesh has finished loading. Keep track of that status.
31 | if (!importComponent.ImportComplete_Meshes.Contains(asset, StringComparer.OrdinalIgnoreCase))
32 | {
33 | importComponent.ImportComplete_Meshes.Add(asset);
34 | }
35 |
36 | // Are we done importing all meshes? If so then start importing prefabs.
37 | if (importComponent.IsMeshImportingCompleted())
38 | {
39 | ImportAllPrefabs(importComponent);
40 | }
41 | }
42 | }
43 |
44 | private void ImportAllMeshes(Tiled2Unity.ImportBehaviour importComponent)
45 | {
46 | foreach (var xmlMesh in importComponent.XmlDocument.Root.Elements("ImportMesh"))
47 | {
48 | // We're going to create/write a file that contains our mesh data as a Wavefront Obj file
49 | // The actual mesh will be imported from this Obj file
50 | string file = ImportUtils.GetAttributeAsString(xmlMesh, "filename");
51 | string data = xmlMesh.Value;
52 |
53 | // Keep track of mesh we're going to import
54 | if (!importComponent.ImportWait_Meshes.Contains(file, StringComparer.OrdinalIgnoreCase))
55 | {
56 | importComponent.ImportWait_Meshes.Add(file);
57 | }
58 |
59 | // The data is in base64 format. We need it as a raw string.
60 | string raw = ImportUtils.Base64ToString(data);
61 |
62 | // Save and import the asset
63 | string pathToMesh = GetMeshAssetPath(importComponent.MapName, Path.GetFileNameWithoutExtension(file));
64 | ImportUtils.ReadyToWrite(pathToMesh);
65 | File.WriteAllText(pathToMesh, raw, Encoding.UTF8);
66 | importComponent.ImportTiled2UnityAsset(pathToMesh);
67 | }
68 |
69 | // If we have no meshes to import then go to next stage
70 | if (importComponent.ImportWait_Meshes.Count() == 0)
71 | {
72 | ImportAllPrefabs(importComponent);
73 | }
74 | }
75 |
76 | } // end class
77 | } // end namespace
78 | #endif
--------------------------------------------------------------------------------
/tool/Tiled2Unity/src/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Tiled2Unity.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tiled2Unity.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized resource of type System.Drawing.Bitmap.
65 | ///
66 | internal static System.Drawing.Bitmap mega_dad_stand {
67 | get {
68 | object obj = ResourceManager.GetObject("mega-dad-stand", resourceCulture);
69 | return ((System.Drawing.Bitmap)(obj));
70 | }
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Logger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | public class Logger
9 | {
10 | // Only to be printed in verbose mode. Useful for debugging.
11 | public delegate void WriteVerboseDelegate(string line);
12 | public static event WriteVerboseDelegate OnWriteVerbose;
13 |
14 | // These are always printed out whether verbose is enabled or not
15 | public delegate void WriteInfoDelegate(string line);
16 | public static event WriteInfoDelegate OnWriteInfo;
17 |
18 | public delegate void WriteSuccessDelegate(string line);
19 | public static event WriteSuccessDelegate OnWriteSuccess;
20 |
21 | public delegate void WriteWarningDelegate(string line);
22 | public static event WriteWarningDelegate OnWriteWarning;
23 |
24 | public delegate void WriteErrorDelegate(string line);
25 | public static event WriteErrorDelegate OnWriteError;
26 |
27 | public static void WriteVerbose()
28 | {
29 | WriteVerbose("");
30 | }
31 |
32 | public static void WriteVerbose(string line)
33 | {
34 | if (Tiled2Unity.Settings.Verbose)
35 | {
36 | line += "\n";
37 | if (OnWriteVerbose != null)
38 | OnWriteVerbose(line);
39 | }
40 | }
41 |
42 | public static void WriteVerbose(string fmt, params object[] args)
43 | {
44 | if (Tiled2Unity.Settings.Verbose)
45 | {
46 | WriteVerbose(String.Format(fmt, args));
47 | }
48 | }
49 |
50 | public static void WriteInfo()
51 | {
52 | WriteInfo("");
53 | }
54 |
55 | public static void WriteInfo(string line)
56 | {
57 | line += "\n";
58 | if (OnWriteInfo != null)
59 | OnWriteInfo(line);
60 | Console.Write(line);
61 | }
62 |
63 | public static void WriteInfo(string fmt, params object[] args)
64 | {
65 | WriteInfo(String.Format(fmt, args));
66 | }
67 |
68 | public static void WriteSuccess(string success)
69 | {
70 | success += "\n";
71 | if (OnWriteSuccess != null)
72 | OnWriteSuccess(success);
73 | Console.Write(success);
74 | }
75 |
76 | public static void WriteSuccess(string fmt, params object[] args)
77 | {
78 | WriteSuccess(String.Format(fmt, args));
79 | }
80 |
81 | public static void WriteWarning(string warning)
82 | {
83 | warning += "\n";
84 | if (OnWriteWarning != null)
85 | OnWriteWarning(warning);
86 | Console.Write(warning);
87 | }
88 |
89 | public static void WriteWarning(string fmt, params object[] args)
90 | {
91 | WriteWarning(String.Format(fmt, args));
92 | }
93 |
94 | public static void WriteError(string error)
95 | {
96 | error += "\n";
97 | if (OnWriteError != null)
98 | OnWriteError(error);
99 | Console.Write(error);
100 | }
101 |
102 | public static void WriteError(string fmt, params object[] args)
103 | {
104 | WriteError(String.Format(fmt, args));
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxTile.Xml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Xml;
7 | using System.Xml.Linq;
8 |
9 | namespace Tiled2Unity
10 | {
11 | // partial class methods that build tile data from xml
12 | partial class TmxTile
13 | {
14 | public void ParseTileXml(XElement elem, TmxMap tmxMap, uint firstId)
15 | {
16 | Logger.WriteVerbose("Parse tile data (gid = {0}, id {1}) ...", this.GlobalId, this.LocalId);
17 |
18 | this.Properties = TmxProperties.FromXml(elem);
19 |
20 | // Do we have an object group for this tile?
21 | XElement elemObjectGroup = elem.Element("objectgroup");
22 | if (elemObjectGroup != null)
23 | {
24 | this.ObjectGroup = TmxObjectGroup.FromXml(elemObjectGroup, null, tmxMap);
25 | FixTileColliderObjects(tmxMap);
26 | }
27 |
28 | // Is this an animated tile?
29 | XElement elemAnimation = elem.Element("animation");
30 | if (elemAnimation != null)
31 | {
32 | this.Animation = TmxAnimation.FromXml(elemAnimation, firstId);
33 | }
34 | }
35 |
36 | private void FixTileColliderObjects(TmxMap tmxMap)
37 | {
38 | // Objects inside of tiles are colliders that will be merged with the colliders on neighboring tiles.
39 | // In order to promote this merging we have to perform the following clean up operations ...
40 | // - All rectangles objects are made into polygon objects
41 | // - All polygon objects will have their rotations burned into the polygon points (and Rotation set to zero)
42 | // - All cooridinates will be "sanitized" to make up for floating point errors due to rotation and poor placement of colliders
43 | // (The sanitation will round all numbers to the nearest 1/256th)
44 |
45 | // Replace rectangles with polygons
46 | for (int i = 0; i < this.ObjectGroup.Objects.Count; i++)
47 | {
48 | TmxObject tmxObject = this.ObjectGroup.Objects[i];
49 | if (tmxObject is TmxObjectRectangle)
50 | {
51 | TmxObjectPolygon tmxObjectPolygon = TmxObjectPolygon.FromRectangle(tmxMap, tmxObject as TmxObjectRectangle);
52 | this.ObjectGroup.Objects[i] = tmxObjectPolygon;
53 | }
54 | }
55 |
56 | // Burn rotation into all polygon points, sanitizing the point locations as we go
57 | foreach (TmxObject tmxObject in this.ObjectGroup.Objects)
58 | {
59 | TmxHasPoints tmxHasPoints = tmxObject as TmxHasPoints;
60 | if (tmxHasPoints != null)
61 | {
62 | var pointfs = tmxHasPoints.Points.ToArray();
63 |
64 | // Rotate our points by the rotation and position in the object
65 | TmxMath.RotatePoints(pointfs, tmxObject);
66 |
67 | // Sanitize our points to make up for floating point precision errors
68 | pointfs = pointfs.Select(TmxMath.Sanitize).ToArray();
69 |
70 | // Set the points back into the object
71 | tmxHasPoints.Points = pointfs.ToList();
72 |
73 | // Zero out our rotation
74 | tmxObject.BakeRotation();
75 | }
76 | }
77 | }
78 |
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/SummaryReport.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Tiled2Unity
7 | {
8 | // Helper class that gathers success, warning and error messages and blasts them back out through logging when requested
9 | class SummaryReport
10 | {
11 | private string name = "";
12 | private List successes = new List();
13 | private List warnings = new List();
14 | private List errors = new List();
15 |
16 | public void Capture(string name)
17 | {
18 | Listen();
19 |
20 | this.name = name;
21 | this.successes.Clear();
22 | this.warnings.Clear();
23 | this.errors.Clear();
24 | }
25 |
26 | private delegate void LoggingDelegate(string message, params object[] args);
27 | public void Report()
28 | {
29 | // Stop listening because we're going to blast back out to the logging system
30 | Ignore();
31 |
32 | // Are we going to log as success, warnings, or errors?
33 | LoggingDelegate func = Logger.WriteSuccess;
34 | if (this.warnings.Count > 0)
35 | {
36 | func = Logger.WriteWarning;
37 | }
38 | if (this.errors.Count > 0)
39 | {
40 | func = Logger.WriteError;
41 | }
42 |
43 | // Write out the summary report
44 | string separator = new string('-', 80);
45 | Logger.WriteInfo(separator);
46 | func("{0} summary", this.name);
47 |
48 | // Add successes
49 | Logger.WriteInfo("Succeeded: {0}", this.successes.Count);
50 | foreach (var success in this.successes)
51 | {
52 | Logger.WriteSuccess(" {0}", success);
53 | }
54 |
55 | // Add warnings
56 | Logger.WriteInfo("Warnings: {0}", this.warnings.Count);
57 | foreach (var warn in this.warnings)
58 | {
59 | Logger.WriteWarning(" {0}", warn);
60 | }
61 |
62 | // Add errors
63 | Logger.WriteInfo("Errors: {0}", this.errors.Count);
64 | foreach (var error in this.errors)
65 | {
66 | Logger.WriteError(" {0}", error);
67 | }
68 |
69 | Logger.WriteInfo(separator);
70 | }
71 |
72 | private void Listen()
73 | {
74 | Logger.OnWriteSuccess += Logger_OnWriteSuccess;
75 | Logger.OnWriteWarning += Logger_OnWriteWarning;
76 | Logger.OnWriteError += Logger_OnWriteError;
77 | }
78 |
79 | private void Ignore()
80 | {
81 | Logger.OnWriteSuccess -= Logger_OnWriteSuccess;
82 | Logger.OnWriteWarning -= Logger_OnWriteWarning;
83 | Logger.OnWriteError -= Logger_OnWriteError;
84 | }
85 |
86 | private void Logger_OnWriteError(string line)
87 | {
88 | line = line.TrimEnd('\r', '\n');
89 | this.errors.Add(line);
90 | }
91 |
92 | private void Logger_OnWriteWarning(string line)
93 | {
94 | line = line.TrimEnd('\r', '\n');
95 | this.warnings.Add(line);
96 | }
97 |
98 | private void Logger_OnWriteSuccess(string line)
99 | {
100 | line = line.TrimEnd('\r', '\n');
101 | this.successes.Add(line);
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectPolygon.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public class TmxObjectPolygon : TmxObject, TmxHasPoints
11 | {
12 | public List Points { get; set; }
13 |
14 | public TmxObjectPolygon()
15 | {
16 | this.Points = new List();
17 | }
18 |
19 | public override RectangleF GetWorldBounds()
20 | {
21 | float xmin = float.MaxValue;
22 | float xmax = float.MinValue;
23 | float ymin = float.MaxValue;
24 | float ymax = float.MinValue;
25 |
26 | foreach (var p in this.Points)
27 | {
28 | xmin = Math.Min(xmin, p.X);
29 | xmax = Math.Max(xmax, p.X);
30 | ymin = Math.Min(ymin, p.Y);
31 | ymax = Math.Max(ymax, p.Y);
32 | }
33 |
34 | RectangleF bounds = new RectangleF(xmin, ymin, xmax - xmin, ymax - ymin);
35 | bounds.Offset(this.Position);
36 | return bounds;
37 | }
38 |
39 | protected override void InternalFromXml(System.Xml.Linq.XElement xml, TmxMap tmxMap)
40 | {
41 | var points = from pt in xml.Element("polygon").Attribute("points").Value.Split(' ')
42 | let x = float.Parse(pt.Split(',')[0])
43 | let y = float.Parse(pt.Split(',')[1])
44 | select new PointF(x, y);
45 |
46 | this.Points = points.ToList();
47 |
48 | // Test if polygons are counter clocksise
49 | // From: http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order
50 | float sum = 0.0f;
51 | for (int i = 1; i < this.Points.Count(); i++)
52 | {
53 | var p1 = this.Points[i - 1];
54 | var p2 = this.Points[i];
55 |
56 | float v = (p2.X - p1.X) * -(p2.Y + p1.Y);
57 | sum += v;
58 | }
59 |
60 | if (sum < 0)
61 | {
62 | // Winding of polygons is counter-clockwise. Reverse the list.
63 | this.Points.Reverse();
64 | }
65 | }
66 |
67 | protected override string InternalGetDefaultName()
68 | {
69 | return "PolygonObject";
70 | }
71 |
72 |
73 | public override string ToString()
74 | {
75 | StringBuilder pts = new StringBuilder();
76 | if (this.Points == null)
77 | {
78 | pts.Append("");
79 | }
80 | else
81 | {
82 | foreach (var p in this.Points)
83 | {
84 | pts.AppendFormat("({0}, {1})", p.X, p.Y);
85 | if (p != this.Points.Last())
86 | {
87 | pts.AppendFormat(", ");
88 | }
89 | }
90 | }
91 |
92 | return String.Format("{0} {1} {2} points=({3})", GetType().Name, GetNonEmptyName(), this.Position, pts.ToString());
93 | }
94 |
95 | public bool ArePointsClosed()
96 | {
97 | return true;
98 | }
99 |
100 | static public TmxObjectPolygon FromRectangle(TmxMap tmxMap, TmxObjectRectangle tmxRectangle)
101 | {
102 | TmxObjectPolygon tmxPolygon = new TmxObjectPolygon();
103 | TmxObject.CopyBaseProperties(tmxRectangle, tmxPolygon);
104 |
105 | tmxPolygon.Points = tmxRectangle.Points;
106 |
107 | return tmxPolygon;
108 | }
109 |
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/ThirdParty/LibTessDotNet/Sources/Dict.cs:
--------------------------------------------------------------------------------
1 | /*
2 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 | ** Copyright (C) 2011 Silicon Graphics, Inc.
4 | ** All Rights Reserved.
5 | **
6 | ** Permission is hereby granted, free of charge, to any person obtaining a copy
7 | ** of this software and associated documentation files (the "Software"), to deal
8 | ** in the Software without restriction, including without limitation the rights
9 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 | ** of the Software, and to permit persons to whom the Software is furnished to do so,
11 | ** subject to the following conditions:
12 | **
13 | ** The above copyright notice including the dates of first publication and either this
14 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be
15 | ** included in all copies or substantial portions of the Software.
16 | **
17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC.
20 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 | ** OR OTHER DEALINGS IN THE SOFTWARE.
23 | **
24 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not
25 | ** be used in advertising or otherwise to promote the sale, use or other dealings in
26 | ** this Software without prior written authorization from Silicon Graphics, Inc.
27 | */
28 | /*
29 | ** Original Author: Eric Veach, July 1994.
30 | ** libtess2: Mikko Mononen, http://code.google.com/p/libtess2/.
31 | ** LibTessDotNet: Remi Gillig, https://github.com/speps/LibTessDotNet
32 | */
33 |
34 | #if DOUBLE
35 | namespace LibTessDotNet.Double
36 | #else
37 | namespace LibTessDotNet
38 | #endif
39 | {
40 | internal class Dict where TValue : class
41 | {
42 | public class Node
43 | {
44 | internal TValue _key;
45 | internal Node _prev, _next;
46 |
47 | public TValue Key { get { return _key; } }
48 | public Node Prev { get { return _prev; } }
49 | public Node Next { get { return _next; } }
50 | }
51 |
52 | public delegate bool LessOrEqual(TValue lhs, TValue rhs);
53 |
54 | private LessOrEqual _leq;
55 | Node _head;
56 |
57 | public Dict(LessOrEqual leq)
58 | {
59 | _leq = leq;
60 |
61 | _head = new Node { _key = null };
62 | _head._prev = _head;
63 | _head._next = _head;
64 | }
65 |
66 | public Node Insert(TValue key)
67 | {
68 | return InsertBefore(_head, key);
69 | }
70 |
71 | public Node InsertBefore(Node node, TValue key)
72 | {
73 | do {
74 | node = node._prev;
75 | } while (node._key != null && !_leq(node._key, key));
76 |
77 | var newNode = new Node { _key = key };
78 | newNode._next = node._next;
79 | node._next._prev = newNode;
80 | newNode._prev = node;
81 | node._next = newNode;
82 |
83 | return newNode;
84 | }
85 |
86 | public Node Find(TValue key)
87 | {
88 | var node = _head;
89 | do {
90 | node = node._next;
91 | } while (node._key != null && !_leq(key, node._key));
92 | return node;
93 | }
94 |
95 | public Node Min()
96 | {
97 | return _head._next;
98 | }
99 |
100 | public void Remove(Node node)
101 | {
102 | node._next._prev = node._prev;
103 | node._prev._next = node._next;
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxLayerNode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Tiled2Unity
8 | {
9 | // There are several different "layer" types in Tiled that share some behaviour (tile layer, object layer, image layer, group layer)
10 | // (In Tiled2Unity we treat image layers as a special case of tile layer)
11 | public abstract partial class TmxLayerNode : TmxHasProperties
12 | {
13 | public enum IgnoreSettings
14 | {
15 | False, // Ingore nothing (layer fully-enabled)
16 | True, // Ignore everything (like layer doesn't exist)
17 | Collision, // Ignore collision on layer
18 | Visual, // Ignore visual on layer
19 | };
20 |
21 | public TmxLayerNode ParentNode { get; private set; }
22 | public TmxMap TmxMap { get; private set; }
23 |
24 | public string Name { get; protected set; }
25 | public bool Visible { get; protected set; }
26 | public float Opacity { get; protected set; }
27 | public PointF Offset { get; protected set; }
28 | public IgnoreSettings Ignore { get; protected set; }
29 |
30 | public TmxProperties Properties { get; protected set; }
31 |
32 | // Helps with drawing order. User can be explicit through unity:sortingLayerName and unity:sortingOrder properties.
33 | public string ExplicitSortingLayerName { get; set; }
34 | public int? ExplicitSortingOrder { get; set; }
35 |
36 | public int DrawOrderIndex { get; set; }
37 | public int DepthBufferIndex { get; set; }
38 |
39 | public string UnityLayerOverrideName { get; protected set; }
40 |
41 | // Layer nodes may have a list of other layer nodes
42 | public List LayerNodes { get; protected set; }
43 |
44 | public TmxLayerNode(TmxLayerNode parent, TmxMap tmxMap)
45 | {
46 | this.DrawOrderIndex = -1;
47 | this.DepthBufferIndex = -1;
48 | this.ParentNode = parent;
49 | this.TmxMap = tmxMap;
50 | this.LayerNodes = new List();
51 | }
52 |
53 | public PointF GetCombinedOffset()
54 | {
55 | PointF offset = this.Offset;
56 | TmxLayerNode parent = this.ParentNode;
57 | while (parent != null)
58 | {
59 | offset = TmxMath.AddPoints(offset, parent.Offset);
60 | parent = parent.ParentNode;
61 | }
62 |
63 | return offset;
64 | }
65 |
66 | public string GetSortingLayerName()
67 | {
68 | // Do we have our own sorting layer name?
69 | if (!String.IsNullOrEmpty(this.ExplicitSortingLayerName))
70 | return this.ExplicitSortingLayerName;
71 |
72 | // If not then rely on the parent
73 | if (this.ParentNode != null)
74 | {
75 | return this.ParentNode.GetSortingLayerName();
76 | }
77 |
78 | // Default is an empty string
79 | return "";
80 | }
81 |
82 | public int GetSortingOrder()
83 | {
84 | // Do we have our own explicit ordering?
85 | if (this.ExplicitSortingOrder.HasValue)
86 | {
87 | return this.ExplicitSortingOrder.Value;
88 | }
89 |
90 | // Use our draw order index
91 | return this.DrawOrderIndex;
92 | }
93 |
94 | public float GetRecursiveOpacity()
95 | {
96 | float parentOpacity = (this.ParentNode != null) ? this.ParentNode.GetRecursiveOpacity() : 1.0f;
97 | return this.Opacity * parentOpacity;
98 | }
99 |
100 | // The child class must implement Visit abstraction
101 | public abstract void Visit(ITmxVisitor visitor);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Editor/Tiled2UnityMenuItems.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | #if !UNITY_WEBPLAYER
9 | using System.Xml.Linq;
10 | #endif
11 |
12 | using UnityEditor;
13 | using UnityEngine;
14 |
15 | namespace Tiled2Unity
16 | {
17 | class Tiled2UnityMenuItems
18 | {
19 | #if !UNITY_WEBPLAYER
20 | // Convenience function for packaging this library
21 | [MenuItem("Tiled2Unity/Export Tiled2Unity Library ...")]
22 | static void ExportLibrary()
23 | {
24 | // Get the version from our Tiled2Unity.export.txt library data file
25 | TextAsset textAsset = AssetDatabase.LoadAssetAtPath("Assets/Tiled2Unity/Tiled2Unity.export.txt", typeof(TextAsset)) as TextAsset;
26 | XDocument xml = XDocument.Parse(textAsset.text);
27 | string version = xml.Element("Tiled2UnityImporter").Element("Header").Attribute("version").Value;
28 |
29 | // Export the package
30 | string name = String.Format("Tiled2Unity.{0}.unitypackage", version);
31 | var path = EditorUtility.SaveFilePanel("Save Tiled2Unity library as unity package.", "", name, "unitypackage");
32 | if (path.Length != 0)
33 | {
34 | List packageFiles = new List();
35 |
36 | // Export all C# files, shaders, text files, and some select materials
37 | packageFiles.AddRange(EnumerateAssetFilesAt("Assets/Tiled2Unity",".cs", ".shader", ".cginc", ".txt", "t2uSprite-Depth.mat", "t2uSprite-DiffuseDepth.mat"));
38 | AssetDatabase.ExportPackage(packageFiles.ToArray(), path);
39 | }
40 | }
41 | #endif
42 |
43 | // Not ready for public consumption yet. (But handy to have for development)
44 | //[MenuItem("Tiled2Unity/Clean Tiled2Unity Files")]
45 | //static void CleanFiles()
46 | //{
47 | // Debug.LogWarning("Cleaning out Tiled2Unity files that were automatically created. Re-import your *.tiled2unity.xml files to re-create them.");
48 | // DeleteAssetsAt("Assets/Tiled2Unity/Materials");
49 | // DeleteAssetsAt("Assets/Tiled2Unity/Meshes");
50 | // DeleteAssetsAt("Assets/Tiled2Unity/Prefabs");
51 | // DeleteAssetsAt("Assets/Tiled2Unity/Textures");
52 | //}
53 |
54 | private static IEnumerable EnumerateAssetFilesAt(string dir, params string[] endPatterns)
55 | {
56 | foreach (string f in Directory.GetFiles(dir))
57 | {
58 | if (endPatterns.Any(pat => f.EndsWith(pat, true, null)))
59 | {
60 | yield return f;
61 | }
62 | }
63 |
64 | foreach (string d in Directory.GetDirectories(dir))
65 | {
66 | foreach (string f in EnumerateAssetFilesAt(d, endPatterns))
67 | {
68 | yield return f;
69 | }
70 | }
71 | }
72 |
73 | private static void DeleteAssetsAt(string dir)
74 | {
75 | // Note: Does not remove any text files.
76 | foreach (string f in Directory.GetFiles(dir))
77 | {
78 | if (f.EndsWith(".txt", true, null))
79 | continue;
80 |
81 | if (f.EndsWith(".meta", true, null))
82 | continue;
83 |
84 | // Just to be safe. Do not remove scripts.
85 | if (f.EndsWith(".cs", true, null))
86 | continue;
87 |
88 | // Do not remove special materials
89 | if (f.EndsWith("t2uSprite-Depth.mat", true, null))
90 | continue;
91 | if (f.EndsWith("t2uSprite-DiffuseDepth.mat", true, null))
92 | continue;
93 |
94 | AssetDatabase.DeleteAsset(f);
95 | }
96 | }
97 |
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/TmxClasses/TmxObjectTile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Tiled2Unity
8 | {
9 | public class TmxObjectTile : TmxObject
10 | {
11 | public TmxTile Tile { get; private set; }
12 | public bool FlippedHorizontal { get; private set; }
13 | public bool FlippedVertical { get; private set; }
14 |
15 | public int DrawOrderIndex { get; set; }
16 | public int DepthIndex { get; set; }
17 |
18 | private string ExplicitSortingLayerName { get; set; }
19 | private int? ExplicitSortingOrder { get; set; }
20 |
21 | public TmxObjectTile()
22 | {
23 | this.DrawOrderIndex = -1;
24 | this.DepthIndex = -1;
25 | this.ExplicitSortingLayerName = "";
26 | }
27 |
28 | public override System.Drawing.RectangleF GetWorldBounds()
29 | {
30 | RectangleF myBounds = new RectangleF(this.Position.X, this.Position.Y - this.Size.Height, this.Size.Width, this.Size.Height);
31 |
32 | RectangleF groupBounds = this.Tile.ObjectGroup.GetWorldBounds(this.Position);
33 | if (groupBounds.IsEmpty)
34 | {
35 | return myBounds;
36 | }
37 | RectangleF combinedBounds = RectangleF.Union(myBounds, groupBounds);
38 | return combinedBounds;
39 | }
40 |
41 | public override string ToString()
42 | {
43 | return String.Format("{{ TmxObjectTile: name={0}, pos={1}, tile={2} }}", GetNonEmptyName(), this.Position, this.Tile);
44 | }
45 |
46 | public SizeF GetTileObjectScale()
47 | {
48 | float scaleX = this.Size.Width / this.Tile.TileSize.Width;
49 | float scaleY = this.Size.Height / this.Tile.TileSize.Height;
50 | return new SizeF(scaleX, scaleY);
51 | }
52 |
53 | public string GetSortingLayerName()
54 | {
55 | // Do we have our own sorting layer name?
56 | if (!String.IsNullOrEmpty(this.ExplicitSortingLayerName))
57 | return this.ExplicitSortingLayerName;
58 |
59 | return this.ParentObjectGroup.GetSortingLayerName();
60 | }
61 |
62 | public int GetSortingOrder()
63 | {
64 | // Do we have our own explicit ordering?
65 | if (this.ExplicitSortingOrder.HasValue)
66 | {
67 | return this.ExplicitSortingOrder.Value;
68 | }
69 |
70 | // Use our draw order index
71 | return this.DrawOrderIndex;
72 | }
73 |
74 | protected override void InternalFromXml(System.Xml.Linq.XElement xml, TmxMap tmxMap)
75 | {
76 | // Get the tile
77 | uint gid = TmxHelper.GetAttributeAsUInt(xml, "gid");
78 | this.FlippedHorizontal = TmxMath.IsTileFlippedHorizontally(gid);
79 | this.FlippedVertical = TmxMath.IsTileFlippedVertically(gid);
80 | uint rawTileId = TmxMath.GetTileIdWithoutFlags(gid);
81 |
82 | this.Tile = tmxMap.Tiles[rawTileId];
83 |
84 | // The tile needs to have a mesh on it.
85 | // Note: The tile may already be referenced by another TmxObjectTile instance, and as such will have its mesh data already made
86 | if (this.Tile.Meshes.Count() == 0)
87 | {
88 | this.Tile.Meshes = TmxMesh.FromTmxTile(this.Tile, tmxMap);
89 | }
90 |
91 | // Check properties for layer placement
92 | this.ExplicitSortingLayerName = this.Properties.GetPropertyValueAsString("unity:sortingLayerName", "");
93 | if (this.Properties.PropertyMap.ContainsKey("unity:sortingOrder"))
94 | {
95 | this.ExplicitSortingOrder = this.Properties.GetPropertyValueAsInt("unity:sortingOrder");
96 | }
97 | }
98 |
99 | protected override string InternalGetDefaultName()
100 | {
101 | return "TileObject";
102 | }
103 |
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/unity/Tiled2Unity/Scripts/Runtime/TiledMap.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | using UnityEngine;
7 |
8 | namespace Tiled2Unity
9 | {
10 | public class TiledMap : MonoBehaviour
11 | {
12 | public enum MapOrientation
13 | {
14 | Orthogonal,
15 | Isometric,
16 | Staggered,
17 | Hexagonal,
18 | }
19 |
20 | public enum MapStaggerAxis
21 | {
22 | X,
23 | Y,
24 | }
25 |
26 | public enum MapStaggerIndex
27 | {
28 | Odd,
29 | Even,
30 | }
31 |
32 | public MapOrientation Orientation = MapOrientation.Orthogonal;
33 | public MapStaggerAxis StaggerAxis = MapStaggerAxis.X;
34 | public MapStaggerIndex StaggerIndex = MapStaggerIndex.Odd;
35 | public int HexSideLength = 0;
36 |
37 | public int NumLayers = 0;
38 | public int NumTilesWide = 0;
39 | public int NumTilesHigh = 0;
40 | public int TileWidth = 0;
41 | public int TileHeight = 0;
42 | public float ExportScale = 1.0f;
43 |
44 | // Note: Because maps can be isometric and staggered we simply can't multiply tile width (or height) by number of tiles wide (or high) to get width (or height)
45 | // We rely on the exporter to calculate the width and height of the map
46 | public int MapWidthInPixels = 0;
47 | public int MapHeightInPixels = 0;
48 |
49 | // Background color could be used to set the camera clear color to get the same effect as in Tiled
50 | public Color BackgroundColor = Color.black;
51 |
52 | public float GetMapWidthInPixelsScaled()
53 | {
54 | return this.MapWidthInPixels * this.transform.lossyScale.x * this.ExportScale;
55 | }
56 |
57 | public float GetMapHeightInPixelsScaled()
58 | {
59 | return this.MapHeightInPixels * this.transform.lossyScale.y * this.ExportScale;
60 | }
61 |
62 | public Rect GetMapRect()
63 | {
64 | Vector2 pos_w = this.gameObject.transform.position;
65 | float width = this.MapWidthInPixels;
66 | float height = this.MapHeightInPixels;
67 | return new Rect(pos_w.x, pos_w.y - height, width, height);
68 | }
69 |
70 | public Rect GetMapRectInPixelsScaled()
71 | {
72 | Vector2 pos_w = this.gameObject.transform.position;
73 | float widthInPixels = GetMapWidthInPixelsScaled();
74 | float heightInPixels = GetMapHeightInPixelsScaled();
75 | return new Rect(pos_w.x, pos_w.y - heightInPixels, widthInPixels, heightInPixels);
76 | }
77 |
78 | public bool AreTilesStaggered()
79 | {
80 | // Hex and Iso Staggered maps both use "staggered" tiles
81 | return this.Orientation == MapOrientation.Staggered || this.Orientation == MapOrientation.Hexagonal;
82 | }
83 |
84 | private void OnDrawGizmosSelected()
85 | {
86 | Vector3 pos_w = this.gameObject.transform.position;
87 | Vector3 topLeft = Vector3.zero + pos_w;
88 | Vector3 topRight = new Vector3(GetMapWidthInPixelsScaled(), 0) + pos_w;
89 | Vector3 bottomRight = new Vector3(GetMapWidthInPixelsScaled(), -GetMapHeightInPixelsScaled()) + pos_w;
90 | Vector3 bottomLeft = new Vector3(0, -GetMapHeightInPixelsScaled()) + pos_w;
91 |
92 | // To make gizmo visible, even when using depth-shader shaders, we decrease the z depth by the number of layers
93 | float depth_z = -1.0f * this.NumLayers;
94 | pos_w.z += depth_z;
95 | topLeft.z += depth_z;
96 | topRight.z += depth_z;
97 | bottomRight.z += depth_z;
98 | bottomLeft.z += depth_z;
99 |
100 | Gizmos.color = Color.blue;
101 | Gizmos.DrawLine(topLeft, topRight);
102 | Gizmos.DrawLine(topRight, bottomRight);
103 | Gizmos.DrawLine(bottomRight, bottomLeft);
104 | Gizmos.DrawLine(bottomLeft, topLeft);
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/tool/Tiled2Unity/Tiled2UnityLib/Geometry/CompositionPolygon.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace Tiled2Unity.Geometry
10 | {
11 | // For compositional considerations, a Polygon is a group of points and edges
12 | // This allows us to merge polygons along edges
13 | public class CompositionPolygon
14 | {
15 | public int InitialId { get; private set; }
16 | public List Points { get; private set; }
17 | public List Edges { get; private set; }
18 |
19 | // A polygon starts off as a triangle with one edge
20 | // Other points and edges are added to the polygon during merge
21 | public CompositionPolygon(IEnumerable points, int initialId)
22 | {
23 | this.InitialId = initialId;
24 | this.Points = new List();
25 | this.Edges = new List();
26 |
27 | this.Points.AddRange(points);
28 | }
29 |
30 | public void AddEdge(PolygonEdge edge)
31 | {
32 | this.Edges.Add(edge);
33 | }
34 |
35 | public int NextIndex(int index)
36 | {
37 | Debug.Assert(index >= 0);
38 |
39 | return (index + 1) % this.Points.Count;
40 | }
41 |
42 | public int PrevIndex(int index)
43 | {
44 | Debug.Assert(index >= 0);
45 |
46 | if (index == 0)
47 | {
48 | return this.Points.Count - 1;
49 | }
50 |
51 | return (index - 1) % this.Points.Count;
52 | }
53 |
54 | public PointF NextPoint(int index)
55 | {
56 | index = NextIndex(index);
57 | return this.Points[index];
58 | }
59 |
60 | public PointF PrevPoint(int index)
61 | {
62 | index = PrevIndex(index);
63 | return this.Points[index];
64 | }
65 |
66 | public void AbsorbPolygon(int q, CompositionPolygon minor, int pMinor)
67 | {
68 | // Insert Minor points Minor[P+1] ... Minor[Q-1] into Major, inserted at Major[Q]
69 | // Same as inserting numPoints-2 starting at index qMinor+1
70 | int numMinorPoints = minor.Points.Count - 2;
71 |
72 | List pointsToInsert = new List();
73 | for (int i = 0; i < numMinorPoints; ++i)
74 | {
75 | int qInsert = (pMinor + 1 + i) % minor.Points.Count;
76 | pointsToInsert.Add(minor.Points[qInsert]);
77 | }
78 |
79 | this.Points.InsertRange(q, pointsToInsert);
80 |
81 | // Absorb the edges from our minor polygon too so that future absoptions carry through
82 | foreach (var minorEdge in minor.Edges)
83 | {
84 | if (!this.Edges.Contains(minorEdge))
85 | {
86 | this.Edges.Add(minorEdge);
87 | }
88 | }
89 | }
90 |
91 | public void ReplaceEdgesWithPolygon(CompositionPolygon replacement, PolygonEdge ignoreEdge)
92 | {
93 | // This polygon is going away as it was merged with another
94 | // All edges this polygon referenced will need to reference the replacement instead
95 | foreach (var edge in this.Edges)
96 | {
97 | if (edge == ignoreEdge)
98 | continue;
99 |
100 | Debug.Assert(!(edge.MajorPartner == this && edge.MinorPartner == this));
101 |
102 | if (edge.MajorPartner == this)
103 | {
104 | edge.ReplaceMajor(replacement);
105 | }
106 | else if (edge.MinorPartner == this)
107 | {
108 | edge.ReplaceMinor(replacement);
109 | }
110 | }
111 | }
112 |
113 | public void UpdateEdgeIndices(PolygonEdge ignoreEdge)
114 | {
115 | // All of our edges need to update their indices to us
116 | foreach (var edge in this.Edges)
117 | {
118 | if (edge == ignoreEdge)
119 | continue;
120 |
121 | edge.UpdateIndices(this);
122 | }
123 | }
124 |
125 |
126 | }
127 | }
128 |
--------------------------------------------------------------------------------