// Update is called once per frame public override void NetUpdate() { playedTime += FrameReplay.deltaTime; if (pause || PlayDone) { return; } if (playedIndex < source.frames.Count) { if (playedTime < source.frames[0].startTime && mRender.enabled) { mRender.enabled = false; } else if (playedTime >= source.frames[0].startTime && !mRender.enabled && source.Hidden == 0 && EffectType != "DRAG" && tex != null) { mRender.enabled = true; } if (playedTime < source.frames[0].startTime) { return; } ChangeAttackCore(); float timeRatio2 = (playedTime - source.frames[playedIndex - 1].startTime) / (source.frames[playedIndex].startTime - source.frames[playedIndex - 1].startTime); string vertexColor = "_TintColor"; if (source.BlendType == 2) { vertexColor = "_InvColor"; } if (source.EffectType.Equals("BOX")) { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); temp.x = source.origScale.x * source.frames[playedIndex - 1].scale.x; temp.y = source.origScale.y * source.frames[playedIndex - 1].scale.y; temp.z = source.origScale.z * source.frames[playedIndex - 1].scale.z; transform.localScale = temp; } else { OnLastFrame(timeRatio2, vertexColor); temp.x = source.origScale.x * source.frames[playedIndex - 1].scale.x; temp.y = source.origScale.y * source.frames[playedIndex - 1].scale.y; temp.z = source.origScale.z * source.frames[playedIndex - 1].scale.z; temp2.x = source.origScale.x * source.frames[playedIndex].scale.x; temp2.y = source.origScale.y * source.frames[playedIndex].scale.y; temp2.z = source.origScale.z * source.frames[playedIndex].scale.z; transform.localScale = Vector3.Lerp(temp, temp2, timeRatio2); } } else if (source.EffectType.Equals("CYLINDER")) { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } } else if (source.EffectType.Equals("PLANE")) { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } } else if (source.EffectType.Equals("SPHERE")) { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Slerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } } else if (source.EffectType.Equals("BILLBOARD")) { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); if (Camera.main != null) { transform.LookAt(Camera.main.transform); } temp.x = source.origScale.x * source.frames[playedIndex - 1].scale.x; temp.y = source.origScale.y * source.frames[playedIndex - 1].scale.y; temp.z = source.origScale.z * source.frames[playedIndex - 1].scale.z; transform.localScale = temp; } else { OnLastFrame(timeRatio2, vertexColor); if (Camera.main != null) { transform.LookAt(Camera.main.transform); } temp.x = source.origScale.x * source.frames[playedIndex - 1].scale.x; temp.y = source.origScale.y * source.frames[playedIndex - 1].scale.y; temp.z = source.origScale.z * source.frames[playedIndex - 1].scale.z; temp2.x = source.origScale.x * source.frames[playedIndex].scale.x; temp2.y = source.origScale.y * source.frames[playedIndex].scale.y; temp2.z = source.origScale.z * source.frames[playedIndex].scale.z; transform.localScale = Vector3.Lerp(temp, temp2, timeRatio2); } } else if (source.EffectType.Equals("MODEL")) { //第一帧开始时间为-1.表示无限时播放 if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Slerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } } else if (source.EffectType.Equals("PARTICLE")) { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); //transform.localScale = source.frames[playedIndex - 1].scale; ParticleSystemRenderer render = particle.GetComponent <ParticleSystemRenderer>(); render.material.SetColor("_Color", source.frames[playedIndex - 1].colorRGB); render.material.SetColor(vertexColor, source.frames[playedIndex - 1].colorRGB); //粒子不要设置强度了,原版本的粒子实现和UNITY的不一样 render.material.SetFloat("_Intensity", source.multiplyAlpha == 1 ? source.alpha * source.frames[playedIndex - 1].TailFlags[9] : source.frames[playedIndex - 1].TailFlags[9]); //particle.Play(); //particle.Emit(source.MaxParticles); //particle.Simulate(); playedIndex++; //playedTime = 0.0f; } else { OnLastFrame(timeRatio2, vertexColor); } } else if (source.EffectType.Equals("DONUT")) { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } } else if (source.EffectType.Equals("DRAG")) { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } } } else { PlayDone = true; if (parentSfx != null) { parentSfx.OnPlayDone(this); } else { Destroy(gameObject); } } }
//public void SaveParticle(string file) //{ // if (source != null && source.particle != null) // { // System.IO.FileStream fs = System.IO.File.OpenWrite(file); // System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs); // w.Write(source.particle); // w.Flush(); // w.Close(); // fs.Close(); // } //} //原粒子系统是右手坐标系的,转移到左手坐标系后非常多问题,特别是父子关系以及,跟随和子物体旋转叠加 public void Init(SfxEffect effect, SFXEffectPlay parent, int index, float timePlayed = 0.0f, bool preLoad = false) { playedTime = timePlayed; PlayDone = false; transform.rotation = Quaternion.identity; effectIndex = index; parentSfx = parent;//当找不到跟随者的时候,向父询问其他特效是否包含此名称. name = effect.EffectName; EffectType = effect.EffectType; //一个是跟随移动,一个是跟随旋转 mOwner = parent.GetComponent <MeteorUnit>(); source = effect; if (effect.EffectType.Equals("PARTICLE")) { particle = Instantiate(Resources.Load <GameObject>("SFXParticles"), Vector3.zero, Quaternion.identity, transform).GetComponent <ParticleSystem>(); ParticleSystem.MainModule mainModule = particle.main; ParticleSystem.EmissionModule emissionModule = particle.emission; ParticleSystem.ShapeModule shapeModule = particle.shape; emissionModule.rateOverTime = new ParticleSystem.MinMaxCurve(effect.MaxParticles, effect.MaxParticles); mainModule.startLifetime = effect.StartLifetime; mainModule.maxParticles = effect.MaxParticles; mainModule.startSize3D = false; mainModule.startSize = new ParticleSystem.MinMaxCurve(effect.startSizeMin, effect.startSizeMax); mainModule.startSpeed = new ParticleSystem.MinMaxCurve(effect.startSpeedMin, effect.startSpeedMax); mainModule.loop = true; mainModule.duration = 1.0f; //124字节的,烟雾特效,旋转角度 0-360,shape使用box, render使用billboard if (effect.version == 1) { mainModule.startRotation = new ParticleSystem.MinMaxCurve(0, 360); shapeModule.shapeType = ParticleSystemShapeType.Box; shapeModule.box = new Vector3(effect.startSizeMin, 0, effect.startSizeMax); ParticleSystemRenderer r = particle.GetComponent <ParticleSystemRenderer>(); r.renderMode = ParticleSystemRenderMode.Billboard; r.minParticleSize = 0.1f; r.maxParticleSize = 0.1f; } } if (string.IsNullOrEmpty(effect.Bone0)) { PositionFollow = mOwner == null ? parentSfx.transform : mOwner.transform; } else if (effect.Bone0.Equals("ROOT")) { PositionFollow = mOwner == null ? parent.transform : mOwner.ROOTNull; } else if (effect.Bone0.Equals("Character"))//根骨骼上一级,角色,就是不随着b骨骼走,但是随着d_base走 { PositionFollow = mOwner == null ? parent.transform: mOwner.RootdBase; } else { PositionFollow = FindFollowed(effect.Bone0); } if (string.IsNullOrEmpty(effect.Bone1)) { RotateFollow = mOwner == null ? parent.transform : mOwner.transform; } else if (effect.Bone1.Equals("ROOT")) { RotateFollow = mOwner == null ? parent.transform : mOwner.ROOTNull; } else if (effect.Bone1.Equals("Character")) { RotateFollow = mOwner == null ? parent.transform : mOwner.RootdBase; } else { RotateFollow = FindFollowed(effect.Bone1); } if (PositionFollow != null) { transform.position = PositionFollow.transform.position; } mRender = gameObject.GetComponent <MeshRenderer>(); mFilter = gameObject.GetComponent <MeshFilter>(); int meshIndex = -1; if (effect.EffectType.Equals("DONUT")) { //Debug.LogError("find Donut Effect"); } //部分模型是要绕X旋转270的,这样他的缩放,和移动,都只能靠自己 if (effect.EffectType.Equals("PLANE")) { meshIndex = 0; } else if (effect.EffectType.Equals("BOX")) { meshIndex = 1; } else if (effect.EffectType.Equals("DONUT")) { transform.localScale = effect.frames[0].scale; meshIndex = 2; } else if (effect.EffectType.Equals("MODEL"))//自行加载模型 { transform.localScale = effect.frames[0].scale; transform.rotation = RotateFollow.rotation * effect.frames[0].quat; transform.position = PositionFollow.position + effect.frames[0].pos; if (!string.IsNullOrEmpty(effect.Tails[0])) { string[] des = effect.Tails[0].Split(new char[] { '\\' }, System.StringSplitOptions.RemoveEmptyEntries); if (des.Length != 0) { WsGlobal.ShowMeteorObject(des[des.Length - 1], transform); } } //这个时候,不要用自带的meshfilter了,让他自己处理显示问题,只要告诉他在哪个地方显示 meshIndex = 100; } else if (effect.EffectType.Equals("SPHERE")) { meshIndex = 3; } else if (effect.EffectType.Equals("PARTICLE")) { if (!string.IsNullOrEmpty(effect.Tails[0])) { PositionFollow = FindFollowed(effect.Tails[0]); } if (!string.IsNullOrEmpty(effect.Tails[1])) { RotateFollow = FindFollowed(effect.Tails[1]); } if (PositionFollow != null) { transform.position = PositionFollow.transform.position; } meshIndex = 101; } else if (effect.EffectType.Equals("CYLINDER")) { meshIndex = 4; } else if (effect.EffectType.Equals("BILLBOARD")) { LookAtC = true; meshIndex = 5; } else if (effect.EffectType.Equals("DRAG")) { meshIndex = 6; } //决定模型 if (meshIndex != -1 && meshIndex < GamePool.Instance.MeshMng.Meshes.Length) { if (meshIndex == 4) { mFilter.mesh = Main.Ins.SfxMeshGenerator.CreateCylinder(source.origAtt.y, source.origAtt.x, source.origScale.x); } else if (meshIndex == 3) { mFilter.mesh = Main.Ins.SfxMeshGenerator.CreateSphere(source.SphereRadius); } else if (meshIndex == 0) { mFilter.mesh = Main.Ins.SfxMeshGenerator.CreatePlane(source.origScale.x, source.origScale.y); } else { mFilter.mesh = GamePool.Instance.MeshMng.Meshes[meshIndex]; } } if (effect.Texture.ToLower().EndsWith(".bmp") || effect.Texture.ToLower().EndsWith(".jpg") || effect.Texture.ToLower().EndsWith(".tga")) { texture = effect.Texture.Substring(0, effect.Texture.Length - 4); tex = Resources.Load <Texture>(texture); } else if (effect.Texture.ToLower().EndsWith(".ifl")) { iflTexture = gameObject.AddComponent <IFLLoader>(); iflTexture.IFLFile = Resources.Load <TextAsset>(effect.Texture); if (effect.EffectType.Equals("PARTICLE")) { iflTexture.SetTargetMeshRenderer(particle.GetComponent <ParticleSystemRenderer>()); } iflTexture.LoadIFL();//传递false表示由特效控制每一帧的切换时间. tex = iflTexture.GetTexture(0); } //else // print("effect contains other prefix:" + effect.Texture == null ? " texture is null" : effect.Texture); if (tex != null) { if (effect.EffectType.Equals("PARTICLE")) { ParticleSystemRenderer render = particle.GetComponent <ParticleSystemRenderer>(); if (effect.BlendType == 0) { render.material.shader = Shader.Find("Unlit/Texture");//普通不透明无光照 } else if (effect.BlendType == 1) { render.material.shader = Shader.Find("UnlitAdditive");//滤色 加亮 不透明 } else if (effect.BlendType == 2) { render.material.shader = Shader.Find("UnlitAdditive");//反色+透明度 } else if (effect.BlendType == 3) { render.material.shader = Shader.Find("Mobile/Particles/Alpha Blended");//不滤色,支持透明 } else if (effect.BlendType == 4) { render.material.shader = Shader.Find("Custom/MeteorBlend4");//滤色,透明 } else { render.material.shader = Shader.Find("Unlit/Texture");//普通不透明无光照 } if (texture.Equals("AItem09")) { render.enabled = false; particle.Stop(); /* 应该是有一个地裂的粒子特效,但是这个特效参数没分析出来. * tex = Resources.Load<Texture>("AItemParticle"); * render.material.SetTexture("_MainTex", tex); */ } else { render.material.SetTexture("_MainTex", tex); } render.material.SetColor("_Color", effect.frames[0].colorRGB); render.material.SetColor("_TintColor", effect.frames[0].colorRGB); render.material.SetFloat("_Intensity", effect.frames[0].TailFlags[9]); if (Main.Ins.GameStateMgr.gameStatus != null && !Main.Ins.GameStateMgr.gameStatus.DisableParticle) { particle.Play(); } } else { if (effect.BlendType == 0) { mRender.material.shader = Shader.Find("Unlit/Texture");//普通不透明无光照 } else if (effect.BlendType == 1) { mRender.material.shader = Shader.Find("UnlitAdditive");//滤色 加亮 不透明 } else if (effect.BlendType == 2) { mRender.material.shader = Shader.Find("UnlitAdditive");//反色+透明度 } else if (effect.BlendType == 3) { mRender.material.shader = Shader.Find("Mobile/Particles/Alpha Blended");//不滤色,支持透明 } else if (effect.BlendType == 4) { mRender.material.shader = Shader.Find("Custom/MeteorBlend4");//滤色,透明 } else { mRender.material.shader = Shader.Find("Unlit/Texture");//普通不透明无光照 } if (effect.BlendType == 2) { mRender.material.SetColor("_InvColor", effect.frames[0].colorRGB); } else { mRender.material.SetColor("_Color", effect.frames[0].colorRGB); mRender.material.SetColor("_TintColor", effect.frames[0].colorRGB); } mRender.material.SetFloat("_Intensity", effect.frames[0].TailFlags[9]); mRender.material.SetTexture("_MainTex", tex); if (effect.uSpeed != 0.0f || effect.vSpeed != 0.0f) { tex.wrapMode = TextureWrapMode.Repeat; } else { tex.wrapMode = TextureWrapMode.Clamp; } mRender.material.SetFloat("_u", effect.uSpeed); mRender.material.SetFloat("_v", effect.vSpeed); } } else { mRender.enabled = false; } //drag不知道有什么作用,可能只是定位用的挂载点 if (effect.Hidden == 1 || meshIndex == 6) { if (particle != null) { ParticleSystemRenderer render = particle.GetComponent <ParticleSystemRenderer>(); if (render != null) { render.enabled = false; } } mRender.enabled = false; } if (effect.EffectName.StartsWith("Attack")) { if (effect.EffectType.ToUpper() == "BOX") { BoxCollider bo = gameObject.AddComponent <BoxCollider>(); bo.center = Vector3.zero; bo.size = Vector3.one; damageBox = bo; } else { //SphereCollider sph = gameObject.AddComponent<SphereCollider>(); //damageBox = sph; //sph.radius = 1.0f; //sph.center = Vector3.zero; MeshCollider co = gameObject.AddComponent <MeshCollider>(); co.convex = true; co.isTrigger = true; damageBox = co; } damageBox.enabled = false; } if (preLoad) { PlayDone = true; if (parentSfx != null) { parentSfx.OnPlayDone(this); } else { Destroy(gameObject); } return; } }
IEnumerator PlayEffectFrame() { while (playedIndex < source.frames.Count) { //某帧锁定 if (pause) { yield return(0); continue; } if (playedTime < source.frames[0].startTime && mRender.enabled) { mRender.enabled = false; } else if (playedTime >= source.frames[0].startTime && !mRender.enabled && source.Hidden == 0) { mRender.enabled = true; } while (playedTime < source.frames[0].startTime) { yield return(0); } float timeRatio2 = (playedTime - source.frames[playedIndex - 1].startTime) / (source.frames[playedIndex].startTime - source.frames[playedIndex - 1].startTime); string vertexColor = "_TintColor"; if (source.BlendType == 2) { vertexColor = "_InvColor"; } if (source.EffectType == "BOX") { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = new Vector3(source.origScale.x * source.frames[playedIndex - 1].scale.x, source.origScale.y * source.frames[playedIndex - 1].scale.y, source.origScale.z * source.frames[playedIndex - 1].scale.z); } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Lerp(new Vector3(source.origScale.x * source.frames[playedIndex - 1].scale.x, source.origScale.y * source.frames[playedIndex - 1].scale.y, source.origScale.z * source.frames[playedIndex - 1].scale.z), new Vector3(source.origScale.x * source.frames[playedIndex].scale.x, source.origScale.y * source.frames[playedIndex].scale.y, source.origScale.z * source.frames[playedIndex].scale.z), timeRatio2); } } else if (source.EffectType == "CYLINDER") { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } //if (source.frames[playedIndex].startTime <= playedTime) //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * source.frames[playedIndex].quat; // else // transform.rotation = source.frames[playedIndex].quat; // if (PositionFollow != null) // transform.position = PositionFollow.position + source.frames[playedIndex].pos; // else // transform.position = source.frames[playedIndex].pos; // transform.localScale = source.frames[playedIndex].scale; // mRender.material.SetFloat("_Intensity", source.frames[playedIndex].TailFlags[9]); // mRender.material.SetColor(vertexColor, source.frames[playedIndex].colorRGB); // playedIndex++; //} //else //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * Quaternion.Slerp(source.frames[playedIndex - 1].quat, source.frames[playedIndex].quat, timeRatio2); // else // transform.rotation = Quaternion.Slerp(source.frames[playedIndex - 1].quat, source.frames[playedIndex].quat, timeRatio2); // if (PositionFollow != null) // transform.position = PositionFollow.position + Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // else // transform.position = Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); // mRender.material.SetFloat("_Intensity", Mathf.Lerp(source.frames[playedIndex - 1].TailFlags[9], source.frames[playedIndex].TailFlags[9], timeRatio2)); // mRender.material.SetColor(vertexColor, Color.Lerp(source.frames[playedIndex - 1].colorRGB, source.frames[playedIndex].colorRGB, timeRatio2)); //} } else if (source.EffectType == "PLANE") { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } //if (source.frames[playedIndex].startTime <= playedTime) //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * source.frames[playedIndex].quat; // else // transform.rotation = source.frames[playedIndex].quat; // if (PositionFollow != null) // transform.position = PositionFollow.position + source.frames[playedIndex].pos; // else // transform.position = source.frames[playedIndex].pos; // transform.localScale = new Vector3(source.origScale.x * source.frames[playedIndex].scale.x, source.origScale.y * source.frames[playedIndex].scale.y, source.origScale.z * source.frames[playedIndex].scale.z); // mRender.material.SetColor(vertexColor, source.frames[playedIndex].colorRGB); // mRender.material.SetFloat("_Intensity", source.frames[playedIndex].TailFlags[9]); // playedIndex++; //} //else //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * Quaternion.Slerp(source.frames[playedIndex - 1].quat, source.frames[playedIndex].quat, timeRatio2); // else // transform.rotation = Quaternion.Slerp(source.frames[playedIndex - 1].quat, source.frames[playedIndex].quat, timeRatio2); // if (PositionFollow != null) // transform.localPosition = PositionFollow.position + Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // else // transform.position = Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // transform.localScale = Vector3.Lerp(new Vector3(source.origScale.x * source.frames[playedIndex - 1].scale.x, source.origScale.y * source.frames[playedIndex - 1].scale.y, source.origScale.z * source.frames[playedIndex - 1].scale.z), new Vector3(source.origScale.x * source.frames[playedIndex].scale.x, source.origScale.y * source.frames[playedIndex].scale.y, source.origScale.z * source.frames[playedIndex].scale.z), timeRatio2); // mRender.material.SetFloat("_Intensity", Mathf.Lerp(source.frames[playedIndex - 1].TailFlags[9], source.frames[playedIndex].TailFlags[9], timeRatio2)); // mRender.material.SetColor(vertexColor, Color.Lerp(source.frames[playedIndex - 1].colorRGB, source.frames[playedIndex].colorRGB, timeRatio2)); //} } else if (source.EffectType == "SPHERE") { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Slerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } //if (source.frames[playedIndex].startTime <= playedTime) //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * source.frames[playedIndex].quat; // else // transform.rotation = source.frames[playedIndex].quat; // if (source.localSpace == 1) // { // if (RotateFollow != null) // { // Vector3 targetPos = RotateFollow.TransformPoint(source.frames[playedIndex].pos) - RotateFollow.position; // if (PositionFollow != null) // transform.position = PositionFollow.position + targetPos; // else // transform.position = targetPos; // } // } // else // { // if (PositionFollow != null) // transform.position = PositionFollow.position + source.frames[playedIndex].pos; // else // transform.position = source.frames[playedIndex].pos; // } // //if (PositionFollow != null) // // transform.position = PositionFollow.position + source.frames[playedIndex].pos; // //else // // transform.position = source.frames[playedIndex].pos; // transform.localScale = source.frames[playedIndex].scale; // mRender.material.SetFloat("_Intensity", source.frames[playedIndex].TailFlags[9]); // mRender.material.SetColor(vertexColor, source.frames[playedIndex].colorRGB); // playedIndex++; //} //else //{ // //旋转用球面插值 // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * Quaternion.Slerp(source.frames[playedIndex - 1].quat, source.frames[playedIndex].quat, timeRatio2); // else // transform.rotation = Quaternion.Slerp(source.frames[playedIndex - 1].quat, source.frames[playedIndex].quat, timeRatio2); // if (source.localSpace == 1) // { // if (RotateFollow != null) // { // Vector3 targetPos = RotateFollow.TransformPoint(Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2)) - RotateFollow.position; // if (PositionFollow != null) // transform.position = PositionFollow.position + targetPos; // else // transform.position = targetPos; // } // } // else // { // if (PositionFollow != null) // transform.position = PositionFollow.position + Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // else // transform.position = Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // } // ////移动用直线插值, // //if (PositionFollow != null) // // transform.position = PositionFollow.position + Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // //else // // transform.localPosition = Vector3.Lerp(source.frames[playedIndex - 1].pos , source.frames[playedIndex].pos, timeRatio2); // transform.localScale = Vector3.Slerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); // mRender.material.SetFloat("_Intensity", Mathf.Lerp(source.frames[playedIndex - 1].TailFlags[9], source.frames[playedIndex].TailFlags[9], timeRatio2)); // mRender.material.SetColor(vertexColor, Color.Lerp(source.frames[playedIndex - 1].colorRGB, source.frames[playedIndex].colorRGB, timeRatio2)); //} } else if (source.EffectType == "BILLBOARD") { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.LookAt(Camera.main.transform); transform.localScale = new Vector3(source.origScale.x * source.frames[playedIndex - 1].scale.x, source.origScale.y * source.frames[playedIndex - 1].scale.y, source.origScale.z * source.frames[playedIndex - 1].scale.z); } else { OnLastFrame(timeRatio2, vertexColor); transform.LookAt(Camera.main.transform); transform.localScale = Vector3.Lerp(new Vector3(source.origScale.x * source.frames[playedIndex - 1].scale.x, source.origScale.y * source.frames[playedIndex - 1].scale.y, source.origScale.z * source.frames[playedIndex - 1].scale.z), new Vector3(source.origScale.x * source.frames[playedIndex].scale.x, source.origScale.y * source.frames[playedIndex].scale.y, source.origScale.z * source.frames[playedIndex].scale.z), timeRatio2); } //if (source.frames[playedIndex].startTime <= playedTime) //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * source.frames[playedIndex].quat; // else // transform.rotation = source.frames[playedIndex].quat; // if (source.localSpace == 1) // { // if (RotateFollow != null) // { // Vector3 targetPos = RotateFollow.TransformPoint(source.frames[playedIndex].pos) - RotateFollow.position; // if (PositionFollow != null) // transform.position = PositionFollow.position + targetPos; // else // transform.position = targetPos; // } // else // Debug.LogError("缺少惯性坐标系骨骼"); // } // else // { // if (PositionFollow != null) // transform.position = PositionFollow.position + source.frames[playedIndex].pos; // else // transform.position = source.frames[playedIndex].pos; // } // transform.localScale = new Vector3(source.origScale.x * source.frames[playedIndex].scale.x, source.origScale.y * source.frames[playedIndex].scale.y, source.origScale.z * source.frames[playedIndex].scale.z); // //transform.LookAt(Camera.main.transform); // mRender.material.SetFloat("_Intensity", source.frames[playedIndex].TailFlags[9]); // mRender.material.SetColor(vertexColor, new Color(source.frames[playedIndex].colorRGB.r, source.frames[playedIndex].colorRGB.g, source.frames[playedIndex].colorRGB.b, source.frames[playedIndex].colorRGB.a)); // playedIndex++; // //playedTime = 0.0f; //} //else //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * source.frames[playedIndex].quat; // else // transform.rotation = source.frames[playedIndex].quat; // if (source.localSpace == 1) // { // if (PositionFollow != null) // { // Vector3 targetPos = RotateFollow.TransformPoint(Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2)) - RotateFollow.position; // if (PositionFollow != null) // transform.position = PositionFollow.position + targetPos; // else // transform.position = targetPos; // } // else // Debug.LogError("缺少惯性坐标骨骼"); // } // else // { // if (PositionFollow != null) // transform.position = PositionFollow.position + Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // else // transform.position = Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // } // transform.localScale = Vector3.Lerp(new Vector3(source.origScale.x * source.frames[playedIndex - 1].scale.x, source.origScale.y * source.frames[playedIndex - 1].scale.y, source.origScale.z * source.frames[playedIndex - 1].scale.z), new Vector3(source.origScale.x * source.frames[playedIndex].scale.x, source.origScale.y * source.frames[playedIndex].scale.y, source.origScale.z * source.frames[playedIndex].scale.z), timeRatio2); // //transform.LookAt(Camera.main.transform); // mRender.material.SetFloat("_Intensity", Mathf.Lerp(source.frames[playedIndex - 1].TailFlags[9], source.frames[playedIndex].TailFlags[9], timeRatio2)); // mRender.material.SetColor(vertexColor, Color.Lerp(new Color(source.frames[playedIndex - 1].colorRGB.r, source.frames[playedIndex - 1].colorRGB.g, source.frames[playedIndex - 1].colorRGB.b, source.frames[playedIndex - 1].colorRGB.a), new Color(source.frames[playedIndex].colorRGB.r, source.frames[playedIndex].colorRGB.g, source.frames[playedIndex].colorRGB.b, source.frames[playedIndex].colorRGB.a), timeRatio2)); //} } else if (source.EffectType == "MODEL") { //第一帧开始时间为-1.表示无限时播放 if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Slerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } } else if (source.EffectType == "PARTICLE") { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); //transform.localScale = source.frames[playedIndex - 1].scale; ParticleSystemRenderer render = particle.GetComponent <ParticleSystemRenderer>(); render.material.SetColor("_Color", source.frames[playedIndex - 1].colorRGB); render.material.SetColor(vertexColor, source.frames[playedIndex - 1].colorRGB); //粒子不要设置强度了,原版本的粒子实现和UNITY的不一样render.material.SetFloat("_Intensity", source.frames[playedIndex].TailFlags[9]); particle.Emit(1); //particle.Simulate(); playedIndex++; //playedTime = 0.0f; } else { OnLastFrame(timeRatio2, vertexColor); //transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); //ParticleSystemRenderer render = particle.GetComponent<ParticleSystemRenderer>(); //render.material.SetColor("_Color", new Color(source.frames[playedIndex].colorRGB.r, source.frames[playedIndex].colorRGB.g, source.frames[playedIndex].colorRGB.b, source.frames[playedIndex].colorRGB.a)); //render.material.SetColor(vertexColor, new Color(source.frames[playedIndex].colorRGB.r, source.frames[playedIndex].colorRGB.g, source.frames[playedIndex].colorRGB.b, source.frames[playedIndex].colorRGB.a)); //particle.Emit(1); //render.material.SetFloat("_Intensity", source.frames[playedIndex].TailFlags[9]); } } else if (source.EffectType == "DONUT") { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } //if (source.frames[playedIndex].startTime <= playedTime) //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * source.frames[playedIndex].quat; // else // transform.rotation = source.frames[playedIndex].quat; // transform.localPosition = source.frames[playedIndex].pos; // transform.localScale = source.frames[playedIndex].scale; // mRender.material.SetFloat("_Intensity", source.frames[playedIndex].TailFlags[9]); // mRender.material.SetColor(vertexColor, source.frames[playedIndex].colorRGB); // playedIndex++; // //playedTime = 0.0f; //} //else //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * source.frames[playedIndex].quat; // else // transform.rotation = Quaternion.Slerp(source.frames[playedIndex - 1].quat, source.frames[playedIndex].quat, timeRatio2); // transform.localPosition = Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); // mRender.material.SetFloat("_Intensity", Mathf.Lerp(source.frames[playedIndex - 1].TailFlags[9], source.frames[playedIndex].TailFlags[9], timeRatio2)); // mRender.material.SetColor(vertexColor, Color.Lerp(source.frames[playedIndex - 1].colorRGB, source.frames[playedIndex].colorRGB, timeRatio2)); //} } else if (source.EffectType == "DRAG") { if (source.frames[playedIndex].startTime <= playedTime) { OnNewFrame(vertexColor); transform.localScale = source.frames[playedIndex - 1].scale; } else { OnLastFrame(timeRatio2, vertexColor); transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); } //if (source.frames[playedIndex].startTime <= playedTime) //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * source.frames[playedIndex].quat; // else // transform.rotation = source.frames[playedIndex].quat; // transform.localPosition = source.frames[playedIndex].pos; // transform.localScale = source.frames[playedIndex].scale; // mRender.material.SetFloat("_Intensity", source.frames[playedIndex].TailFlags[9]); // mRender.material.SetColor(vertexColor, source.frames[playedIndex].colorRGB); // playedIndex++; // //playedTime = 0.0f; //} //else //{ // if (RotateFollow != null) // transform.rotation = RotateFollow.rotation * source.frames[playedIndex].quat; // else // RotateFollow.transform.rotation = Quaternion.Slerp(source.frames[playedIndex - 1].quat, source.frames[playedIndex].quat, timeRatio2); // transform.localPosition = Vector3.Lerp(source.frames[playedIndex - 1].pos, source.frames[playedIndex].pos, timeRatio2); // transform.localScale = Vector3.Lerp(source.frames[playedIndex - 1].scale, source.frames[playedIndex].scale, timeRatio2); // mRender.material.SetFloat("_Intensity", Mathf.Lerp(source.frames[playedIndex - 1].TailFlags[9], source.frames[playedIndex].TailFlags[9], timeRatio2)); // mRender.material.SetColor(vertexColor, Color.Lerp(source.frames[playedIndex - 1].colorRGB, source.frames[playedIndex].colorRGB, timeRatio2)); //} } yield return(0); } //?是循环还是删除 //playedIndex = 0; //yield return 0; PlayDone = true; if (parentSfx != null) { parentSfx.OnPlayDone(this); } else { Destroy(gameObject); } yield break; }