EmptySprite.cs 621 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. using System.Collections;
  3. public static class EmptySprite {
  4. static Sprite instance;
  5. ///<summary>
  6. /// Returns the instance of a (1 x 1) white Spprite
  7. /// </summary>
  8. public static Sprite Get(){
  9. if (instance == null) {
  10. instance = OnePixelWhiteSprite();
  11. }
  12. return instance;
  13. }
  14. /// <summary>
  15. /// Generates a white sprite (1 x 1).
  16. /// </summary>
  17. /// <returns>A white sprite (1 x 1).</returns>
  18. static Sprite OnePixelWhiteSprite(){
  19. Texture2D tex = new Texture2D (1,1);
  20. tex.SetPixel (0,0,Color.white);
  21. tex.Apply ();
  22. return Sprite.Create(tex,new Rect(0,0,1,1),Vector2.zero);
  23. }
  24. }