ParticlePlaybackEditorWindow.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. //[ExecuteInEditMode]
  23. //[System.Serializable]
  24. //[CustomEditor(typeof(ShurikenSpritesheet))]
  25. public class ParticlePlaybackEditorWindow : EditorWindow
  26. {
  27. // =================================
  28. // Nested classes and structures.
  29. // =================================
  30. // ...
  31. // =================================
  32. // Variables.
  33. // =================================
  34. // ...
  35. ParticlePlayback particlePlayback = new ParticlePlayback();
  36. // Selected objects in editor and all the particle systems components.
  37. List<GameObject> selectedGameObjectsWithParticleSystems = new List<GameObject>();
  38. // I also keep last frame's particle systems because I update
  39. // the list of particle systems on update. So clearing particles
  40. // inside the systems may not do anything as the particles are
  41. // updated and the list set to a length of zero before OnSelectionChange.
  42. List<ParticleSystem> particleSystems = new List<ParticleSystem>();
  43. List<ParticleSystem> particleSystemsFromLastFrame = new List<ParticleSystem>();
  44. // =================================
  45. // Functions.
  46. // =================================
  47. // Create.
  48. [MenuItem("Window/Mirza Beig/Particle Playback")]
  49. static void showEditor()
  50. {
  51. // Get window reference.
  52. ParticlePlaybackEditorWindow window =
  53. EditorWindow.GetWindow<ParticlePlaybackEditorWindow>(false, "Mirza Beig - Particle Playback");
  54. // Static init.
  55. // ...
  56. // Invoke non-static init.
  57. window.initialize();
  58. // Do a first check.
  59. window.OnSelectionChange();
  60. }
  61. // Initialize.
  62. void initialize()
  63. {
  64. }
  65. // ...
  66. void OnSelectionChange()
  67. {
  68. // Clear if set to clear on selection change.
  69. if (particlePlayback.clearParticlesOnSelectionChange)
  70. {
  71. ParticleEditorUtility.clearParticles(particleSystems);
  72. ParticleEditorUtility.clearParticles(particleSystemsFromLastFrame);
  73. particlePlayback.repaintEditorCameraWindows();
  74. }
  75. // Pause all selected particles.
  76. else if (!Application.isPlaying)
  77. {
  78. particlePlayback.pause(particleSystems);
  79. }
  80. // (Re-)verify current list of particles.
  81. ParticleEditorUtility.getSelectedParticleSystems(ref particleSystems, ref selectedGameObjectsWithParticleSystems);
  82. }
  83. // ...
  84. void OnGUI()
  85. {
  86. // Looks nicer.
  87. EditorGUILayout.Separator();
  88. // Playback settings.
  89. particlePlayback.GUIPlaybackSettings(particleSystems);
  90. EditorGUILayout.Separator();
  91. // Selected objects.
  92. particlePlayback.GUIParticleSelection(selectedGameObjectsWithParticleSystems);
  93. }
  94. // ...
  95. void OnInspectorUpdate()
  96. {
  97. Repaint();
  98. }
  99. // ...
  100. void Update()
  101. {
  102. // (Re-)verify current list of particles.
  103. particleSystemsFromLastFrame =
  104. new List<ParticleSystem>(particleSystems);
  105. ParticleEditorUtility.getSelectedParticleSystems(
  106. ref particleSystems, ref selectedGameObjectsWithParticleSystems);
  107. particlePlayback.update(particleSystems);
  108. }
  109. // ...
  110. void OnFocus()
  111. {
  112. }
  113. // =================================
  114. // End functions.
  115. // =================================
  116. }
  117. // =================================
  118. // End namespace.
  119. // =================================
  120. }
  121. }
  122. }
  123. // =================================
  124. // --END-- //
  125. // =================================