using UnityEngine; using System.Collections; public class EffectManager : MonoBehaviour { public Animator[] Animators; public float amplify; public float curAmplify; public float totalEffectDelayTime; public Transform MoveTarget; public ParticleEffect particleEffect; public AnimatorOffsetChangeEffect animatorOffsetChangeEffect; public AnimatorMeshChangeEffect animatorMeshChangeEffect; public enum EffectType { Particles, AnimatorOffsetChange, AnimatorMeshChange } public EffectType effectType; void Start () { SetEffectSpeed(); EffectMoveToTarget(); } void Update () { } void OnEnable() { if (animatorOffsetChangeEffect.middleEffectNode.rootNode != null) { animatorOffsetChangeEffect.middleEffectNode.rootNode.transform.position = animatorOffsetChangeEffect.frontEffectNode.rootNode.transform.position; animatorOffsetChangeEffect.middleEffectNode.rootNode.SetActive(true); } Start(); } private bool isFirst = true; public void SetEffectSpeed() { //for (int i = 0; i < ParticlesSetStartDelay.Length; i++) { // ParticlesSetStartDelay[i].startDelay /=amplify; //} //for (int i = 0; i < ParticlesSetDuration.Length; i++) { // ParticlesSetDuration[i].startLifetime /=amplify; //} if (isFirst) { isFirst = false; } else return; Effect effect; if (effectType == EffectType.Particles) { effect = particleEffect; if (effect.middleEffectNode != null) { for (int i = 0; i < effect.middleEffectNode.Particles.Length; i++) { effect.middleEffectNode.Particles[i].startSpeed *= amplify; } } } else if (effectType == EffectType.AnimatorOffsetChange) { effect = animatorOffsetChangeEffect; for (int i = 0; i < Animators.Length; i++) { Animators[i].speed *= amplify; } if (effect.middleEffectNode != null) { effect.middleEffectNode.durationTime /= amplify; effect.middleEffectNode.startDelayTime /= amplify; } } else { effect = animatorMeshChangeEffect; for (int i = 0; i < Animators.Length; i++) { Animators[i].speed *= amplify; } } if (effect.frontEffectNode != null) { for (int i = 0; i < effect.frontEffectNode.Particles.Length; i++) { effect.frontEffectNode.Particles[i].startDelay /= amplify; effect.frontEffectNode.Particles[i].startLifetime /= amplify; } } if (effect.lastEffectNode != null) { for (int i = 0; i < effect.lastEffectNode.Particles.Length; i++) { effect.lastEffectNode.Particles[i].startDelay /= amplify; effect.lastEffectNode.Particles[i].startLifetime /= amplify; } } } public void EffectMoveToTarget() { if (effectType == EffectType.Particles) { particleEffect.EffectMoveToTarget(MoveTarget); } else if (effectType == EffectType.AnimatorOffsetChange) { animatorOffsetChangeEffect.EffectMoveToTarget(MoveTarget); } else { animatorMeshChangeEffect.EffectMoveToTarget(MoveTarget); } //Debug.Log(frontEffectTime); //Hashtable args = new Hashtable(); //args.Add("position", MoveTarget.position); //args.Add("time", middleEffectTime); //args.Add("delay", frontEffectTime); //args.Add("easeType", iTween.EaseType.easeInQuad); ////args.Add("isLocal", true); //iTween.MoveTo(MiddleEffect, args); //LastEffect.transform.position = MoveTarget.transform.position; } private void middleEffectNodeReachEvent() { animatorOffsetChangeEffect.middleEffectNode.rootNode.SetActive(false); } } [System.Serializable] public class EffectNode { public GameObject rootNode; public ParticleSystem[] Particles; public float startDelayTime; public float durationTime; } public abstract class Effect { public EffectNode frontEffectNode; public EffectNode middleEffectNode; public EffectNode lastEffectNode; public abstract void EffectMoveToTarget(Transform target); } [System.Serializable] public class AnimatorOffsetChangeEffect : Effect { public override void EffectMoveToTarget(Transform target) { //middleEffectNode.rootNode.transform.LookAt(target); Hashtable args = new Hashtable(); args.Add("position", target.position); args.Add("time", middleEffectNode.durationTime); args.Add("delay", middleEffectNode.startDelayTime); args.Add("easeType", iTween.EaseType.linear); //args.Add("looktarget", target.position); if (isHideMiddle) { args.Add("oncomplete", "middleEffectNodeReachEvent"); args.Add("oncompletetarget", frontEffectNode.rootNode.transform.parent.gameObject); } iTween.MoveTo(middleEffectNode.rootNode, args); lastEffectNode.rootNode.transform.position = target.position; } public bool isHideMiddle; } [System.Serializable] public class ParticleEffect : Effect { public override void EffectMoveToTarget(Transform target) { middleEffectNode.rootNode.transform.LookAt(target); float dis = Vector3.Distance(frontEffectNode.rootNode.transform.position, target.position); middleEffectNode.Particles[0].startSpeed = dis / middleEffectNode.durationTime; lastEffectNode.rootNode.transform.position = target.position; } } [System.Serializable] public class AnimatorMeshChangeEffect : Effect { public override void EffectMoveToTarget(Transform target) { Vector3 dirV = (target.position - middleEffectNode.rootNode.transform.position).normalized; middleEffectNode.rootNode.transform.right = dirV; lastEffectNode.rootNode.transform.position = target.position; } }
using UnityEngine; using System.Collections; public class ShowParticleCout : MonoBehaviour { //定义发射器组件 //粒子数量接受变量 ParticleSystem a = null; public int banjing=0; int a_particleCout=0; // Use this for initialization void Start () { a = GetComponent<ParticleSystem>(); } // Update is called once per frame void Update () { if(a !=null){ //Debug.Log("粒子数:"+ a.particleCount); a_particleCout=a.particleCount; } } public int getParticleCout(){ //返回粒子数 return a_particleCout; } void OnGUI() { string showParticleCout = "粒子数是:" + a_particleCout; GUI.Label(new Rect(10, 10,showParticleCout.Length * 20 , 40),showParticleCout +" asdfasdfa" ); } }
using UnityEngine; using System.Collections; public class Delay : MonoBehaviour { public float delayTime = 1.0f; // Use this for initialization void Start () { gameObject.SetActiveRecursively(false); Invoke("DelayFunc", delayTime); } void DelayFunc() { gameObject.SetActiveRecursively(true); } }