SpriteTexture.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Runtime.CompilerServices;
  2. namespace BansheeEngine
  3. {
  4. /// <summary>
  5. /// Texture interface that encapsulates underlying texture which allows us to create a sprite texture atlas
  6. /// (e.g. multiple sprite textures referencing different parts of a single texture).
  7. /// </summary>
  8. public sealed class SpriteTexture : Resource
  9. {
  10. /// <summary>
  11. /// Constructor for internal use by the runtime.
  12. /// </summary>
  13. private SpriteTexture()
  14. { }
  15. /// <summary>
  16. /// Creates a new sprite texture that references the entire area of the provided texture.
  17. /// </summary>
  18. /// <param name="texture">Texture to wrap by the sprite texture.</param>
  19. public SpriteTexture(Texture2D texture)
  20. {
  21. Internal_CreateInstance(this, texture, Vector2.Zero, Vector2.One);
  22. }
  23. /// <summary>
  24. /// Creates a new sprite texture that references a sub-area of the provided texture.
  25. /// </summary>
  26. /// <param name="texture">Texture to wrap by the sprite texture.</param>
  27. /// <param name="uvOffset">Top-left position of the area used by the sprite texture, in normalized coordinates.
  28. /// </param>
  29. /// <param name="uvScale">Size of the area used by the sprite texture, in normalized coordinates.</param>
  30. public SpriteTexture(Texture2D texture, Vector2 uvOffset, Vector2 uvScale)
  31. {
  32. Internal_CreateInstance(this, texture, uvOffset, uvScale);
  33. }
  34. [MethodImpl(MethodImplOptions.InternalCall)]
  35. private static extern void Internal_CreateInstance(SpriteTexture instance,
  36. Texture2D teture, Vector2 offset, Vector2 scale);
  37. }
  38. }