VFXExpressionCast.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using System.Linq;
  3. using System.Runtime.CompilerServices;
  4. using UnityEngine;
  5. using UnityEngine.VFX;
  6. namespace UnityEditor.VFX
  7. {
  8. class VFXExpressionCastUintToFloat : VFXExpression
  9. {
  10. public VFXExpressionCastUintToFloat() : this(VFXValue<uint>.Default)
  11. {
  12. }
  13. public VFXExpressionCastUintToFloat(VFXExpression from) : base(Flags.None, new VFXExpression[1] { from })
  14. {
  15. if (from.valueType != VFXValueType.Uint32)
  16. throw new InvalidCastException("Invalid VFXExpressionCastUintToFloat");
  17. }
  18. sealed public override VFXExpressionOperation operation
  19. {
  20. get
  21. {
  22. return VFXExpressionOperation.CastUintToFloat;
  23. }
  24. }
  25. sealed protected override VFXExpression Evaluate(VFXExpression[] reducedParents)
  26. {
  27. return VFXValue.Constant((float)reducedParents[0].Get<uint>());
  28. }
  29. sealed public override string GetCodeString(string[] parents)
  30. {
  31. return string.Format("(float){0}", parents[0]);
  32. }
  33. }
  34. class VFXExpressionCastIntToFloat : VFXExpression
  35. {
  36. public VFXExpressionCastIntToFloat() : this(VFXValue<int>.Default)
  37. {
  38. }
  39. public VFXExpressionCastIntToFloat(VFXExpression from) : base(Flags.None, new VFXExpression[1] { from })
  40. {
  41. if (from.valueType != VFXValueType.Int32)
  42. throw new InvalidCastException("Invalid VFXExpressionCastIntToFloat");
  43. }
  44. sealed public override VFXExpressionOperation operation
  45. {
  46. get
  47. {
  48. return VFXExpressionOperation.CastIntToFloat;
  49. }
  50. }
  51. sealed protected override VFXExpression Evaluate(VFXExpression[] reducedParents)
  52. {
  53. return VFXValue.Constant((float)reducedParents[0].Get<int>());
  54. }
  55. sealed public override string GetCodeString(string[] parents)
  56. {
  57. return string.Format("(float){0}", parents[0]);
  58. }
  59. }
  60. class VFXExpressionCastFloatToUint : VFXExpression
  61. {
  62. public VFXExpressionCastFloatToUint() : this(VFXValue<float>.Default)
  63. {
  64. }
  65. public VFXExpressionCastFloatToUint(VFXExpression from) : base(Flags.None, new VFXExpression[1] { from })
  66. {
  67. if (from.valueType != VFXValueType.Float)
  68. throw new InvalidCastException("Invalid VFXExpressionCastFloatToUint");
  69. }
  70. sealed public override VFXExpressionOperation operation
  71. {
  72. get
  73. {
  74. return VFXExpressionOperation.CastFloatToUint;
  75. }
  76. }
  77. sealed protected override VFXExpression Evaluate(VFXExpression[] reducedParents)
  78. {
  79. return VFXValue.Constant((uint)reducedParents[0].Get<float>());
  80. }
  81. sealed public override string GetCodeString(string[] parents)
  82. {
  83. return string.Format("(uint){0}", parents[0]);
  84. }
  85. }
  86. class VFXExpressionCastIntToUint : VFXExpression
  87. {
  88. public VFXExpressionCastIntToUint() : this(VFXValue<int>.Default)
  89. {
  90. }
  91. public VFXExpressionCastIntToUint(VFXExpression from) : base(Flags.None, new VFXExpression[1] { from })
  92. {
  93. if (from.valueType != VFXValueType.Int32)
  94. throw new InvalidCastException("Invalid VFXExpressionCastIntToUint");
  95. }
  96. sealed public override VFXExpressionOperation operation
  97. {
  98. get
  99. {
  100. return VFXExpressionOperation.CastIntToUint;
  101. }
  102. }
  103. sealed protected override VFXExpression Evaluate(VFXExpression[] reducedParents)
  104. {
  105. return VFXValue.Constant((uint)reducedParents[0].Get<int>());
  106. }
  107. sealed public override string GetCodeString(string[] parents)
  108. {
  109. return string.Format("(uint){0}", parents[0]);
  110. }
  111. }
  112. class VFXExpressionCastFloatToInt : VFXExpression
  113. {
  114. public VFXExpressionCastFloatToInt() : this(VFXValue<float>.Default)
  115. {
  116. }
  117. public VFXExpressionCastFloatToInt(VFXExpression from) : base(Flags.None, new VFXExpression[1] { from })
  118. {
  119. if (from.valueType != VFXValueType.Float)
  120. throw new InvalidCastException("Invalid VFXExpressionCastFloatToInt");
  121. }
  122. sealed public override VFXExpressionOperation operation
  123. {
  124. get
  125. {
  126. return VFXExpressionOperation.CastFloatToInt;
  127. }
  128. }
  129. sealed protected override VFXExpression Evaluate(VFXExpression[] reducedParents)
  130. {
  131. return VFXValue.Constant((int)reducedParents[0].Get<float>());
  132. }
  133. sealed public override string GetCodeString(string[] parents)
  134. {
  135. return string.Format("(int){0}", parents[0]);
  136. }
  137. }
  138. class VFXExpressionCastUintToInt : VFXExpression
  139. {
  140. public VFXExpressionCastUintToInt() : this(VFXValue<uint>.Default)
  141. {
  142. }
  143. public VFXExpressionCastUintToInt(VFXExpression from) : base(Flags.None, new VFXExpression[1] { from })
  144. {
  145. if (from.valueType != VFXValueType.Uint32)
  146. throw new InvalidCastException("Invalid VFXExpressionCastUintToInt");
  147. }
  148. sealed public override VFXExpressionOperation operation
  149. {
  150. get
  151. {
  152. return VFXExpressionOperation.CastUintToInt;
  153. }
  154. }
  155. sealed protected override VFXExpression Evaluate(VFXExpression[] reducedParents)
  156. {
  157. return VFXValue.Constant((int)reducedParents[0].Get<uint>());
  158. }
  159. sealed public override string GetCodeString(string[] parents)
  160. {
  161. return string.Format("(int){0}", parents[0]);
  162. }
  163. }
  164. }