2
0

Prefab.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. public Prefab(SceneObject so)
  27. {
  28. IntPtr soPtr = so.GetCachedPtr();
  29. Internal_CreateInstance(this, soPtr);
  30. }
  31. /// <summary>
  32. /// Instantiates a prefab by creating an instance of the prefab's scene object hierarchy. The returned hierarchy
  33. /// will be parented to world root by default.
  34. /// </summary>
  35. /// <returns>New scene object instance containing a copy of the prefab's hierarchy.</returns>
  36. public SceneObject Instantiate()
  37. {
  38. return Internal_Instantiate(mCachedPtr);
  39. }
  40. [MethodImpl(MethodImplOptions.InternalCall)]
  41. private static extern void Internal_CreateInstance(Prefab instance, IntPtr so);
  42. [MethodImpl(MethodImplOptions.InternalCall)]
  43. private static extern SceneObject Internal_Instantiate(IntPtr thisPtr);
  44. }
  45. /** @} */
  46. }