diff --git a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TmxAssetImporter.cs b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TmxAssetImporter.cs index 895b72f8..1b728e64 100644 --- a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TmxAssetImporter.cs +++ b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Importers/TmxAssetImporter.cs @@ -377,28 +377,38 @@ private void DoPrefabReplacements() foreach (var so in supers) { var prefab = SuperImportContext.Settings.GetPrefabReplacement(so.m_Type); + if (prefab != null) { - // Replace the super object with the instantiated prefab - var instance = (GameObject)PrefabUtility.InstantiatePrefab(prefab); - instance.transform.SetParent(so.transform.parent); - instance.transform.position = so.transform.position + prefab.transform.localPosition; - instance.transform.rotation = so.transform.rotation; - - // Apply custom properties as messages to the instanced prefab - var props = so.GetComponent(); - if (props != null) + if (prefab.m_Prefab != null) { - foreach (var p in props.m_Properties) + // Replace the super object with the instantiated prefab + var instance = (GameObject)PrefabUtility.InstantiatePrefab(prefab.m_Prefab); + instance.transform.SetParent(so.transform.parent); + instance.transform.position = so.transform.position + prefab.m_Prefab.transform.localPosition; + instance.transform.rotation = so.transform.rotation; + + // Apply custom properties as messages to the instanced prefab + var props = so.GetComponent(); + if (props != null) { - instance.gameObject.BroadcastProperty(p); + foreach (var p in props.m_Properties) + { + instance.gameObject.BroadcastProperty(p); + } } - } - // Keep the name from Tiled. - string name = so.gameObject.name; - DestroyImmediate(so.gameObject); - instance.name = name; + // Keep the name from Tiled. + string name = so.gameObject.name; + DestroyImmediate(so.gameObject); + instance.name = name; + } + else if (prefab.m_TypeName == so.m_Type) + { + // Ignore game object as per Prefab Replacements (Object Type present but no game object to replace with) + Debug.LogWarningFormat("Prefab Replacements-> Ignoring GameObject: {0} in map {1} (Object Type: {2} present but no game object to replace with)", so.gameObject.name, m_MapComponent.gameObject.name, so.m_Type); + DestroyImmediate(so.gameObject); + } } } } diff --git a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Settings/ST2USettings.cs b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Settings/ST2USettings.cs index b81ae035..e8b6c764 100644 --- a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Settings/ST2USettings.cs +++ b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Settings/ST2USettings.cs @@ -176,12 +176,12 @@ public void AddObjectsToPrefabReplacements() } } - public GameObject GetPrefabReplacement(string type) + public TypePrefabReplacement GetPrefabReplacement(string type) { var replacement = PrefabReplacements.FirstOrDefault(r => r.m_TypeName == type); if (replacement != null) { - return replacement.m_Prefab; + return replacement; } return null; diff --git a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Settings/ST2USettingsProvider.cs b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Settings/ST2USettingsProvider.cs index 96d73396..1cfa0bb4 100644 --- a/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Settings/ST2USettingsProvider.cs +++ b/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Settings/ST2USettingsProvider.cs @@ -209,7 +209,7 @@ private void DoGuiPrefabReplacements() } } - EditorGUILayout.HelpBox("When the Tiled import scripts come across a Tiled Object of one of these given types it will be replaced, automatically, with the associated prefab.", MessageType.None); + EditorGUILayout.HelpBox("When the Tiled import scripts come across a Tiled Object of one of these given types it will be replaced, automatically, with the associated prefab.\nNote: If no game object is specified, the Tiled Object won't be imported (ignored)", MessageType.None); } }