Prefab.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;
  4. namespace BansheeEngine
  5. {
  6. /// <summary>
  7. /// Prefab is a saveable hierarchy of scene objects. In general it can serve as any grouping of scene objects
  8. /// (e.g. a level) or be used as a form of a template instantiated and reused throughout the scene.
  9. /// </summary>
  10. public class Prefab : Resource
  11. {
  12. /// <summary>
  13. /// Constructor for internal use by the runtime.
  14. /// </summary>
  15. private Prefab()
  16. { }
  17. /// <summary>
  18. /// Creates a new prefab from the provided scene object. If the scene object has an existing prefab link it will
  19. /// be broken. After the prefab is created the scene object will be automatically linked to it.
  20. /// </summary>
  21. /// <param name="so">Scene object to generate the prefab for.</param>
  22. public Prefab(SceneObject so)
  23. {
  24. IntPtr soPtr = so.GetCachedPtr();
  25. Internal_CreateInstance(this, soPtr);
  26. }
  27. /// <summary>
  28. /// Instantiates a prefab by creating an instance of the prefab's scene object hierarchy. The returned hierarchy
  29. /// will be parented to world root by default.
  30. /// </summary>
  31. /// <returns>New scene object instance containing a copy of the prefab's hierarchy.</returns>
  32. public SceneObject Instantiate()
  33. {
  34. return Internal_Instantiate(mCachedPtr);
  35. }
  36. [MethodImpl(MethodImplOptions.InternalCall)]
  37. private static extern void Internal_CreateInstance(Prefab instance, IntPtr so);
  38. [MethodImpl(MethodImplOptions.InternalCall)]
  39. private static extern SceneObject Internal_Instantiate(IntPtr thisPtr);
  40. }
  41. }