GImage.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using UnityEngine;
  2. using FairyGUI.Utils;
  3. namespace FairyGUI
  4. {
  5. /// <summary>
  6. /// GImage class.
  7. /// </summary>
  8. public class GImage : GObject, IColorGear
  9. {
  10. Image _content;
  11. public GImage()
  12. {
  13. }
  14. override protected void CreateDisplayObject()
  15. {
  16. _content = new Image();
  17. _content.gOwner = this;
  18. displayObject = _content;
  19. }
  20. /// <summary>
  21. /// Color of the image.
  22. /// </summary>
  23. public Color color
  24. {
  25. get { return _content.color; }
  26. set
  27. {
  28. _content.color = value;
  29. UpdateGear(4);
  30. }
  31. }
  32. /// <summary>
  33. /// Flip type.
  34. /// </summary>
  35. /// <seealso cref="FlipType"/>
  36. public FlipType flip
  37. {
  38. get { return _content.graphics.flip; }
  39. set { _content.graphics.flip = value; }
  40. }
  41. /// <summary>
  42. /// Fill method.
  43. /// </summary>
  44. /// <seealso cref="FillMethod"/>
  45. public FillMethod fillMethod
  46. {
  47. get { return _content.fillMethod; }
  48. set { _content.fillMethod = value; }
  49. }
  50. /// <summary>
  51. /// Fill origin.
  52. /// </summary>
  53. /// <seealso cref="OriginHorizontal"/>
  54. /// <seealso cref="OriginVertical"/>
  55. /// <seealso cref="Origin90"/>
  56. /// <seealso cref="Origin180"/>
  57. /// <seealso cref="Origin360"/>
  58. public int fillOrigin
  59. {
  60. get { return _content.fillOrigin; }
  61. set { _content.fillOrigin = value; }
  62. }
  63. /// <summary>
  64. /// Fill clockwise if true.
  65. /// </summary>
  66. public bool fillClockwise
  67. {
  68. get { return _content.fillClockwise; }
  69. set { _content.fillClockwise = value; }
  70. }
  71. /// <summary>
  72. /// Fill amount. (0~1)
  73. /// </summary>
  74. public float fillAmount
  75. {
  76. get { return _content.fillAmount; }
  77. set { _content.fillAmount = value; }
  78. }
  79. /// <summary>
  80. /// Set texture directly. The image wont own the texture.
  81. /// </summary>
  82. public NTexture texture
  83. {
  84. get { return _content.texture; }
  85. set
  86. {
  87. if (value != null)
  88. {
  89. sourceWidth = value.width;
  90. sourceHeight = value.height;
  91. }
  92. else
  93. {
  94. sourceWidth = 0;
  95. sourceHeight = 0;
  96. }
  97. initWidth = sourceWidth;
  98. initHeight = sourceHeight;
  99. _content.texture = value;
  100. }
  101. }
  102. /// <summary>
  103. /// Set material.
  104. /// </summary>
  105. public Material material
  106. {
  107. get { return _content.material; }
  108. set { _content.material = value; }
  109. }
  110. /// <summary>
  111. /// Set shader.
  112. /// </summary>
  113. public string shader
  114. {
  115. get { return _content.shader; }
  116. set { _content.shader = value; }
  117. }
  118. override public void ConstructFromResource()
  119. {
  120. this.gameObjectName = packageItem.name;
  121. PackageItem contentItem = packageItem.getBranch();
  122. sourceWidth = contentItem.width;
  123. sourceHeight = contentItem.height;
  124. initWidth = sourceWidth;
  125. initHeight = sourceHeight;
  126. contentItem = contentItem.getHighResolution();
  127. contentItem.Load();
  128. _content.scale9Grid = contentItem.scale9Grid;
  129. _content.scaleByTile = contentItem.scaleByTile;
  130. _content.tileGridIndice = contentItem.tileGridIndice;
  131. _content.texture = contentItem.texture;
  132. _content.textureScale = new Vector2(contentItem.width / (float)sourceWidth, contentItem.height / (float)sourceHeight);
  133. SetSize(sourceWidth, sourceHeight);
  134. }
  135. override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
  136. {
  137. base.Setup_BeforeAdd(buffer, beginPos);
  138. buffer.Seek(beginPos, 5);
  139. if (buffer.ReadBool())
  140. _content.color = buffer.ReadColor();
  141. _content.graphics.flip = (FlipType)buffer.ReadByte();
  142. _content.fillMethod = (FillMethod)buffer.ReadByte();
  143. if (_content.fillMethod != FillMethod.None)
  144. {
  145. _content.fillOrigin = buffer.ReadByte();
  146. _content.fillClockwise = buffer.ReadBool();
  147. _content.fillAmount = buffer.ReadFloat();
  148. }
  149. }
  150. }
  151. }