Skip to content

Commit 52342af

Browse files
committed
Implement unity:prefabKeepObject
Currently, using prefab imports nukes the SuperObject and the SuperCustomProperties components. While custom properties are broadcast, it may still be desirable to allow access to arbitrary custom properties by name at runtime. Add a new unity attributes, unity:prefabKeepObject that on import, checks if set on the object, and if so, creates a copy of the SuperObject and SuperCustomProperties onto the root node of the prefab.
1 parent c0673e6 commit 52342af

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TmxAssetImporter.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,15 @@ private void DoPrefabReplacements()
430430
{
431431
objectsById[so.m_Id].BroadcastProperty(p, objectsById);
432432
}
433+
434+
if (so.gameObject.GetSuperPropertyValueBool(StringConstants.Unity_PrefabKeepObject, false))
435+
{
436+
var superObjectCopy = objectsById[so.m_Id].AddComponent<SuperObject>();
437+
EditorUtility.CopySerialized(so, superObjectCopy);
438+
439+
var superPropsCopy = objectsById[so.m_Id].AddComponent<SuperCustomProperties>();
440+
EditorUtility.CopySerialized(props, superPropsCopy);
441+
}
433442
}
434443
}
435444

SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/StringConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public static class StringConstants
66
public const string Unity_Ignore = Unity_Prefix + "ignore";
77
public const string Unity_IsTrigger = Unity_Prefix + "IsTrigger";
88
public const string Unity_Layer = Unity_Prefix + "layer";
9+
public const string Unity_PrefabKeepObject = Unity_Prefix + "prefabKeepObject";
910
public const string Unity_SortingLayer = Unity_Prefix + "SortingLayer";
1011
public const string Unity_SortingLayerName = Unity_Prefix + "SortingLayerName";
1112
public const string Unity_SortingOrder = Unity_Prefix + "SortingOrder";

docs/manual/custom-properties-importing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ These custom properties always have a :code:`unity:` prefix so that they do not
1919
* **Collision**: The colliders are not imported for the layer."
2020
":code:`unity:IsTrigger`", ":code:`bool`", "Layers, Tileset, Tile, Collider, Collider Group", "Controls the :code:`isTrigger` setting of the :code:`Collider2D` object generated in the prefab. Add as a layer custom property to override all colliders for a given layer."
2121
":code:`unity:layer`", ":code:`string`", "Layers, Tileset, Tile, Collider, Collider Group", "Controls which Unity phyisics layer our generated colliders are assigned. The layer name must exist in your project's Tag Manager."
22+
":code:`unity:prefabKeepObject`", ":code:`bool`", "Objects", "When set on a prefab replacement object, will retain the SuperObject and SuperCustomProperties."
2223
":code:`unity:SortingLayer`", ":code:`string`", "Layers, Tile Objects", "Controls which sorting layer is assigned to the Unity :code:`Renderer` component created for your tilemaps and sprites. The sorting layer name must exist in your project's Tag Manager."
2324
":code:`unity:SortingOrder`", ":code:`int`", "Layers, Tile Objects", "Controls which sorting order is applied to the Unity :code:`Renderer` component created for your tilemaps and sprites."
2425
":code:`unity:Tag`", ":code:`string`", "Layers, Objects", "Controls which tag is applied to the :code:`GameObject` created for your layers and objects. The tag must exist in your project's Tag Manager."

0 commit comments

Comments
 (0)