PrefabUtility.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. using BansheeEngine;
  6. namespace BansheeEditor
  7. {
  8. /** @addtogroup Utility-Editor
  9. * @{
  10. */
  11. /// <summary>
  12. /// Performs various prefab specific operations.
  13. /// </summary>
  14. public static class PrefabUtility
  15. {
  16. /// <summary>
  17. /// Breaks the link between a prefab instance and its prefab. Object will retain all current values but will
  18. /// no longer be influenced by modifications to its parent prefab.
  19. /// </summary>
  20. /// <param name="obj">Prefab instance whose link to break.</param>
  21. public static void BreakPrefab(SceneObject obj)
  22. {
  23. if (obj == null)
  24. return;
  25. IntPtr objPtr = obj.GetCachedPtr();
  26. Internal_BreakPrefab(objPtr);
  27. }
  28. /// <summary>
  29. /// Updates the contents of the prefab with the contents of the provided prefab instance. If the provided object
  30. /// is not a prefab instance nothing happens.
  31. /// </summary>
  32. /// <param name="obj">Prefab instance whose prefab to update.</param>
  33. public static void ApplyPrefab(SceneObject obj)
  34. {
  35. if (obj == null)
  36. return;
  37. IntPtr objPtr = obj.GetCachedPtr();
  38. Internal_ApplyPrefab(objPtr);
  39. }
  40. /// <summary>
  41. /// Remove any instance specific changes to the object or its hierarchy from the provided prefab instance and
  42. /// restore it to the exact copy of the linked prefab.
  43. /// </summary>
  44. /// <param name="obj">Prefab instance to revert to original state.</param>
  45. public static void RevertPrefab(SceneObject obj)
  46. {
  47. if (obj == null)
  48. return;
  49. IntPtr objPtr = obj.GetCachedPtr();
  50. Internal_RevertPrefab(objPtr);
  51. }
  52. /// <summary>
  53. /// Checks if a scene object has a prefab link. Scene objects with a prefab link will be automatically updated
  54. /// when their prefab changes in order to reflect its changes.
  55. /// </summary>
  56. /// <param name="obj">Scene object to check if it has a prefab link.</param>
  57. /// <returns>True if the object is a prefab instance (has a prefab link), false otherwise.</returns>
  58. public static bool IsPrefabInstance(SceneObject obj)
  59. {
  60. if (obj == null)
  61. return false;
  62. IntPtr objPtr = obj.GetCachedPtr();
  63. return Internal_HasPrefabLink(objPtr);
  64. }
  65. /// <summary>
  66. /// Returns the root object of the prefab instance that this object belongs to, if any.
  67. /// </summary>
  68. /// <param name="obj">Scene object to retrieve the prefab parent for.</param>
  69. /// <returns>Prefab parent of the provided object, or null if the object is not part of a prefab instance.</returns>
  70. public static SceneObject GetPrefabParent(SceneObject obj)
  71. {
  72. if (obj == null)
  73. return null;
  74. IntPtr objPtr = obj.GetCachedPtr();
  75. return Internal_GetPrefabParent(objPtr);
  76. }
  77. [MethodImpl(MethodImplOptions.InternalCall)]
  78. private static extern void Internal_BreakPrefab(IntPtr nativeInstance);
  79. [MethodImpl(MethodImplOptions.InternalCall)]
  80. private static extern void Internal_ApplyPrefab(IntPtr nativeInstance);
  81. [MethodImpl(MethodImplOptions.InternalCall)]
  82. private static extern void Internal_RevertPrefab(IntPtr nativeInstance);
  83. [MethodImpl(MethodImplOptions.InternalCall)]
  84. private static extern bool Internal_HasPrefabLink(IntPtr nativeInstance);
  85. [MethodImpl(MethodImplOptions.InternalCall)]
  86. private static extern SceneObject Internal_GetPrefabParent(IntPtr nativeInstance);
  87. }
  88. /** @} */
  89. }