Skip to content

Commit

Permalink
Merge branch 'develop' into feature/asepriteSupport-2
Browse files Browse the repository at this point in the history
# Conflicts:
#	Assets/LDtkUnity/Editor/LDtkUnity.Editor.asmdef
#	Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs
  • Loading branch information
Cammin committed Sep 29, 2023
2 parents a048274 + 505838e commit 64d9c81
Show file tree
Hide file tree
Showing 125 changed files with 3,977 additions and 1,724 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
tests:
name: Test-${{ matrix.testMode }}-${{ matrix.unityVersion }}
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
Expand All @@ -20,7 +21,7 @@ jobs:
- 2020.3.48f1
- 2021.3.29f1
- 2022.3.7f1
- 2023.1.0f1
- 2023.1.15f1

steps:
#Test Checkout
Expand Down Expand Up @@ -61,19 +62,26 @@ jobs:
builds:
name: Build-${{ matrix.targetPlatform }}-${{ matrix.unityVersion }}
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
targetPlatform:
- StandaloneWindows
- WebGL
#- WebGL
unityVersion:
- 2019.3.15f1
- 2019.4.40f1
- 2020.3.48f1
- 2021.3.29f1
- 2022.3.7f1
- 2023.1.0f1
include:
- targetPlatform: WebGL
unityVersion: 2019.3.15f1
- targetPlatform: WebGL
unityVersion: 2023.1.15f1


steps:
#Build Checkout
Expand Down
10 changes: 8 additions & 2 deletions Assets/LDtkUnity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# 4.0.2
###### September 28, 2023
- Added safety-check if a tileset definition's relPath was null or empty

