Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public partial class TmxAssetImporter : TiledAssetImporter
private Dictionary<uint, TilePolygonCollection> m_TilePolygonDatabase;
private int m_NextTileAsObjectId;

private Dictionary<int, GameObject> m_ObjectsById;

[SerializeField]
private bool m_TilesAsObjects = false;
public bool TilesAsObjects { get { return m_TilesAsObjects; } }
Expand All @@ -44,6 +46,17 @@ public partial class TmxAssetImporter : TiledAssetImporter
[SerializeField]
private List<SuperTileset> m_InternalTilesets;

/// <summary>
/// Returns the game object corresponding to a Tiled object ID.
/// If no such object could be found, returns null.
/// </summary>
public GameObject GetObject(int targetId)
{
return m_ObjectsById.TryGetValue(targetId, out var go)
? go
: null;
}

protected override void InternalOnImportAsset()
{
base.InternalOnImportAsset();
Expand Down Expand Up @@ -395,7 +408,7 @@ private void DoPrefabReplacements()
{
// Should any of our objects (from Tiled) be replaced by instantiated prefabs?
var supers = m_MapComponent.GetComponentsInChildren<SuperObject>();
var objectsById = supers.ToDictionary(so => so.m_Id, so => so.gameObject);
m_ObjectsById = supers.ToDictionary(so => so.m_Id, so => so.gameObject);
var goToDestroy = new List<GameObject>();

foreach (var so in supers)
Expand All @@ -414,7 +427,7 @@ private void DoPrefabReplacements()

// Update bookkeeping for later custom property replacement.
goToDestroy.Add(so.gameObject);
objectsById[so.m_Id] = instance;
m_ObjectsById[so.m_Id] = instance;
}
}

Expand All @@ -428,7 +441,7 @@ private void DoPrefabReplacements()
{
foreach (var p in props.m_Properties)
{
objectsById[so.m_Id].BroadcastProperty(p, objectsById);
m_ObjectsById[so.m_Id].BroadcastProperty(p, m_ObjectsById);
}
}
}
Expand Down