首页 > 代码库 > EffectManager
EffectManager
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 +"\r\n 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); } }
EffectManager
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。