Skip to content
Open
Show file tree
Hide file tree
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 @@ -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<SuperCustomProperties>();
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<SuperCustomProperties>();
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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down