ManagedResource.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using System.Text;
  8. namespace BansheeEngine
  9. {
  10. /// <summary>
  11. /// Base class for all user-defined managed resources. Managed resources are automatically serialized, can be saved
  12. /// and persistently referenced by other objects.
  13. /// </summary>
  14. public class ManagedResource : Resource
  15. {
  16. /// <summary>
  17. /// Constructor for internal use by the runtime.
  18. /// </summary>
  19. protected ManagedResource()
  20. { }
  21. /// <summary>
  22. /// Creates a new managed resource.
  23. /// </summary>
  24. /// <typeparam name="T">Type of the managed resource to create.</typeparam>
  25. /// <returns>A new instance of a managed resource with default values.</returns>
  26. static public T Create<T>() where T : ManagedResource, new()
  27. {
  28. T newResource = new T();
  29. Internal_CreateInstance(newResource);
  30. return newResource;
  31. }
  32. [MethodImpl(MethodImplOptions.InternalCall)]
  33. private static extern void Internal_CreateInstance(ManagedResource resource);
  34. }
  35. }