Applies the difference from the prefab object instance, saves the changes and synchronizes them with the active instances of the prefab asset. Applies all the changes from not only the given actor instance but all actors created within that prefab instance. The modified instance.
(Actor instance)
| 241 | /// </remarks> |
| 242 | /// <param name="instance">The modified instance.</param> |
| 243 | public void ApplyAll(Actor instance) |
| 244 | { |
| 245 | // Validate input |
| 246 | if (!instance) |
| 247 | throw new ArgumentNullException(nameof(instance)); |
| 248 | if (!instance.HasPrefabLink || instance.PrefabID == Guid.Empty) |
| 249 | throw new ArgumentException("The modified actor instance has missing prefab link."); |
| 250 | |
| 251 | var prefab = FlaxEngine.Content.LoadAsync<Prefab>(instance.PrefabID); |
| 252 | if (prefab == null) |
| 253 | throw new ArgumentException("Missing prefab to apply."); |
| 254 | PrefabApplying?.Invoke(prefab, instance); |
| 255 | |
| 256 | // When applying changes to prefab from actor in level ignore it's root transformation (see ActorEditor.ProcessDiff) |
| 257 | Actor prefabRoot = null; |
| 258 | var originalTransform = instance.LocalTransform; |
| 259 | var originalName = instance.Name; |
| 260 | if (instance.HasScene) |
| 261 | { |
| 262 | prefabRoot = instance.GetPrefabRoot(); |
| 263 | if (prefabRoot != null && prefabRoot.IsPrefabRoot && instance.HasScene) |
| 264 | { |
| 265 | var defaultInstance = prefab.GetDefaultInstance(); |
| 266 | originalTransform = prefabRoot.LocalTransform; |
| 267 | originalName = prefabRoot.Name; |
| 268 | prefabRoot.LocalTransform = defaultInstance.Transform; |
| 269 | prefabRoot.Name = defaultInstance.Name; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | // Call backend |
| 274 | var failed = PrefabManager.Internal_ApplyAll(FlaxEngine.Object.GetUnmanagedPtr(instance)); |
| 275 | if (prefabRoot != null) |
| 276 | { |
| 277 | prefabRoot.LocalTransform = originalTransform; |
| 278 | prefabRoot.Name = originalName; |
| 279 | } |
| 280 | if (failed) |
| 281 | throw new Exception("Failed to apply the prefab. See log to learn more."); |
| 282 | |
| 283 | PrefabApplied?.Invoke(prefab, instance); |
| 284 | } |
| 285 | } |
| 286 | } |
no test coverage detected