//远程攻击-激发飞行特效 void RemoteAttack(AnimationEvent animEvent) { GameObject actorObj = gameObject.transform.parent.gameObject; ActorProp actorProp = actorObj.GetComponent <ActorProp>(); if (actorProp == null) { return; } Actor actor = actorProp.ActorLogicObj; AttackAction action = actor.ActionControl.LookupAction(ActorAction.ENType.enAttackAction) as AttackAction; if (null == action) { Debug.LogWarning("Remote Attack is error, attack action is null"); return; } ++action.m_skillResultIDIndex; if (null == action.m_skillInfo) {//技能为空 Debug.LogWarning("remote attack,skill info is null,skillID:" + action.m_skillID); return; } int skillID = action.m_skillID; //飞行道具的id和SkillResultID是一样的 FlyingItemInfo itemInfo = GameTable.FlyingItemTableAsset.LookUp(action.SkillResultID); if (itemInfo == null) { Debug.LogWarning("flying item info is null, id is " + action.SkillResultID.ToString()); return; } Vector3 targetPos = Vector3.zero; Actor skillTarget = action.m_skillTarget; if (skillTarget != null) { if (skillTarget.Type == ActorType.enMain && skillTarget.IsActorExit) { skillTarget = ActorManager.Singleton.MainActor; action.m_skillTargetID = skillTarget.ID; } targetPos = skillTarget.RealPos; } if (skillTarget != null) { actor.Forward(skillTarget.RealPos); } RemoteAttackManager.Info info = new RemoteAttackManager.Info(itemInfo); info.m_srcActor = actor; info.m_dstActor = skillTarget; info.m_targetPos = targetPos; info.m_skillID = skillID; RemoteAttackManager.Singleton.Add(info); if (animEvent.intParameter != 0) {//隐藏武器 actor.ShowWeaponModelWithTable(false); } }
public void Init(RemoteAttackManager.Info info) { GetComponent <Rigidbody>().WakeUp(); m_targetIDList.Clear(); m_info = info; if (!string.IsNullOrEmpty(m_info.m_itemInfo.Item_BoneOffset)) { string[] param = m_info.m_itemInfo.Item_BoneOffset.Split(new char[1] { ',' }); m_offset = new Vector3(float.Parse(param[0]), float.Parse(param[1]), float.Parse(param[2])); } }
//远程攻击-多个目标 void RemoteAttackMultiTarget(AnimationEvent animEvent) { GameObject actorObj = gameObject.transform.parent.gameObject; ActorProp actorProp = actorObj.GetComponent <ActorProp>(); if (actorProp == null) { return; } m_self = actorProp.ActorLogicObj; AttackAction action = m_self.ActionControl.LookupAction(ActorAction.ENType.enAttackAction) as AttackAction; if (null == action) { Debug.LogWarning("RemoteAttackMultiTarget is error, attack action is null"); return; } ++action.m_skillResultIDIndex; int skillID = action.m_skillID; //animEvent.intParameter;//目标个数 //animEvent.floatParameter;//范围 m_multiTargetNumber = animEvent.intParameter; m_multiTargetRange = animEvent.floatParameter; if (m_multiTargetNumber == 0) {//不填写,只指定技能目标 m_multiTargetNumber = 1; } //find target m_multiTargetList = new List <Actor>(m_multiTargetNumber); if (action.m_skillTarget != null) { m_self.Forward(action.m_skillTarget.RealPos); m_multiTargetList.Add(action.m_skillTarget); } if (m_multiTargetList.Count < m_multiTargetNumber) { ActorManager.Singleton.ForEach(CheckTarget); //while (m_multiTargetList.Count < m_multiTargetNumber) //{//目标数量不足,用技能目标填满 // if (action.m_skillTarget == null) // { // break; // } // m_multiTargetList.Add(action.m_skillTarget); //} } //飞行道具的id和SkillResultID是一样的 FlyingItemInfo itemInfo = GameTable.FlyingItemTableAsset.LookUp(action.SkillResultID); if (itemInfo == null) { Debug.LogWarning("flying item info is null, id is " + action.SkillResultID.ToString()); return; } for (int i = 0; i < m_multiTargetList.Count; ++i) { Vector3 targetPos = Vector3.zero; Actor skillTarget = m_multiTargetList[i]; if (skillTarget.Type == ActorType.enMain && skillTarget.IsActorExit) { skillTarget = ActorManager.Singleton.MainActor; action.m_skillTargetID = skillTarget.ID; } targetPos = skillTarget.RealPos; RemoteAttackManager.Info info = new RemoteAttackManager.Info(itemInfo); info.m_srcActor = m_self; info.m_dstActor = skillTarget; info.m_targetPos = targetPos; info.m_skillID = skillID; RemoteAttackManager.Singleton.Add(info); } if (string.IsNullOrEmpty(animEvent.stringParameter)) {//隐藏武器 m_self.ShowWeaponModelWithTable(false); } }
IEnumerator Coroutine_Add(RemoteAttackManager.Info info) { //飞行道具 if (string.IsNullOrEmpty(info.m_itemInfo.Item_Name)) { Debug.LogWarning("effect name is null"); } else { GameResPackage.AsyncLoadObjectData data = new GameResPackage.AsyncLoadObjectData(); IEnumerator e = PoolManager.Singleton.Coroutine_Load(GameData.GetEffectPath(info.m_itemInfo.Item_Name), data, true); while (true) { e.MoveNext(); if (data.m_isFinish) { break; } yield return(e.Current); } if (data.m_obj == null) { Debug.LogWarning("load effect obj fail, effect name is " + info.m_itemInfo.Item_Name); } else { info.m_itemObj = data.m_obj as GameObject; //获得脚本 FlyingItemCallback callback = info.m_itemObj.GetComponent <FlyingItemCallback>(); if (callback == null) { //从子中获得脚本 callback = info.m_itemObj.GetComponentInChildren <FlyingItemCallback>(); if (callback == null) {//未获得脚本,添加脚本在collider上 //获得collider Collider c = info.m_itemObj.GetComponent <Collider>(); if (c == null) { //从子中获得collider c = info.m_itemObj.GetComponentInChildren <Collider>(); } if (c != null) { callback = c.transform.gameObject.AddComponent <FlyingItemCallback>(); } else { if (!info.m_itemInfo.IsStretch) {//拉伸道具不使用collider Debug.LogWarning("fly obj is not exist collider, fly obj id = " + info.m_itemInfo.ID); } } } } if (callback != null) { callback.Init(info); } //获得Rigidbody Rigidbody rBody = info.m_itemObj.GetComponent <Rigidbody>(); if (rBody == null) { rBody = info.m_itemObj.GetComponentInChildren <Rigidbody>(); } info.m_rigidbody = rBody; if (!string.IsNullOrEmpty(info.m_itemInfo.Item_BoneName)) {//起始bone info.m_boneT = info.m_srcActor.LookupBone(info.m_srcActor.MainObj.transform, info.m_itemInfo.Item_BoneName); if (info.m_boneT == null) {//没有bone,则出生在CenterCollider if (info.m_srcActor.CenterCollider != null) { info.m_boneT = info.m_srcActor.CenterCollider.transform; } info.m_itemObj.transform.position = info.m_srcActor.RealPos; Debug.LogWarning("lookup bone fail, bone name is " + info.m_itemInfo.Item_BoneName); } else { info.m_itemObj.transform.position = info.m_boneT.position; } } else { if (info.m_targetPos != Vector3.zero) {//没有起始bone,则出生在目标点 info.m_itemObj.transform.position = info.m_targetPos; } else {//没有目标点,则出生在CenterCollider info.m_itemObj.transform.position = info.m_srcActor.RealPos; } if (info.m_srcActor.CenterCollider != null) { info.m_boneT = info.m_srcActor.CenterCollider.transform; } } if (!string.IsNullOrEmpty(info.m_itemInfo.Item_BoneOffset)) { Vector3 pos = info.m_itemObj.transform.position; string[] param = info.m_itemInfo.Item_BoneOffset.Split(new char[1] { ',' }); Vector3 offset = new Vector3(float.Parse(param[0]), float.Parse(param[1]), float.Parse(param[2])); pos = pos + info.m_boneT.rotation * offset; info.m_itemObj.transform.position = pos; } if (info.m_srcPos != Vector3.zero) { info.m_itemObj.transform.position = info.m_srcPos; } if (info.m_itemInfo.Item_MoveSpeed == 0) { Vector3 currentForward = info.m_itemObj.transform.eulerAngles; currentForward.y = info.m_srcActor.MainObj.transform.eulerAngles.y; info.m_itemObj.transform.eulerAngles = currentForward; } info.m_startPos = info.m_itemObj.transform.position; info.m_actorType = info.m_srcActor.Type; if (info.m_actorType != info.m_srcActor.TempType) {//使用更改后的ActorType info.m_actorType = info.m_srcActor.TempType; } info.m_actorCamp = (ENCamp)info.m_srcActor.Camp; if (info.m_actorCamp != info.m_srcActor.TempCamp) { info.m_actorCamp = info.m_srcActor.TempCamp; } if (info.m_itemInfo.IsWarningBeforeItem) { info.m_isHaveWarningEffect = true; //方向 if (info.m_targetPos != Vector3.zero) {//有目标,起始点为道具出生点 if (info.m_itemInfo.Item_IsLockY) { info.m_targetPos.y = info.m_startPos.y; } Vector3 direction = info.m_targetPos - info.m_startPos; direction.Normalize(); info.m_forward = direction; } else {//无目标 info.m_forward = info.m_srcActor.MainObj.transform.forward; } {//预警特效 GameResPackage.AsyncLoadObjectData data2 = new GameResPackage.AsyncLoadObjectData(); e = PoolManager.Singleton.Coroutine_Load(GameData.GetEffectPath(info.m_itemInfo.WarningEffectName), data2, true); while (true) { e.MoveNext(); if (data2.m_isFinish) { break; } yield return(e.Current); } if (data2.m_obj != null) { info.m_objWarningEffect = data2.m_obj as GameObject; info.m_objWarningEffect.transform.localPosition = info.m_targetPos; } } //info.m_objWarningEffect = PoolManager.Singleton.CreateEffectObj(info.m_itemInfo.WarningEffectName); //info.m_objWarningEffect.transform.localPosition = info.m_targetPos; info.m_startTime = Time.time; info.m_itemObj.SetActive(false); } else { //方向 if (info.m_targetPos != Vector3.zero) {//有目标,起始点为collider if (info.m_itemInfo.Item_IsLockY) { info.m_targetPos.y = info.m_startPos.y; } Vector3 direction = info.m_targetPos - info.m_startPos; direction.Normalize(); info.m_forward = direction; } else {//无目标 info.m_forward = info.m_srcActor.MainObj.transform.forward; } } info.m_cameraIsBack = false; if (info.m_itemObj.activeSelf) {//没有预警特效,直接改变焦点 if (info.m_itemInfo.IsChangeCamera) { if (info.m_actorType == ActorType.enMain) { MainGame.Singleton.MainCamera.ChangeFollowTarget(info.m_itemObj, info.m_itemInfo.CC_ChangeTime, info.m_itemInfo.CC_BackTime, false); } } } if (info.m_itemInfo.IsCurveMove) {//曲线移动,设置曲线移动的方向 string[] array = info.m_itemInfo.Item_AddtionalDirection.Split(new char[1] { ',' }); int x = 0, y = 0, z = 0; if (array.Length > 0) { x = int.Parse(array[0]); } if (array.Length > 1) { y = int.Parse(array[1]); } if (array.Length > 2) { z = int.Parse(array[2]); } info.m_curveForward = info.m_forward - new Vector3(x, y, z); //Debug.LogError("old forward:"+info.m_forward.ToString()+",new forward:"+info.m_curveForward.ToString()); } info.m_itemObj.transform.localScale = Vector3.one; if (info.m_itemInfo.IsStretch) {//拉伸-z轴 float d = 0; if (info.m_dstActor != null) { d = ActorTargetManager.GetTargetDistance(info.m_srcActor.MainPos, info.m_dstActor.MainPos); } info.m_duration = d / info.m_itemInfo.ZAxisLongth / info.m_itemInfo.Item_StretchSpeed; //Debug.LogError("remote attack,d:" + d + ",z:" + info.m_itemInfo.ZAxisLongth + ",speed:" + info.m_itemInfo.Item_StretchSpeed); info.m_itemObj.transform.forward = info.m_forward; info.m_itemObj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); } info.m_itemObj.SetActive(false); m_infoList.Add(info); } } }
public void Add(RemoteAttackManager.Info info) { MainGame.Singleton.StartCoroutine(Coroutine_Add(info)); }
//private IEnumerator RemoveEffect2(GameObject obj, float duration) //{ // yield return new WaitForSeconds(duration); // { // if (null != obj) // { // PoolManager.Singleton.ReleaseObj(obj); // } // } //} //开始反弹 public void StartBouncy(Info info, Vector3 startPos) { if (!info.m_itemInfo.IsBouncy) {//没有反弹 return; } if (info.m_bouncyCount <= 0) {//没有反弹次数 return; } //查找目标 GetTargetList(startPos, info.m_actorType, info.m_actorCamp, ENTargetType.enEnemy, info.m_itemInfo.Item_BouncyDistance); if (info.m_bouncyTargetIDList == null) { info.m_bouncyTargetIDList = new List <int>(); if ((FlyingItemInfo.ENBouncyType)info.m_itemInfo.Item_BouncyType == FlyingItemInfo.ENBouncyType.enNotRepeat) { info.m_bouncyTargetIDList.Add(info.m_dstActor.ID); } } for (int i = 0; i < m_targetIDList.Count;) { int id = m_targetIDList[i]; if (info.m_dstActor != null && id == info.m_dstActor.ID) { m_targetIDList.RemoveAt(i); continue; } switch ((FlyingItemInfo.ENBouncyType)info.m_itemInfo.Item_BouncyType) { case FlyingItemInfo.ENBouncyType.enRandom: break; case FlyingItemInfo.ENBouncyType.enNotRepeat: { if (info.m_bouncyTargetIDList.Contains(id)) { //已经反弹过该目标 m_targetIDList.RemoveAt(i); continue; } } break; } ++i; } if (m_targetIDList.Count != 0) { int index = UnityEngine.Random.Range(0, m_targetIDList.Count); Actor target = ActorManager.Singleton.Lookup(m_targetIDList[index]); RemoteAttackManager.Info newInfo = new RemoteAttackManager.Info(info.m_itemInfo); newInfo.m_srcActor = info.m_srcActor; newInfo.m_dstActor = target; startPos.y = info.m_itemObj.transform.position.y; newInfo.m_srcPos = startPos; newInfo.m_targetPos = target.MainPos; newInfo.m_skillID = info.m_skillID; newInfo.m_bouncyCount = --info.m_bouncyCount; newInfo.m_bouncyTargetIDList = new List <int>(); newInfo.m_bouncyTargetIDList.AddRange(info.m_bouncyTargetIDList); if (!newInfo.m_bouncyTargetIDList.Contains(target.ID)) { newInfo.m_bouncyTargetIDList.Add(target.ID); } RemoteAttackManager.Singleton.Add(newInfo); } }