using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace BansheeEngine
{
///
/// Prefab is a saveable hierarchy of scene objects. In general it can serve as any grouping of scene objects
/// (e.g. a level) or be used as a form of a template instantiated and reused throughout the scene.
///
public class Prefab : Resource
{
///
/// Constructor for internal use by the runtime.
///
private Prefab()
{ }
///
/// Creates a new prefab from the provided scene object. If the scene object has an existing prefab link it will
/// be broken. After the prefab is created the scene object will be automatically linked to it.
///
/// Scene object to generate the prefab for.
public Prefab(SceneObject so)
{
IntPtr soPtr = so.GetCachedPtr();
Internal_CreateInstance(this, soPtr);
}
///
/// Instantiates a prefab by creating an instance of the prefab's scene object hierarchy. The returned hierarchy
/// will be parented to world root by default.
///
/// New scene object instance containing a copy of the prefab's hierarchy.
public SceneObject Instantiate()
{
return Internal_Instantiate(mCachedPtr);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(Prefab instance, IntPtr so);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern SceneObject Internal_Instantiate(IntPtr thisPtr);
}
}