using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
public class Delay : MonoBehaviour {
public float delayTime = 1.0f;
private bool isDelayCallBack = false;
private List<GameObject> gameObjects = new List<GameObject>();
void OnEnable()
{
//find all animation
Animator[] animators = gameObject.GetComponentsInChildren<Animator>();
for (int i = 0; i < animators.Length; i++)
{
gameObjects.Add(animators[i].gameObject);
}
//
if (!isDelayCallBack)
{
isDelayCallBack = true;
for (int i = 0; i < gameObjects.Count; i++)
{
gameObjects[i].SetActive(false);
Invoke("DelayFunc", delayTime);
}
}
}
void DelayFunc()
{
for (int i = 0; i < gameObjects.Count; i++)
{
gameObjects[i].SetActive(true);
}
isDelayCallBack = false;
}
public void SetDelay()
{
ParticleSystem[] ps = gameObject.GetComponentsInChildren<ParticleSystem>();
for (int j = 0; j < ps.Length; j++)
{
var main = ps[j].main;
main.startDelay = delayTime;
}
}
}
[CustomEditor(typeof(Delay))]
public class DelayEditor : Editor {
public override void OnInspectorGUI()
{
serializedObject.Update();
Delay delay = (Delay)target;
delay.delayTime = EditorGUILayout.FloatField("DelayTime", delay.delayTime);
if (GUILayout.Button("SetDelay"))
delay.SetDelay();
}
}