Prefab.cs 2.0 KB

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