Prefab.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. namespace BansheeEngine
  6. {
  7. /** @addtogroup Scene
  8. * @{
  9. */
  10. /// <summary>
  11. /// Prefab is a saveable hierarchy of scene objects. In general it can serve as any grouping of scene objects
  12. /// (for example a level) or be used as a form of a template instantiated and reused throughout the scene.
  13. /// </summary>
  14. public class Prefab : Resource
  15. {
  16. /// <summary>
  17. /// Constructor for internal use by the runtime.
  18. /// </summary>
  19. private Prefab()
  20. { }
  21. /// <summary>
  22. /// Creates a new prefab from the provided scene object. If the scene object has an existing prefab link it will
  23. /// be broken. After the prefab is created the scene object will be automatically linked to it.
  24. /// </summary>
  25. /// <param name="so">Scene object to generate the prefab for.</param>
  26. /// <param name="isScene">Determines if the prefab represents a scene or just a generic group of objects.
  27. /// <see cref="IsScene"/></param>
  28. public Prefab(SceneObject so, bool isScene = true)
  29. {
  30. IntPtr soPtr = so.GetCachedPtr();
  31. Internal_CreateInstance(this, soPtr, isScene);
  32. }
  33. /// <summary>
  34. /// Instantiates a prefab by creating an instance of the prefab's scene object hierarchy. The returned hierarchy
  35. /// will be parented to world root by default.
  36. /// </summary>
  37. /// <returns>New scene object instance containing a copy of the prefab's hierarchy.</returns>
  38. public SceneObject Instantiate()
  39. {
  40. return Internal_Instantiate(mCachedPtr);
  41. }
  42. /// <summary>
  43. /// Determines if the prefab represents a scene or just a generic group of objects. The only difference between the
  44. /// two is the way root object is handled: scenes are assumed to be saved with the scene root object (which is
  45. /// hidden), while object group root is a normal scene object (not hidden). This is relevant when when prefabs are
  46. /// loaded, so the systems knows to append the root object to non-scene prefabs.
  47. /// </summary>
  48. public bool IsScene
  49. {
  50. get { return Internal_IsScene(mCachedPtr); }
  51. }
  52. [MethodImpl(MethodImplOptions.InternalCall)]
  53. private static extern void Internal_CreateInstance(Prefab instance, IntPtr so, bool isScene);
  54. [MethodImpl(MethodImplOptions.InternalCall)]
  55. private static extern SceneObject Internal_Instantiate(IntPtr thisPtr);
  56. [MethodImpl(MethodImplOptions.InternalCall)]
  57. private static extern bool Internal_IsScene(IntPtr thisPtr);
  58. }
  59. /** @} */
  60. }