FTME01_ParticleController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using ParticlePlayground;
  5. [ExecuteInEditMode()]
  6. public class FTME01_ParticleController : MonoBehaviour {
  7. //scale parameter
  8. public float scale = 1f;
  9. public float scaleLife = 1f;
  10. //public float deadtime = 10;
  11. //lifetime parameter
  12. List<float> origLifetime = new List<float>();
  13. List<float> origSpeed = new List<float>();
  14. Animator[] anim;
  15. //color parameter
  16. public List<Gradient> particleColor = new List<Gradient>();
  17. //particleplayground
  18. public PlaygroundParticlesC[] particleSystems;
  19. //child script
  20. FTME01_ScaleStateSize[] childScaleState;
  21. FTME01_ParticleScaler[] childScaleParticle;
  22. FTME01_ScaleManipulatorSize[] childScaleManipulator;
  23. FTME01_ScaleMesh[] childScaleMesh;
  24. FTME01_ScaleLight[] childScaleLight;
  25. void OnEnable () {
  26. //Get ParticlePlayground and other component.
  27. if (childScaleState==null){
  28. childScaleState = transform.GetComponentsInChildren<FTME01_ScaleStateSize>();
  29. }
  30. if (childScaleParticle==null){
  31. childScaleParticle = transform.GetComponentsInChildren<FTME01_ParticleScaler>();
  32. }
  33. if (childScaleManipulator==null){
  34. childScaleManipulator = transform.GetComponentsInChildren<FTME01_ScaleManipulatorSize>();
  35. }
  36. if (childScaleMesh==null){
  37. childScaleMesh = transform.GetComponentsInChildren<FTME01_ScaleMesh>();
  38. }
  39. if (childScaleLight==null){
  40. childScaleLight = transform.GetComponentsInChildren<FTME01_ScaleLight>();
  41. }
  42. //Set initial value.
  43. for (int i = 0; i < childScaleState.Length; i++) {
  44. childScaleState[i].ScaleStateSizeOnEnable();
  45. }
  46. for (int i = 0; i < childScaleParticle.Length; i++) {
  47. childScaleParticle[i].ParticleScaleOnEnable();
  48. }
  49. for (int i = 0; i < childScaleManipulator.Length; i++) {
  50. childScaleManipulator[i].ScaleManipulatorSizeOnEnable();
  51. }
  52. for (int i = 0; i < childScaleMesh.Length; i++) {
  53. childScaleMesh[i].ScaleMeshOnEnable();
  54. }
  55. for (int i = 0; i < childScaleLight.Length; i++) {
  56. childScaleLight[i].ScaleLightRangeOnEnable();
  57. }
  58. anim = transform.GetComponentsInChildren<Animator>();
  59. //particleSystems = transform.GetComponentsInChildren<PlaygroundParticlesC>();
  60. if (particleColor.Count == 0){
  61. for (int i = 0; i < particleSystems.Length; i++) {
  62. particleColor.Add(particleSystems[i].lifetimeColor);
  63. }
  64. }
  65. }
  66. void OnDisable () {
  67. for (int i = 0; i < childScaleState.Length; i++) {
  68. childScaleState[i].ScaleStateSizeOnDisable();
  69. }
  70. for (int i = 0; i < childScaleParticle.Length; i++) {
  71. childScaleParticle[i].ParticleScaleOnDisable();
  72. }
  73. for (int i = 0; i < childScaleManipulator.Length; i++) {
  74. childScaleManipulator[i].ScaleManipulatorSizeOnDisable();
  75. }
  76. for (int i = 0; i < childScaleMesh.Length; i++) {
  77. childScaleMesh[i].ScaleMeshOnDisable();
  78. }
  79. for (int i = 0; i < childScaleLight.Length; i++) {
  80. childScaleLight[i].ScaleLightRangeOnDisable();
  81. }
  82. }
  83. public void Update () {
  84. //Scaling particle
  85. for (int i = 0; i < childScaleState.Length; i++) {
  86. childScaleState[i].scaleState = scale;
  87. childScaleState[i].ScaleStateSize();
  88. }
  89. for (int i = 0; i < childScaleParticle.Length; i++) {
  90. childScaleParticle[i].scaleSize = scale;
  91. childScaleParticle[i].ParticleScale();
  92. }
  93. for (int i = 0; i < childScaleManipulator.Length; i++) {
  94. childScaleManipulator[i].scaleManipulatorSize = scale;
  95. childScaleManipulator[i].ScaleManipulatorSize();
  96. }
  97. for (int i = 0; i < childScaleMesh.Length; i++) {
  98. childScaleMesh[i].scaleMeshSize = scale;
  99. childScaleMesh[i].ScaleMesh();
  100. }
  101. for (int i = 0; i < childScaleLight.Length; i++) {
  102. childScaleLight[i].scaleLightRangeSize = scale;
  103. childScaleLight[i].ScaleLightRange();
  104. }
  105. //Scale lifetime.
  106. for (int i = 0; i < anim.Length; i++) {
  107. origSpeed.Add(anim[i].speed);
  108. anim[i].speed = origSpeed[i]*(1/scaleLife);
  109. }
  110. for (int i = 0; i < particleSystems.Length; i++) {
  111. origLifetime.Add(particleSystems[i].lifetime);
  112. particleSystems [i].lifetime = origLifetime[i] * scaleLife;
  113. }
  114. for (int i = 0; i < particleColor.Count; i++) {
  115. particleSystems[i].lifetimeColor = particleColor[i];
  116. }
  117. }
  118. public void GetColor () {
  119. if (particleColor.Count == 0){
  120. for (int i = 0; i < particleSystems.Length; i++) {
  121. particleColor.Add(particleSystems[i].lifetimeColor);
  122. }
  123. }
  124. }
  125. public void ClearColor () {
  126. if(particleColor != null)
  127. particleColor.Clear();
  128. }
  129. /*void Awake (){
  130. if (deadtime != 0) {
  131. Destroy (gameObject, deadtime);
  132. }
  133. }*/
  134. }