GrassItem.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using UnityEngine;
  2. namespace MTE
  3. {
  4. /// <summary>
  5. /// Grass instance wrapper for editing
  6. /// </summary>
  7. public class GrassItem : IQuadObject
  8. {
  9. private readonly GrassStar star;
  10. private readonly GrassQuad quad;
  11. public GameObject gameObject;
  12. public GrassItem(GrassStar star, GameObject gameObject)
  13. {
  14. this.star = star;
  15. this.gameObject = gameObject;
  16. }
  17. public GrassItem(GrassQuad quad, GameObject gameObject)
  18. {
  19. this.quad = quad;
  20. this.gameObject = gameObject;
  21. }
  22. public GrassStar Star
  23. {
  24. get { return this.star; }
  25. }
  26. public GrassQuad Quad
  27. {
  28. get { return this.quad; }
  29. }
  30. public bool Destroyed
  31. {
  32. get { return !this.gameObject; }
  33. }
  34. public Vector2 Position2D
  35. {
  36. get
  37. {
  38. if(this.quad != null)
  39. {
  40. return new Vector2(this.quad.Position.x, this.quad.Position.z);
  41. }
  42. if (this.star != null)
  43. {
  44. return new Vector2(this.star.Position.x, this.star.Position.z);
  45. }
  46. return Vector2.zero;
  47. }
  48. set
  49. {
  50. if (this.quad != null)
  51. {
  52. this.quad.Position = value;
  53. }
  54. else
  55. {
  56. this.star.Position = value;
  57. }
  58. if (!this.gameObject)
  59. {//ignore missing GameObject
  60. return;
  61. }
  62. this.gameObject.transform.position = value;
  63. }
  64. }
  65. public float Size
  66. {
  67. get
  68. {
  69. if (this.quad != null)
  70. {
  71. return this.quad.Width;
  72. }
  73. if (this.star != null)
  74. {
  75. return this.star.Width;
  76. }
  77. return 0;
  78. }
  79. }
  80. public float Height
  81. {
  82. get
  83. {
  84. if (this.quad != null)
  85. {
  86. return this.quad.Position.y;
  87. }
  88. if (this.star != null)
  89. {
  90. return this.star.Position.y;
  91. }
  92. return 0;
  93. }
  94. set
  95. {
  96. if (this.quad != null)
  97. {
  98. var p = this.quad.Position;
  99. this.quad.Position = new Vector3(p.x, value, p.z);
  100. }
  101. if (this.star != null)
  102. {
  103. var p = this.star.Position;
  104. this.star.Position = new Vector3(p.x, value, p.z);
  105. }
  106. {
  107. if (!this.gameObject)
  108. {//ignore missing GameObject
  109. return;
  110. }
  111. var p = this.gameObject.transform.position;
  112. this.gameObject.transform.position = new Vector3(p.x, value, p.z);
  113. }
  114. }
  115. }
  116. public float RotationY
  117. {
  118. get
  119. {
  120. if (this.quad != null)
  121. {
  122. return this.quad.RotationY;
  123. }
  124. if (this.star != null)
  125. {
  126. return this.star.RotationY;
  127. }
  128. return 0;
  129. }
  130. set
  131. {
  132. if (this.quad != null)
  133. {
  134. var p = this.quad.RotationY;
  135. this.quad.RotationY = value;
  136. }
  137. if (this.star != null)
  138. {
  139. var p = this.star.Position;
  140. this.star.RotationY = value;
  141. }
  142. if (!this.gameObject)
  143. {//ignore missing GameObject
  144. return;
  145. }
  146. this.gameObject.transform.rotation = Quaternion.Euler(0, value, 0);
  147. }
  148. }
  149. public Rect Bounds
  150. {
  151. get
  152. {
  153. if (this.quad != null)
  154. {
  155. return new Rect(this.quad.Position.x, this.quad.Position.z,
  156. 0.00001f, 0.00001f);
  157. }
  158. if (this.star != null)
  159. {
  160. return new Rect(this.star.Position.x, this.star.Position.z,
  161. 0.00001f, 0.00001f);
  162. }
  163. return Rect.zero;
  164. }
  165. }
  166. }
  167. }