UIParticleAdd.cs 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UIExtensions;
  4. public class UIParticleAdd
  5. {
  6. [MenuItem("GameObject/UIParticleAdd", false, 22)]
  7. public static void AddUIParticle()
  8. {
  9. GameObject go = Selection.activeGameObject;
  10. ParticleSystem[] array = go.GetComponentsInChildren<ParticleSystem>();
  11. for (int i = 0; i < array.Length; ++i)
  12. {
  13. GameObject obj = array[i].gameObject;
  14. if (obj.GetComponent<RectTransform>() == null)
  15. ObjectFactory.AddComponent<RectTransform>(obj);
  16. UIParticle particle = obj.GetComponent<UIParticle>() == null ? obj.AddComponent<UIParticle>() : obj.GetComponent<UIParticle>();
  17. particle.cachedParticleSystem = array[i];
  18. if (i == 0)
  19. {
  20. UINode node = obj.GetComponent<UINode>() == null ? obj.AddComponent<UINode>() : obj.GetComponent<UINode>();
  21. node.UIName = go.name.ToLower();
  22. }
  23. }
  24. EditorUtility.SetDirty(go);
  25. }
  26. }