123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- [CustomEditor(typeof(ParticleAndAnimation))]
- public class ParticleAndAnimation : Editor
- {
- private static GameObject SelectObj;
- #if UNITY_EDITOR
- void Start ()
- {
- PlayOnce();
- }
- #endif
- [MenuItem("Tools/Play Loop %l")]
- //[ContextMenu("Play Loop")]
- public static void PlayLoop()
- {
- Object[] objs = Selection.objects;
- if(objs.Length > 0)
- {
- ParticleAndAnimation.SelectObj = objs[0] as GameObject;
- }
- //PlaySelf(gameObject, true);
- Transform[] trans = SelectObj.GetComponentsInChildren<Transform>(true);
- foreach(Transform t in trans)
- {
- DelayPlay d = t.GetComponent<DelayPlay>();
- if (d != null)
- {
- if (d.delayTime >= 0)
- {
- d.InvokePlay(true, false);
- }
- }
- else
- {
- PlaySelf(t.gameObject, true);
- }
- }
- }
- //[ContextMenu("Play Once")]
- [MenuItem("Tools/Play Once %;")]
- public static void PlayOnce ()
- {
- //PlaySelf(gameObject, false);
- Object[] objs = Selection.objects;
- if (objs.Length > 0)
- {
- ParticleAndAnimation.SelectObj = objs[0] as GameObject;
- }
- Transform[] trans = SelectObj.GetComponentsInChildren<Transform>(true);
- foreach(Transform t in trans)
- {
- DelayPlay d = t.GetComponent<DelayPlay>();
- if (d != null)
- {
- if (d.delayTime >= 0)
- {
- d.InvokePlay(false, false);
- }
- }
- else
- {
- PlaySelf(t.gameObject, false);
- }
- }
- }
- void PlaySelfAndAllChildren(GameObject obj, bool loop)
- {
- if (obj == null)
- return;
- //EnableChildrenAll(obj, true);
-
- ParticleSystem[] pss = obj.GetComponentsInChildren<ParticleSystem>(true);
- foreach(ParticleSystem ps in pss)
- {
- ps.loop = loop;
- ps.Clear(true);
- ps.Play();
- }
-
- Animation[] anis = obj.GetComponentsInChildren<Animation>(true);
- foreach(Animation an in anis)
- {
- an.wrapMode = loop? WrapMode.Loop : WrapMode.Once;
- an.Play();
- }
-
- Animator[] amts = obj.GetComponentsInChildren<Animator>();
- foreach(Animator amt in amts)
- {
- if (null != amt)
- {
- #if UNITY_5
- AnimatorClipInfo[] infs = amt.GetCurrentAnimatorClipInfo(0);
- foreach (AnimatorClipInfo info in infs)
- {
- info.clip.wrapMode = loop? WrapMode.Loop : WrapMode.Once;
- amt.Play(info.clip.name, -1, 0);
- break;
- }
- #else
- AnimatorClipInfo[] infs = amt.GetCurrentAnimatorClipInfo(0);
- foreach (AnimatorClipInfo info in infs)
- {
- info.clip.wrapMode = loop? WrapMode.Loop : WrapMode.Once;
- amt.Play(info.clip.name, -1, 0);
- break;
- }
- #endif
- }
- }
- }
- static void PlaySelf(GameObject obj, bool loop)
- {
- if (obj == null)
- return;
- ParticleSystem ps = obj.GetComponent<ParticleSystem>();
- if (null != ps)
- {
- ps.loop = loop;
- ps.Clear(true);
- ps.time = 0f;
- ps.Play();
- }
- Animation anim = obj.GetComponent<Animation>();
- if (null != anim)
- {
- anim.wrapMode = loop? WrapMode.Loop : WrapMode.Once;
- anim.Play();
- }
-
- Animator amt = obj.GetComponent<Animator>();
- if (null != amt)
- {
- #if UNITY_5
- AnimatorClipInfo[] infs = amt.GetCurrentAnimatorClipInfo(0);
- foreach (AnimatorClipInfo info in infs)
- {
- info.clip.wrapMode = loop? WrapMode.Loop : WrapMode.Once;
- amt.Play(info.clip.name, -1, 0);
- break;
- }
- #else
- AnimatorClipInfo[] infs = amt.GetCurrentAnimatorClipInfo(0);
- foreach (AnimatorClipInfo info in infs)
- {
- info.clip.wrapMode = loop? WrapMode.Loop : WrapMode.Once;
- amt.Play(info.clip.name, -1, 0);
- break;
- }
- #endif
- }
- //EnableChildrenAll(obj, true);
- }
-
- public void EnableChildrenAll(GameObject obj, bool enable)
- {
- if (obj == null)
- return;
- for (int i = obj.transform.childCount - 1; i >= 0; i--)
- {
- obj.transform.GetChild(i).gameObject.SetActive(enable);
- }
- }
- }
|