PrefabUtility.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using BansheeEngine;
  8. namespace BansheeEditor
  9. {
  10. /// <summary>
  11. /// Performs various prefab specific operations.
  12. /// </summary>
  13. public static class PrefabUtility
  14. {
  15. /// <summary>
  16. /// Breaks the link between a prefab instance and its prefab. Object will retain all current values but will
  17. /// no longer be influenced by modifications to its parent prefab.
  18. /// </summary>
  19. /// <param name="obj">Prefab instance whose link to break.</param>
  20. public static void BreakPrefab(SceneObject obj)
  21. {
  22. if (obj == null)
  23. return;
  24. IntPtr objPtr = obj.GetCachedPtr();
  25. Internal_BreakPrefab(objPtr);
  26. }
  27. /// <summary>
  28. /// Updates the contents of the prefab with the contents of the provided prefab instance. If the provided object
  29. /// is not a prefab instance nothing happens.
  30. /// </summary>
  31. /// <param name="obj">Prefab instance whose prefab to update.</param>
  32. public static void ApplyPrefab(SceneObject obj)
  33. {
  34. if (obj == null)
  35. return;
  36. IntPtr objPtr = obj.GetCachedPtr();
  37. Internal_ApplyPrefab(objPtr);
  38. }
  39. /// <summary>
  40. /// Remove any instance specific changes to the object or its hierarchy from the provided prefab instance and
  41. /// restore it to the exact copy of the linked prefab.
  42. /// </summary>
  43. /// <param name="obj">Prefab instance to revert to original state.</param>
  44. public static void RevertPrefab(SceneObject obj)
  45. {
  46. if (obj == null)
  47. return;
  48. IntPtr objPtr = obj.GetCachedPtr();
  49. Internal_RevertPrefab(objPtr);
  50. }
  51. /// <summary>
  52. /// Checks if a scene object has a prefab link. Scene objects with a prefab link will be automatically updated
  53. /// when their prefab changes in order to reflect its changes.
  54. /// </summary>
  55. /// <param name="obj">Scene object to check if it has a prefab link.</param>
  56. /// <returns>True if the object is a prefab instance (has a prefab link), false otherwise.</returns>
  57. public static bool IsPrefabInstance(SceneObject obj)
  58. {
  59. if (obj == null)
  60. return false;
  61. IntPtr objPtr = obj.GetCachedPtr();
  62. return Internal_HasPrefabLink(objPtr);
  63. }
  64. [MethodImpl(MethodImplOptions.InternalCall)]
  65. private static extern void Internal_BreakPrefab(IntPtr nativeInstance);
  66. [MethodImpl(MethodImplOptions.InternalCall)]
  67. private static extern void Internal_ApplyPrefab(IntPtr nativeInstance);
  68. [MethodImpl(MethodImplOptions.InternalCall)]
  69. private static extern void Internal_RevertPrefab(IntPtr nativeInstance);
  70. [MethodImpl(MethodImplOptions.InternalCall)]
  71. private static extern bool Internal_HasPrefabLink(IntPtr nativeInstance);
  72. }
  73. }