Fix preserving objects order in prefab instances on apply (based on the prefab)
Fixes #346
This commit is contained in:
@@ -367,6 +367,17 @@ bool PrefabInstanceData::SynchronizePrefabInstances(Array<PrefabInstanceData>& p
|
|||||||
Level::callActorEvent(Level::ActorEventType::OnActorActiveChanged, actor, nullptr);
|
Level::callActorEvent(Level::ActorEventType::OnActorActiveChanged, actor, nullptr);
|
||||||
Level::callActorEvent(Level::ActorEventType::OnActorOrderInParentChanged, actor, nullptr);
|
Level::callActorEvent(Level::ActorEventType::OnActorOrderInParentChanged, actor, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preserve order in parent (values from prefab are used)
|
||||||
|
if (i != 0)
|
||||||
|
{
|
||||||
|
auto prefab = Content::Load<Prefab>(prefabId);
|
||||||
|
const auto defaultInstance = prefab ? prefab->GetDefaultInstance(obj->GetPrefabObjectID()) : nullptr;
|
||||||
|
if (defaultInstance)
|
||||||
|
{
|
||||||
|
obj->SetOrderInParent(defaultInstance->GetOrderInParent());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -784,6 +795,20 @@ bool Prefab::ApplyAllInternal(Actor* targetActor, bool linkTargetActorObjectToPr
|
|||||||
obj->Deserialize(diffDataDocument[dataIndex], modifier.Value);
|
obj->Deserialize(diffDataDocument[dataIndex], modifier.Value);
|
||||||
|
|
||||||
sceneObjects->Add(obj);
|
sceneObjects->Add(obj);
|
||||||
|
|
||||||
|
// Synchronize order of the scene objects with the serialized data (eg. user reordered actors in prefab editor and applied changes)
|
||||||
|
if (i != 0)
|
||||||
|
{
|
||||||
|
for (int32 j = 0; j < targetObjects->Count(); j++)
|
||||||
|
{
|
||||||
|
SceneObject* targetObject = targetObjects->At(j);
|
||||||
|
if (targetObject->GetPrefabObjectID() == obj->GetID())
|
||||||
|
{
|
||||||
|
obj->SetOrderInParent(targetObject->GetOrderInParent());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -257,6 +257,16 @@ void SceneObjectsFactory::SynchronizePrefabInstances(Array<SceneObject*>& sceneO
|
|||||||
// Reparent
|
// Reparent
|
||||||
obj->SetParent(actualParent, false);
|
obj->SetParent(actualParent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preserve order in parent (values from prefab are used)
|
||||||
|
if (i != 0)
|
||||||
|
{
|
||||||
|
const auto defaultInstance = prefab ? prefab->GetDefaultInstance(obj->GetPrefabObjectID()) : nullptr;
|
||||||
|
if (defaultInstance)
|
||||||
|
{
|
||||||
|
obj->SetOrderInParent(defaultInstance->GetOrderInParent());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check all actors with prefab linkage for adding missing objects
|
// Check all actors with prefab linkage for adding missing objects
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ void ChangeIds(rapidjson_flax::Value& obj, rapidjson_flax::Document& document, c
|
|||||||
|
|
||||||
void JsonTools::ChangeIds(Document& doc, const Dictionary<Guid, Guid>& mapping)
|
void JsonTools::ChangeIds(Document& doc, const Dictionary<Guid, Guid>& mapping)
|
||||||
{
|
{
|
||||||
|
if (mapping.IsEmpty())
|
||||||
|
return;
|
||||||
::ChangeIds(doc, doc, mapping);
|
::ChangeIds(doc, doc, mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user