ITexture.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using UnityEngine;
  2. using UnityTexture2D = UnityEngine.Texture2D;
  3. using System;
  4. namespace UnityEditor.U2D.Sprites
  5. {
  6. internal abstract class ITexture2D
  7. {
  8. public abstract int width { get; }
  9. public abstract int height { get; }
  10. public abstract TextureFormat format { get; }
  11. public abstract Color32[] GetPixels32();
  12. public abstract FilterMode filterMode { get; set; }
  13. public abstract string name { get; }
  14. public abstract void SetPixels(Color[] c);
  15. public abstract void Apply();
  16. public abstract float mipMapBias { get; }
  17. public static bool operator==(ITexture2D t1, ITexture2D t2)
  18. {
  19. if (object.ReferenceEquals(t1, null))
  20. {
  21. return object.ReferenceEquals(t2, null) || t2 == null;
  22. }
  23. return t1.Equals(t2);
  24. }
  25. public static bool operator!=(ITexture2D t1, ITexture2D t2)
  26. {
  27. if (object.ReferenceEquals(t1, null))
  28. {
  29. return !object.ReferenceEquals(t2, null) && t2 != null;
  30. }
  31. return !t1.Equals(t2);
  32. }
  33. public override bool Equals(object other)
  34. {
  35. throw new NotImplementedException();
  36. }
  37. public override int GetHashCode()
  38. {
  39. throw new NotImplementedException();
  40. }
  41. public static implicit operator UnityEngine.Object(ITexture2D t)
  42. {
  43. return object.ReferenceEquals(t, null) ? null : t.ToUnityObject();
  44. }
  45. public static implicit operator UnityEngine.Texture2D(ITexture2D t)
  46. {
  47. return object.ReferenceEquals(t, null) ? null : t.ToUnityTexture();
  48. }
  49. protected abstract UnityEngine.Object ToUnityObject();
  50. protected abstract UnityEngine.Texture2D ToUnityTexture();
  51. }
  52. internal class Texture2DWrapper : ITexture2D
  53. {
  54. UnityTexture2D m_Texture;
  55. public Texture2DWrapper(UnityTexture2D texture)
  56. {
  57. m_Texture = texture;
  58. }
  59. public override int width
  60. {
  61. get { return m_Texture.width; }
  62. }
  63. public override int height
  64. {
  65. get { return m_Texture.height; }
  66. }
  67. public override TextureFormat format
  68. {
  69. get { return m_Texture.format; }
  70. }
  71. public override Color32[] GetPixels32()
  72. {
  73. return m_Texture.GetPixels32();
  74. }
  75. public override FilterMode filterMode
  76. {
  77. get { return m_Texture.filterMode; }
  78. set { m_Texture.filterMode = value; }
  79. }
  80. public override float mipMapBias
  81. {
  82. get { return m_Texture.mipMapBias; }
  83. }
  84. public override string name
  85. {
  86. get { return m_Texture.name; }
  87. }
  88. public override bool Equals(object other)
  89. {
  90. Texture2DWrapper t = other as Texture2DWrapper;
  91. if (object.ReferenceEquals(t, null))
  92. return m_Texture == null;
  93. return m_Texture == t.m_Texture;
  94. }
  95. public override int GetHashCode()
  96. {
  97. return m_Texture.GetHashCode();
  98. }
  99. public override void SetPixels(Color[] c)
  100. {
  101. m_Texture.SetPixels(c);
  102. }
  103. public override void Apply()
  104. {
  105. m_Texture.Apply();
  106. }
  107. protected override UnityEngine.Object ToUnityObject()
  108. {
  109. return m_Texture;
  110. }
  111. protected override UnityEngine.Texture2D ToUnityTexture()
  112. {
  113. return m_Texture;
  114. }
  115. }
  116. }