ParticleEditorUtility.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. 
  2. // =================================
  3. // Namespaces.
  4. // =================================
  5. using UnityEngine;
  6. using UnityEditor;
  7. using System.Linq;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. // =================================
  11. // Define namespace.
  12. // =================================
  13. namespace MirzaBeig
  14. {
  15. namespace EditorExtensions
  16. {
  17. namespace Utilities
  18. {
  19. // =================================
  20. // Classes.
  21. // =================================
  22. public class ParticleEditorUtility
  23. {
  24. // =================================
  25. // Nested classes and structures.
  26. // =================================
  27. // ...
  28. // =================================
  29. // Variables.
  30. // =================================
  31. // ...
  32. // =================================
  33. // Functions.
  34. // =================================
  35. // Clear all active particles.
  36. public static void clearParticles(List<ParticleSystem> particleSystems)
  37. {
  38. for (int i = 0; i < particleSystems.Count; i++)
  39. {
  40. if (particleSystems[i])
  41. {
  42. particleSystems[i].Clear(false);
  43. }
  44. }
  45. }
  46. // Get a list of particle system components from all selected GameObjects as well as the gameObjects themselves.
  47. public static void getSelectedParticleSystems(ref List<ParticleSystem> particleSystems, ref List<GameObject> selectedGameObjectsWithParticleSystems)
  48. {
  49. // Clear for updated selection.
  50. particleSystems.Clear();
  51. // NOTE: These do the same thing, but I'm not sure which one is better/faster/more efficient.
  52. // I _think_ the second method is faster because when I select a GO in the hierarchy with a large
  53. // number of embedded particles, it seems to cause the least delay.
  54. // SelectedGameObjects == all objects which either have a particle system on them, or in at least one child.
  55. //selectedGameObjectsWithParticleSystems = Selection.gameObjects.Where(
  56. // selected => selected.GetComponentsInChildren<ParticleSystem>(true) != null).ToList();
  57. //// All the particle systems in all selected.
  58. //for (int i = 0; i < selectedGameObjectsWithParticleSystems.Count; i++)
  59. //{
  60. // // Merge to self while ignoring duplicate components.
  61. // particleSystems = particleSystems.Union(selectedGameObjectsWithParticleSystems[i].GetComponentsInChildren<ParticleSystem>(true)).ToList();
  62. //}
  63. // Allows selection of inactive objects.
  64. // In this version, the parameters can be lists rather than arrays so I can
  65. // just use Selection.GetFiltered(typeof(GameObject), SelectionMode.TopLevel) as GameObject[]
  66. // as rather than running a loop to add converted elements.
  67. Object[] selectedObjects =
  68. Selection.GetFiltered(typeof(GameObject), SelectionMode.TopLevel);
  69. selectedGameObjectsWithParticleSystems.Clear();
  70. for (int i = 0; i < selectedObjects.Length; i++)
  71. {
  72. selectedGameObjectsWithParticleSystems.Add(selectedObjects[i] as GameObject);
  73. }
  74. for (int i = 0; i < selectedGameObjectsWithParticleSystems.Count; i++)
  75. {
  76. // Merge to self while ignoring duplicate components.
  77. particleSystems.AddRange(selectedGameObjectsWithParticleSystems[i].GetComponentsInChildren<ParticleSystem>(true));
  78. }
  79. }
  80. // =================================
  81. // End functions.
  82. // =================================
  83. }
  84. // =================================
  85. // End namespace.
  86. // =================================
  87. }
  88. }
  89. }
  90. // =================================
  91. // --END-- //
  92. // =================================