| 257 | } |
| 258 | |
| 259 | void SceneObjectsFactory::Deserialize(Context& context, SceneObject* obj, ISerializable::DeserializeStream& stream) |
| 260 | { |
| 261 | CHECK_DEBUG(obj); |
| 262 | ISerializeModifier* modifier = context.GetModifier(); |
| 263 | LogContextScope logContext(obj->GetID()); |
| 264 | |
| 265 | // Check for prefab instance |
| 266 | Guid prefabObjectId; |
| 267 | if (JsonTools::GetGuidIfValid(prefabObjectId, stream, "PrefabObjectID")) |
| 268 | { |
| 269 | // Get prefab asset id |
| 270 | const Guid prefabId = JsonTools::GetGuid(stream, "PrefabID"); |
| 271 | if (!prefabId.IsValid()) |
| 272 | { |
| 273 | LOG(Warning, "Invalid prefab id."); |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | // Load prefab |
| 278 | auto prefab = Content::LoadAsync<Prefab>(prefabId); |
| 279 | if (prefab == nullptr) |
| 280 | { |
| 281 | LOG(Warning, "Missing prefab {0}.", prefabId); |
| 282 | return; |
| 283 | } |
| 284 | if (prefab->WaitForLoaded()) |
| 285 | { |
| 286 | LOG(Warning, "Failed to load prefab {0}.", prefab->ToString()); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | // Get prefab object data from the prefab |
| 291 | const ISerializable::DeserializeStream* prefabData; |
| 292 | if (!prefab->ObjectsDataCache.TryGet(prefabObjectId, prefabData)) |
| 293 | { |
| 294 | LOG(Warning, "Missing object {1} data in prefab {0}.", prefab->ToString(), prefabObjectId); |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | // Deserialize prefab data (recursive prefab loading to support nested prefabs) |
| 299 | const auto prevVersion = modifier->EngineBuild; |
| 300 | modifier->EngineBuild = prefab->DataEngineBuild; |
| 301 | #if USE_EDITOR |
| 302 | bool prevDeprecated = ContentDeprecated::Clear(); |
| 303 | #endif |
| 304 | Deserialize(context, obj, *(ISerializable::DeserializeStream*)prefabData); |
| 305 | #if USE_EDITOR |
| 306 | if (ContentDeprecated::Clear(prevDeprecated)) |
| 307 | { |
| 308 | // Prefab contains deprecated data format |
| 309 | context.Locker.Lock(); |
| 310 | context.DeprecatedPrefabs.Add(prefab); |
| 311 | context.Locker.Unlock(); |
| 312 | } |
| 313 | #endif |
| 314 | modifier->EngineBuild = prevVersion; |
| 315 | } |
| 316 |
no test coverage detected