# 4.0.1
###### September 22, 2023
- Updated json support for LDtk 1.4
###### September 28, 2023
- Updated json support for [LDtk 1.4](https://ldtk.io/json/#changes;1.4.0)
- Fixed a compile error if Unity's Aseprite importer is also installed
- Fixed an issue where the tileset file export app wasn't able to run on MacOS
- Swapped the order of the TilemapCollider2D and CompositeCollider2D in layers to resolve a [physics issue](https://forum.unity.com/threads/tilemap-collider-with-composite-doesnt-work-with-particle-system-collision-trigger.833737/#post-9173561) for particles
- Updated the docs with content for the 4.0.0 update, among other tweaks

# 4.0.0
###### September 22, 2023
Expand Down
8 changes: 6 additions & 2 deletions Assets/LDtkUnity/Editor/Builders/LDtkBuilderLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ protected void AddLayerOffset(Tilemap tilemap)

protected void AddTilemapCollider(GameObject tilemapGameObject)
{
TilemapCollider2D collider = tilemapGameObject.AddComponent<TilemapCollider2D>();
//intentionally making the order of the composite collider first because of issues with physics particles:
//https://forum.unity.com/threads/tilemap-collider-with-composite-doesnt-work-with-particle-system-collision-trigger.833737/#post-9173561

if (Project.UseCompositeCollider)
{
Expand All @@ -62,13 +63,16 @@ protected void AddTilemapCollider(GameObject tilemapGameObject)
CompositeCollider2D composite = tilemapGameObject.AddComponent<CompositeCollider2D>();
composite.geometryType = Project.GeometryType;

TilemapCollider2D collider = tilemapGameObject.AddComponent<TilemapCollider2D>();
#if UNITY_2023_1_OR_NEWER
collider.compositeOperation = Collider2D.CompositeOperation.Merge;
#else
collider.usedByComposite = true;
#endif

return;
}

tilemapGameObject.AddComponent<TilemapCollider2D>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@ public LDtkEditorCommandUpdater(string projectPath)
private string GetCommand()
{
string fromPath = LDtkPathUtility.AssetsPathToAbsolutePath(ProjectPath);


#if UNITY_EDITOR_OSX
//if mac, we're launching a different file that's meant to launch the exe
string appPath = LDtkTilesetExporterUtil.PathToMacSh();
#else
string appPath = LDtkTilesetExporterUtil.PathToExe();

var relPath = LDtkPathUtility.GetRelativePath(fromPath, appPath);
//backslashes break deserialization
relPath = LDtkPathUtility.CleanPathSlashes(relPath);
#endif

var commandContent = LDtkPathUtility.GetRelativePath(fromPath, appPath);
//backslashes break deserialization
commandContent = LDtkPathUtility.CleanPathSlashes(commandContent);

//Debug.Log($"fromPath {fromPath}");
//Debug.Log($"appPath {appPath}");
//Debug.Log($"relPath {relPath}");

#if UNITY_EDITOR_OSX
//on mac, the command needs to have this in the front: sudo chmod a+x <your sub command file>
relPath = "sudo chmod a+x " + relPath;
#endif

return relPath;
return commandContent;
}

public void TryDrawFixButton(LdtkJson data)
Expand All @@ -47,11 +49,6 @@ public void TryDrawFixButton(LdtkJson data)
return;
}

if (HasCustomCommand(data, out var reason))
{
return;
}

if (!IsInstalled(out var installReason))
{
using (new EditorGUILayout.HorizontalScope())
Expand Down Expand Up @@ -82,6 +79,11 @@ public void TryDrawFixButton(LdtkJson data)
return;
}

if (HasCustomCommand(data, out var reason))
{
return;
}

using (new EditorGUILayout.HorizontalScope())
{
EditorGUIUtility.SetIconSize(Vector2.one * 32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
internal static class LDtkImporterConsts
{
public const int PROJECT_VERSION = 25;
public const int LEVEL_VERSION = 9;
public const int PROJECT_VERSION = 26;
public const int LEVEL_VERSION = 10;
public const int TILESET_VERSION = 2;
public const string LDTK_JSON_VERSION = "1.3.0";
public const string EXPORT_APP_VERSION_REQUIRED = "1.0.0.0";
Expand Down
21 changes: 16 additions & 5 deletions Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private static string[] GatherDependenciesFromSourceFile(string path)
}

//this depends on the texture
//todo add a digger for getting the RelPath
LDtkProfiler.BeginSample($"GatherDependenciesFromSourceFile/{Path.GetFileName(path)}");
string texPath = PathToTexture(path);
texPath = !File.Exists(texPath) ? string.Empty : texPath;
Expand Down Expand Up @@ -415,7 +416,13 @@ private bool DeserializeAndAssign()
return false;
}

Profiler.BeginSample("GetTextureImporter");
if (_json.RelPath.IsNullOrEmpty())
{
Logger.LogError($"The tileset relative path was null or empty! Try fixing the Tileset path in the LDtk editor for \"{assetPath}\"");
return false;
}

Profiler.BeginSample("CacheTextureImporterOrAsepriteImporter");
if (!CacheTextureImporterOrAsepriteImporter())
{
Profiler.EndSample();
Expand All @@ -439,7 +446,7 @@ private bool DeserializeAndAssign()

private bool CacheTextureImporterOrAsepriteImporter()
{
string path = PathToTexture(assetPath);
string path = PathToTexture(assetPath, _json);

//First check embed atlas
if (_json.IsEmbedAtlas && path.IsNullOrEmpty())
Expand Down Expand Up @@ -481,9 +488,13 @@ private bool CacheTextureImporterOrAsepriteImporter()
/// <summary>
/// Only use when needed, it performs a deserialize. look at optimizing if it's expensive
/// </summary>
private static string PathToTexture(string assetPath)
private static string PathToTexture(string assetPath, TilesetDefinition def = null)
{
TilesetDefinition def = FromJson<LDtkTilesetDefinition>(assetPath).Def;
if (def == null)
{
def = FromJson<LDtkTilesetDefinition>(assetPath).Def;
}

if (def.IsEmbedAtlas)
{
string iconsPath = LDtkProjectSettings.InternalIconsTexturePath;
Expand Down Expand Up @@ -582,7 +593,7 @@ private bool HasTextureIssue(TextureImporter textureImporter, TextureImporterPla

private Texture2D LoadTex(bool forceLoad = false)
{
//in case the importer was destroyed via file delete
//this is important: in case the importer was destroyed via file delete
if (this == null)
{
return null;
Expand Down
21 changes: 19 additions & 2 deletions Assets/LDtkUnity/Editor/Utility/LDtkTilesetExporterUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ internal static class LDtkTilesetExporterUtil
{
private const string EXPORT_ZIP = "LDtkTilesetExporter.zip";
private const string EXPORT_APP = "ExportTilesetDefinition.exe";
private const string MAC_APP = "ExportTilesetDefinitionMac.sh";

//[MenuItem("UnzipToProject/Unzip")]
public static void UnzipToLibrary()
{
string pathToZip = PathToZip();

string destDir = PathToLibraryDir();


LDtkPathUtility.TryCreateDirectory(destDir);
if (Directory.Exists(destDir))
{
Expand All @@ -33,6 +32,19 @@ public static void UnzipToLibrary()
Debug.Assert(Directory.Exists(destDir), "Directory.Exists(destDir)");

ZipUtil.Extract(pathToZip, destDir);

#if UNITY_EDITOR_OSX
string pathToExe = PathToExe();

//if mac, we need to create a shell script to run the exe
string shPath = Path.Combine(destDir, MAC_APP);
string shContent = $"#!/bin/sh\n /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono {pathToExe}";
File.WriteAllText(shPath, shContent);

//on mac, the app needs some permission. Use "sudo chmod +x"
Process.Start("/bin/bash", $"-c \" chmod +x {shPath}\" ");
#endif

LDtkDebug.Log($"Extracted the tileset export app to \"{destDir}\"");
}

Expand Down Expand Up @@ -71,6 +83,11 @@ public static string PathToExe()
string exePath = Path.Combine(PathToLibraryDir(), EXPORT_APP);
return exePath;
}
public static string PathToMacSh()
{
string exePath = Path.Combine(PathToLibraryDir(), MAC_APP);
return exePath;
}

public static bool GetAppUpToDate()
{
Expand Down
8 changes: 4 additions & 4 deletions Assets/LDtkUnity/Runtime/Fields/LDtkFieldsPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public partial class LDtkFields
#region Multiline

/// <summary>
/// Gets a multiline field's value.
/// Gets a multiline field's value. IMPORTANT: Make sure that the LDtk project is configured to use "Multilines" in it's advanced settings
/// </summary>
/// <param name="identifier">
/// The field instance's identifier. Case sensitive.
Expand All @@ -231,7 +231,7 @@ public partial class LDtkFields
public string GetMultiline(string identifier) => GetFieldSingle(identifier, LDtkFieldType.Multiline, element => element.GetMultilineValue());

/// <summary>
/// Gets a multiline field's value.
/// Gets a multiline field's value. IMPORTANT: Make sure that the LDtk project is configured to use "Multilines" in it's advanced settings
/// </summary>
/// <param name="identifier">
/// The field instance's identifier. Case sensitive.
Expand All @@ -245,7 +245,7 @@ public partial class LDtkFields
public bool TryGetMultiline(string identifier, out string value) => TryGetFieldSingle(identifier, LDtkFieldType.Multiline, element => element.GetMultilineValue(), out value);

/// <summary>
/// Gets a multiline field's values.
/// Gets a multiline field's values. IMPORTANT: Make sure that the LDtk project is configured to use "Multilines" in it's advanced settings
/// </summary>
/// <param name="identifier">
/// The field instance's identifier. Case sensitive.
Expand All @@ -256,7 +256,7 @@ public partial class LDtkFields
public string[] GetMultilineArray(string identifier) => GetFieldArray(identifier, LDtkFieldType.Multiline, element => element.GetMultilineValue());

/// <summary>
/// Gets a multiline field's values.
/// Gets a multiline field's values. IMPORTANT: Make sure that the LDtk project is configured to use "Multilines" in it's advanced settings
/// </summary>
/// <param name="identifier">
/// The field instance's identifier. Case sensitive.
Expand Down
6 changes: 3 additions & 3 deletions Assets/LDtkUnity/Runtime/Tools/Const/LDtkHelpUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ internal static class LDtkHelpURL
public const string IMPORTER_LDTK_LEVEL =
ROOT + "documentation/Importer/topic_LevelImporter.html";
public const string IMPORTER_LDTK_TILESET =
ROOT + "documentation/Importer/topic_TilesetImporter.html"; //todo this doesnt exist yet, ensure it does
ROOT + "documentation/Importer/topic_TilesetImporter.html";

public const string JSON_PROJECT =
ROOT + "documentation/Topics/topic_ProjectFile.html";
public const string JSON_LEVEL =
ROOT + "documentation/Topics/topic_LevelFile.html";
public const string JSON_TILESET =
ROOT + "documentation/Topics/topic_TilesetFile.html"; //todo this doesnt exist yet, ensure it does
ROOT + "documentation/Topics/topic_TilesetFile.html";

//section contents
public const string SECTION_MAIN =
Expand Down Expand Up @@ -60,7 +60,7 @@ internal static class LDtkHelpURL
public const string SO_INT_GRID_TILE =
ROOT + "documentation/Topics/topic_IntGridTile.html";
public const string SO_TILESET_TILE =
ROOT + "documentation/Topics/topic_ArtifactAssets.html";
ROOT + "documentation/Importer/topic_TilesetImporter.html";
public const string SO_TOC =
ROOT + "documentation/Topics/topic_TableOfContents.html";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace LDtkUnity
{
/// <summary>
/// Stores the autogenerated tiles/sprites for tilesets.
/// </summary>
[HelpURL(LDtkHelpURL.SO_ARTIFACT_ASSETS)]
public sealed class LDtkArtifactAssetsTileset : ScriptableObject
{
internal const string PROPERTY_SPRITE_LIST = nameof(_sprites);
Expand Down
2 changes: 1 addition & 1 deletion Assets/LDtkUnity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.cammin.ldtkunity",
"version": "4.0.0",
"version": "4.0.1",
"displayName": "LDtk to Unity",
"description": "A Unity importer system for the Level Designer Toolkit.",
"documentationUrl": "https://cammin.github.io/LDtkToUnity/",
Expand Down
3 changes: 3 additions & 0 deletions DocFX/documentation/Importer/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- name: Level Importer
href: topic_LevelImporter.md

- name: Tileset Importer
href: topic_TilesetImporter.md

- name: Main
href: topic_Section_Main.md

Expand Down
2 changes: 1 addition & 1 deletion DocFX/documentation/Importer/topic_LevelImporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The project can also be re-imported from here with a quick button.
![Level Importer](../../images/img_Unity_LevelImporter.png)

### Depend On Dependencies
Used by both project and level. [See here.](topic_Section_Dependencies.md#depend-on-dependencies)
Used by all LDtk assets. [See here.](topic_Section_Dependencies.md#depend-on-dependencies)

## Nested Prefabs
Imported LDtk levels can be nested in prefabs.
Expand Down
13 changes: 2 additions & 11 deletions DocFX/documentation/Importer/topic_ProjectImporter.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
# Project Importer

Store the LDtk project file in the Unity project so that it can be imported.

The file format must be `.ldtk`.
![Use Extension](../../images/img_ldtk_UseLDtkExtension.png)

**Simply drag-and-drop this main asset into the scene.**
![Drag-N-Drop](../../images/gif_DragNDrop.gif)
Also, double clicking the LDtk file in the project window will conveniently open the project in LDtk.

## Inspector
The importer inspector is composed of several sections:
[**Main**](topic_Section_Main.md),
[**IntGrids**](topic_Section_IntGrids.md),
[**Entities**](topic_Section_Entities.md),
and [**Enums**](topic_Section_Enums.md).
[**Enums**](topic_Section_Enums.md),
and [**Dependencies**](topic_Section_Dependencies.md).
![Inspector](../../images/img_Unity_ProjectAsset.png)
- After making any changes, click the apply button at the bottom to reimport.
- If any section is hidden, it's because there were no associated definitions in the LDtk project.


## Hierarchy
The imported project generates a hierarchy of GameObjects.
All of the objects have accompanying scripts that contain useful data.
Expand Down
Loading

0 comments on commit 64d9c81

Please sign in to comment.