UI_ParticleRange.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. using System;
  2. using UnityEngine;
  3. public class UI_ParticleRange : UI_ScreenFitBase
  4. {
  5. protected override void Start()
  6. {
  7. this.m_MyParticle = base.GetComponent<ParticleSystem>();
  8. this.m_FirstLifeTime = this.m_MyParticle.main.startLifetimeMultiplier;
  9. this.m_FirstSpeed = this.m_MyParticle.main.startSpeedMultiplier;
  10. this.m_FirstCircleRange = this.m_MyParticle.shape.radius;
  11. this.m_FirstBoxRange = this.m_MyParticle.shape.box;
  12. this.m_FirstSize = this.m_MyParticle.main.startSizeMultiplier;
  13. this.m_FirstSize3D.x = this.m_MyParticle.main.startSizeXMultiplier;
  14. this.m_FirstSize3D.y = this.m_MyParticle.main.startSizeYMultiplier;
  15. this.m_FirstSize3D.z = this.m_MyParticle.main.startSizeZMultiplier;
  16. if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.Circle)
  17. {
  18. base.transform.localScale = base.ScreenRate(0f, 1f, 1f) * Vector3.one;
  19. }
  20. base.Start();
  21. }
  22. protected override void Update()
  23. {
  24. base.Update();
  25. }
  26. protected override void FitAction()
  27. {
  28. this.m_MyParticle.shape.box = this.m_FirstBoxRange;
  29. UI_ParticleRange.ParticleRangeType rangeType = this.m_RangeType;
  30. switch (rangeType)
  31. {
  32. case UI_ParticleRange.ParticleRangeType.Circle:
  33. case UI_ParticleRange.ParticleRangeType.CircleHorizontal:
  34. case UI_ParticleRange.ParticleRangeType.CircleVirtical:
  35. this.FitShapeCircle();
  36. break;
  37. case UI_ParticleRange.ParticleRangeType.Cone:
  38. this.FitShapeCone();
  39. break;
  40. default:
  41. if (rangeType != UI_ParticleRange.ParticleRangeType.None)
  42. {
  43. this.FitShapeBox();
  44. }
  45. break;
  46. case UI_ParticleRange.ParticleRangeType.EdgeHorizontal:
  47. case UI_ParticleRange.ParticleRangeType.EdgeVertical:
  48. this.FitShapeEdge();
  49. break;
  50. }
  51. }
  52. private void FitShapeBox()
  53. {
  54. ParticleSystem.ShapeModule shape = this.m_MyParticle.shape;
  55. ParticleSystem.MainModule main = this.m_MyParticle.main;
  56. Vector3 zero = Vector3.zero;
  57. UI_ParticleRange.ParticleRangeType rangeType = this.m_RangeType;
  58. if (rangeType != UI_ParticleRange.ParticleRangeType.ScreenHorizontal)
  59. {
  60. if (rangeType != UI_ParticleRange.ParticleRangeType.ScreenVertical)
  61. {
  62. if (rangeType == UI_ParticleRange.ParticleRangeType.ScreenAll)
  63. {
  64. zero.x = (float)Screen.width;
  65. zero.y = (float)Screen.height;
  66. }
  67. }
  68. else
  69. {
  70. zero.y = (float)Screen.height;
  71. }
  72. }
  73. else
  74. {
  75. zero.x = (float)Screen.width;
  76. }
  77. if (UI_ScreenFitBase.m_NGUICamera)
  78. {
  79. Vector3 vector = UI_ScreenFitBase.m_NGUICamera.ScreenToWorldPoint(zero) - UI_ScreenFitBase.m_NGUICamera.transform.position;
  80. Vector3 zero2 = Vector3.zero;
  81. UI_ParticleRange.ParticleRangeType rangeType2 = this.m_RangeType;
  82. if (rangeType2 != UI_ParticleRange.ParticleRangeType.ScreenHorizontal)
  83. {
  84. if (rangeType2 != UI_ParticleRange.ParticleRangeType.ScreenVertical)
  85. {
  86. if (rangeType2 == UI_ParticleRange.ParticleRangeType.ScreenAll)
  87. {
  88. zero2.x = vector.x * 2f;
  89. zero2.y = vector.y * 2f;
  90. }
  91. }
  92. else
  93. {
  94. zero2.y = vector.y * 2f;
  95. if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
  96. {
  97. zero2.x = this.m_AsspectRatio.x / this.m_AsspectRatio.y * zero2.y;
  98. }
  99. else if (!this.m_IsSizeAdjust)
  100. {
  101. zero2.x = base.ScreenRate(0f, this.m_FirstBoxRange.x, this.m_FirstBoxRange.x);
  102. }
  103. else
  104. {
  105. zero2.x = base.ScreenRate(0f, this.m_FirstSize3D.x, this.m_FirstSize3D.x);
  106. }
  107. }
  108. }
  109. else
  110. {
  111. zero2.x = vector.x * 2f;
  112. if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
  113. {
  114. zero2.y = this.m_AsspectRatio.y / this.m_AsspectRatio.x * zero2.x;
  115. }
  116. else if (!this.m_IsSizeAdjust)
  117. {
  118. zero2.y = base.ScreenRate(0f, this.m_FirstBoxRange.y, this.m_FirstBoxRange.y);
  119. }
  120. else
  121. {
  122. zero2.y = base.ScreenRate(0f, this.m_FirstSize3D.y, this.m_FirstSize3D.y);
  123. }
  124. }
  125. if (this.m_IsSizeAdjust)
  126. {
  127. shape.box = this.m_FirstBoxRange;
  128. if (main.startSize3D)
  129. {
  130. main.startSizeX = zero2.x;
  131. main.startSizeY = zero2.y;
  132. }
  133. else if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.ScreenHorizontal)
  134. {
  135. main.startSize = zero2.x;
  136. }
  137. else if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.ScreenVertical)
  138. {
  139. main.startSize = zero2.y;
  140. }
  141. }
  142. else
  143. {
  144. shape.box = zero2;
  145. }
  146. }
  147. }
  148. private void FitShapeCircle()
  149. {
  150. ParticleSystem.ShapeModule shape = this.m_MyParticle.shape;
  151. ParticleSystem.MainModule main = this.m_MyParticle.main;
  152. if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.Circle)
  153. {
  154. main.startSpeedMultiplier = base.ScreenRate(this.m_MinSpeed, this.m_FirstSpeed, this.m_FirstSpeed);
  155. main.simulationSpeed = main.startSpeedMultiplier / this.m_FirstSpeed;
  156. base.transform.localScale = base.ScreenRate(0f, 1f, 1f) * Vector3.one;
  157. }
  158. else
  159. {
  160. Vector3 position = Vector3.zero;
  161. if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.CircleHorizontal)
  162. {
  163. position = Vector3.right * (float)Screen.width;
  164. }
  165. else
  166. {
  167. position = Vector3.up * (float)Screen.height;
  168. }
  169. Vector3 vector = UI_ScreenFitBase.m_NGUICamera.ScreenToWorldPoint(position) - UI_ScreenFitBase.m_NGUICamera.transform.position;
  170. if (this.m_IsSizeAdjust)
  171. {
  172. if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.CircleHorizontal)
  173. {
  174. main.startSizeMultiplier = vector.x;
  175. }
  176. else
  177. {
  178. main.startSizeMultiplier = vector.y;
  179. }
  180. }
  181. else if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.CircleHorizontal)
  182. {
  183. shape.radius = vector.x;
  184. }
  185. else
  186. {
  187. shape.radius = vector.y;
  188. }
  189. }
  190. }
  191. private void FitShapeCone()
  192. {
  193. ParticleSystem.MainModule main = this.m_MyParticle.main;
  194. main.startLifetimeMultiplier = base.ScreenRate(this.m_MinLifeTime, this.m_FirstLifeTime, this.m_FirstLifeTime);
  195. main.startSpeedMultiplier = base.ScreenRate(this.m_MinSpeed, this.m_FirstSpeed, this.m_FirstSpeed);
  196. main.simulationSpeed = main.startSpeedMultiplier / this.m_FirstSpeed;
  197. }
  198. private void FitShapeEdge()
  199. {
  200. ParticleSystem.MainModule main = this.m_MyParticle.main;
  201. Vector3 position = Vector3.zero;
  202. if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.EdgeHorizontal)
  203. {
  204. position = Vector3.right * (float)Screen.width;
  205. }
  206. else
  207. {
  208. position = Vector3.up * (float)Screen.height;
  209. }
  210. Vector3 vector = UI_ScreenFitBase.m_NGUICamera.ScreenToWorldPoint(position) - UI_ScreenFitBase.m_NGUICamera.transform.position;
  211. if (!this.m_IsAdjustSpeed)
  212. {
  213. if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.EdgeHorizontal)
  214. {
  215. main.startLifetimeMultiplier = vector.x * 3f / this.m_FirstSpeed;
  216. }
  217. else
  218. {
  219. main.startLifetimeMultiplier = vector.y * 3f / this.m_FirstSpeed;
  220. }
  221. if (this.m_STSync)
  222. {
  223. float b = this.m_FirstSpeed * (main.startLifetimeMultiplier / this.m_FirstLifeTime);
  224. main.startSpeedMultiplier = Mathf.Max(this.m_FirstSpeed, b);
  225. }
  226. else
  227. {
  228. main.startSpeedMultiplier = this.m_FirstSpeed;
  229. }
  230. }
  231. else
  232. {
  233. if (this.m_RangeType == UI_ParticleRange.ParticleRangeType.EdgeHorizontal)
  234. {
  235. main.startSpeedMultiplier = vector.x * 3f / this.m_FirstLifeTime;
  236. }
  237. else
  238. {
  239. main.startSpeedMultiplier = vector.y * 3f / this.m_FirstLifeTime;
  240. }
  241. if (this.m_STSync)
  242. {
  243. float b2 = this.m_FirstLifeTime * (main.startSpeedMultiplier / this.m_FirstSpeed);
  244. main.startLifetimeMultiplier = Mathf.Max(this.m_FirstLifeTime, b2);
  245. }
  246. else
  247. {
  248. main.startLifetimeMultiplier = this.m_FirstLifeTime;
  249. }
  250. }
  251. if (this.m_MyParticle.noise.enabled && this.m_IsNoiseAdjust)
  252. {
  253. Vector3 localScale = base.transform.localScale;
  254. localScale.z = (float)Screen.height / (float)Screen.width;
  255. base.transform.localScale = localScale;
  256. }
  257. }
  258. [SerializeField]
  259. private UI_ParticleRange.ParticleRangeType m_RangeType = UI_ParticleRange.ParticleRangeType.None;
  260. [SerializeField]
  261. [Header("Shapeの大きさではなくStartSizeを直接変えるか")]
  262. private bool m_IsSizeAdjust;
  263. [SerializeField]
  264. [Header("Horizontal・Vertical時の画像の比率((0, 0)で比率固定されない)")]
  265. private Vector2 m_AsspectRatio = Vector2.zero;
  266. [SerializeField]
  267. [Header("パーティクルの最小速度(Circle・Coneで使用)")]
  268. private float m_MinSpeed = 0.15f;
  269. [SerializeField]
  270. [Header("パーティクル最小生存時間(Coneで使用)")]
  271. private float m_MinLifeTime = 0.01f;
  272. [SerializeField]
  273. [Header("ノイズも調整するか")]
  274. private bool m_IsNoiseAdjust;
  275. [SerializeField]
  276. [Header("(Edgeで使用)スピードで範囲調整するか")]
  277. private bool m_IsAdjustSpeed;
  278. [SerializeField]
  279. [Header("(Edgeで使用)速度と生存時間を同期させるか")]
  280. private bool m_STSync;
  281. private ParticleSystem m_MyParticle;
  282. private float m_FirstSize;
  283. private Vector3 m_FirstSize3D;
  284. private Vector3 m_FirstBoxRange;
  285. private float m_FirstCircleRange;
  286. private float m_FirstSpeed;
  287. private float m_FirstLifeTime;
  288. private enum ParticleRangeType
  289. {
  290. ScreenHorizontal,
  291. ScreenVertical,
  292. Circle = 4,
  293. Cone,
  294. ScreenAll,
  295. EdgeHorizontal,
  296. EdgeVertical,
  297. CircleHorizontal,
  298. CircleVirtical,
  299. None = 100
  300. }
  301. }