//播放动画,特效,声音 IEnumerator PlayActionEfxSound(SkillPlayParam param, float delayTime) { if (m_actor == null) { yield break; } m_strActionName = param.action; if (m_strActionName != null && m_strActionName.Length > 0) { //动作带位移 的 不能延迟播放, 延迟播放将影响 位移曲线计算 m_actor.PlayAction(m_strActionName, false); m_actor.SetActionTime(m_strActionName, param.startTime); m_actor.SetSkillActionSpeed(m_strActionName, param.speed, m_skillDesc); } //其它玩家不播放了 if (m_actor.mActorType == ActorType.AT_REMOTE_PLAYER) { yield break; } if (m_actor.mActorType == ActorType.AT_PET) { PetObj pet = m_actor as PetObj; if (null != pet && pet.m_MasterActor != CoreEntry.gActorMgr.MainPlayer) { yield break; } } //播放声音 string sound1 = param.sound; string sound2 = param.voice; if (sound1 != null && sound1.Length > 0) { m_actor.StopSound(); m_actor.PlaySound(sound1); } if (sound2 != null && sound2.Length > 0) { m_actor.StopSound2(); m_actor.PlaySound2(sound2); } LuaTable skill_action = CoreEntry.gSkillMgr.GetSkillActon(m_skillID); if (skill_action == null) { Debug.LogError("==skill_action == is null m_skillID = " + m_skillID); yield break; } Vector3 efxPos = m_actor.transform.position; bool isBind = skill_action.Get <bool>("isBind"); int bindType = skill_action.Get <int>("skillEfxPos"); if (!isBind) { if (bindType == 1) { ActorObj target = m_actor.GetSelTarget(); if (null != target) { efxPos = target.transform.position; } } } if (delayTime > 0.0001f) { yield return(new WaitForSeconds(delayTime)); } //if (ByteToString.toString(m_skillDesc.szAttackEfxPrefab).Length > 0) if (param.actionEfx != null && param.actionEfx.Length > 0) { if (/*m_skillDesc.skilltype == 0 && */ m_actor.mActorType == ActorType.AT_BOSS) { yield return(new WaitForSeconds(m_actor.NoramalAttackEffectDelayTime)); } if (skill_action != null) { param.actionEfx = skill_action.Get <string>("skilleffect"); //efxObj = Instantiate(CoreEntry.gResLoader.LoadResource(param.actionEfx)) as GameObject;//CoreEntry.gGameObjPoolMgr.InstantiateEffect(param.actionEfx); efxObj = CoreEntry.gGameObjPoolMgr.InstantiateEffect(param.actionEfx); if (efxObj == null) { LogMgr.LogError("找不到attackEfxPrefab:" + skill_action.Get <string>("skilleffect") + " " + m_skillDesc.Get <string>("name")); } } float maxEfxTime = 0; if (skill_action.Get <float>("skillEfxLength") > 0) { maxEfxTime = skill_action.Get <float>("skillEfxLength"); } //LogMgr.UnityLog("maxEfxTime=" + maxEfxTime + ", " + m_strActionName); //特效存在时间 if (maxEfxTime <= 0.001) { maxEfxTime = m_actor.GetActionLength(m_strActionName); if (maxEfxTime <= 0.001) { LogMgr.UnityError("技能 动作时间 没有配置 skillID:" + m_skillDesc.Get <int>("id")); } } bool isFollowMove = false; EfxAttachActionPool efx = efxObj.GetComponent <EfxAttachActionPool>(); if (efx == null) { efx = efxObj.AddComponent <EfxAttachActionPool>(); } if (efx != null) { efx.Init(m_actor.transform, maxEfxTime, isFollowMove); m_actionEfx = efx; if (isBind) { ActorObj bindActor = null; if (bindType == 0) { bindActor = m_actor; } else { bindActor = m_actor.GetSelTarget(); } Transform bindTran = null; if (null != bindActor) { string hangPoint = skill_action.Get <string>("hangPoint"); if (!string.IsNullOrEmpty(hangPoint)) { bindTran = bindActor.transform.FindChild(hangPoint); } if (null == bindTran) { bindTran = bindActor.transform; } } else { bindTran = m_actor.transform; } m_actionEfx.transform.parent = bindTran; m_actionEfx.transform.localPosition = Vector3.zero; m_actionEfx.transform.localScale = Vector3.one; m_actionEfx.transform.rotation = m_actor.transform.rotation; } else { if (bindType == 1) { m_actionEfx.transform.position = efxPos; } else { m_actionEfx.transform.position = m_actor.transform.position; } m_actionEfx.transform.localScale = Vector3.one; m_actionEfx.transform.rotation = m_actor.transform.rotation; } //设置有挂点的特效 Transform[] childTransform = efxObj.GetComponentsInChildren <Transform>(); //foreach (Transform childTrans in childTransform) for (int i = 0; i < childTransform.Length; ++i) { Transform childTrans = childTransform[i]; EfxSetAttachPoint setAttach = childTrans.gameObject.GetComponent <EfxSetAttachPoint>(); if (setAttach == null || setAttach.m_attachPointEnum == AttachPoint.E_None) { continue; } setAttach.Init(false); Transform parent = m_actor.GetChildTransform(setAttach.m_attachPointEnum.ToString()); if (parent != null) { childTrans.parent = parent; childTrans.localPosition = Vector3.zero; childTrans.localRotation = Quaternion.identity; childTrans.localScale = Vector3.one; m_attachEfxObjectlist.Add(childTrans.gameObject); } } //影子 ghostMesh[] ghostMesh = efx.GetComponentsInChildren <ghostMesh>(); if (ghostMesh.Length > 0) { SkinnedMeshRenderer MianSkinMesh = m_actor.m_skinnedMeshRenderer[0]; for (int i = 0; i < m_actor.m_skinnedMeshRenderer.Length; ++i) { if (m_actor.m_skinnedMeshRenderer[i].name.Contains("weapon")) { continue; } MianSkinMesh = m_actor.m_skinnedMeshRenderer[i]; } for (int i = 0; i < ghostMesh.Length; ++i) { ghostMesh[i].characterMesh[0] = MianSkinMesh; } } } } yield return(1); }
//释放技能 void CastSkill() { CancelInvoke("CastSkill"); CancelInvoke("AutoLookatTarget"); // 如果不是激活状态不往下运行 if (!gameObject.activeInHierarchy) { return; } //释放吟唱阶段的动作特效 SendEvent(SkillCellEventType.SE_DESTROY_ACTION_EFX, null); //销毁吟唱阶段数据 DestroyEfx(); //播放动作,特效,声音 SkillPlayParam param = new SkillPlayParam(); LuaTable skill_action = CoreEntry.gSkillMgr.GetSkillActon(m_skillID); if (skill_action == null) { Debug.LogError("skill_action is null...m_skillID = " + m_skillID); return; } if (skill_action != null) { param.action = skill_action.Get <string>("animation"); param.actionEfx = skill_action.Get <string>("skilleffect"); param.startTime = m_startPlayTimeSet; param.speed = m_speed; param.remainEfx = skill_action.Get <string>("remain"); } //播放声音 string sound1 = ""; string sound2 = ""; AudioCore.GenerateAudio(m_skillDesc.Get <int>("sound_id"), ref sound1); AudioCore.GenerateAudio(m_skillDesc.Get <int>("talk_sound_id"), ref sound2); param.sound = sound1; param.voice = sound2; StartCoroutine(PlayActionEfxSound(param, skill_action.Get <float>("skillEfxDelay"))); //技能元素 SkillClassDisplayDesc skillClass = m_gameDBMgr.GetSkillClassDisplayDesc(m_skillDesc.Get <int>("skillDisplayID")); if (skillClass == null) { Debug.LogError("===skillClass== is null==="); return; } bool isLocal = false; if (m_actor is PlayerObj || m_actor is PetObj) { isLocal = true; } for (int i = 0; i < skillClass.castStageDataList.Count; ++i) { if (null != m_actor && !isLocal) { if (skillClass.castStageDataList[i] is MovePosAttackDesc) { continue; } } GameObject cellObj = CoreEntry.gGameObjPoolMgr.InstantiateSkillCell(skillClass.castStageDataList[i].prefabPath); cellObj.transform.parent = transform; ISkillCell skillCell = cellObj.GetComponent <ISkillCell>(); skillCell.Init(skillClass.castStageDataList[i], this); skillCell.SetAoeState(m_bIsAoe); CheckSkillCell(skillCell); AddSkillCell(cellObj); } //技能结束时间 if (m_skillDesc.Get <int>("skill_end") > 0) { m_overTime = (m_skillDesc.Get <int>("skill_end") / 1000f - m_startPlayTimeSet) / m_speed; } else { m_overTime = (m_actor.GetActionLength(m_strActionName) - m_startPlayTimeSet) / m_speed; } //如果是不可打破机能,释放出后恢复动作 if (canBeBroke == false) { float time = (m_actor.GetActionLength(m_strActionName) - m_startPlayTimeSet) / m_speed; CancelInvoke("SkillAnimationIsOver"); Invoke("SkillAnimationIsOver", time); } LogMgr.UnityLog("overtime=" + m_overTime + ", skillid=" + m_skillID); //技能结束 Invoke("SkillEnd", m_overTime); }