diff --git a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TiledAssetImporter.cs b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TiledAssetImporter.cs index 9253f2a9..2c45a831 100644 --- a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TiledAssetImporter.cs +++ b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TiledAssetImporter.cs @@ -61,7 +61,7 @@ public void AddSuperCustomProperties(GameObject go, XElement xProperties, SuperT component.m_Properties = properties.OrderBy(p => p.m_Name).ToList(); AssignUnityTag(component); - AssignUnityLayer(component); + AssignUnityLayer(component, defaultInheritFromParent: true); } public void AssignTilemapSorting(TilemapRenderer renderer) @@ -146,7 +146,7 @@ protected void AssignUnityTag(SuperCustomProperties properties) } } - protected void AssignUnityLayer(SuperCustomProperties properties) + protected void AssignUnityLayer(SuperCustomProperties properties, bool defaultInheritFromParent) { // Do we have a 'unity:layer' property? CustomProperty prop; @@ -163,7 +163,7 @@ protected void AssignUnityLayer(SuperCustomProperties properties) properties.gameObject.layer = LayerMask.NameToLayer(layer); } } - else + else if (defaultInheritFromParent) { // Inherit the layer of our parent var parent = properties.gameObject.transform.parent; diff --git a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TmxAssetImporter.cs b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TmxAssetImporter.cs index 0abc240f..2c4362b4 100644 --- a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TmxAssetImporter.cs +++ b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TmxAssetImporter.cs @@ -412,6 +412,17 @@ private void DoPrefabReplacements() // Keep the name from Tiled. instance.name = so.gameObject.name; + // Transfer and reapply custom property magic on the instantiated prefab. + var soComponent = so.gameObject.GetComponent(); + if (soComponent != null && !soComponent.m_Properties.IsEmpty()) + { + var component = instance.AddComponent(); + component.m_Properties = new List(); + component.m_Properties.CombineFromSource(soComponent.m_Properties); + AssignUnityTag(component); + AssignUnityLayer(component, defaultInheritFromParent: false); + } + // Update bookkeeping for later custom property replacement. goToDestroy.Add(so.gameObject); objectsById[so.m_Id] = instance;