IEnumerator WaitMoveBulletToTarget(BulletStruct es, GameObject bullet, GameObject target) { BulletTrace xBulletTrace = new BulletTrace(); xBulletTrace.target = target; xBulletTrace.bullet = bullet; xBulletTrace.Index = es.Index; xBulletTrace.gameID = this.gameObject.GetInstanceID(); xBulletTrace.movetype = es.moveType; mxBulletTraceInfo.Add(xBulletTrace); float fMinDis = 0.3f; Vector3 vTargetPos = target.transform.position; while (true) { if (target == null) { Vector3 _vec = vTargetPos - bullet.transform.position; float fDis = Vector3.Distance(vTargetPos, bullet.transform.position); float fMoveDis = es.Speed * Time.deltaTime; if (fMoveDis > fDis) { bullet.transform.position = vTargetPos; } else { bullet.transform.Translate(_vec.normalized * es.Speed * Time.deltaTime); } } else { vTargetPos = target.transform.position; float fDis = Vector3.Distance(vTargetPos, bullet.transform.position); if (fDis > fMinDis) { Vector3 _vec = vTargetPos - bullet.transform.position; float fMoveDis = es.Speed * Time.deltaTime; if (fMoveDis > fDis) { bullet.transform.position = vTargetPos; } else { bullet.transform.Translate(_vec.normalized * es.Speed * Time.deltaTime); } } } if (Vector3.Distance(bullet.transform.position, vTargetPos) < fMinDis) { if (target == null) { mxAnimationEvent.OnBulletTouchPositionEvent(bullet, vTargetPos, es.AnimationType, -1); } else { int arrayIndex = -1; for (int i = 0; i < mxBulletTraceInfo.Count; ++i) { if (mxBulletTraceInfo[i].bullet.GetInstanceID() == bullet.GetInstanceID()) { arrayIndex = i; break; } } mxAnimationEvent.OnBulletTouchTargetEvent(bullet, target, 0, mxBulletTraceInfo[arrayIndex].Index); mxBulletTraceInfo.RemoveAt(arrayIndex); } Destroy(bullet); if (es.TouchEffect) { GameObject _startEff = GameObject.Instantiate <GameObject>(es.TouchEffect, vTargetPos, Quaternion.identity); _startEff.SetActive(true); Destroy(_startEff, es.TouchEffLifeTime); } if (es.TouchAudio) { AudioClip _startEff = GameObject.Instantiate <AudioClip>(es.TouchAudio, vTargetPos, Quaternion.identity); AudioSource.PlayClipAtPoint(_startEff, transform.position); Destroy(_startEff, es.TouchEffLifeTime); } yield break; } yield return(new WaitForEndOfFrame()); } }
IEnumerator WaitPlayBullet(BulletStruct es, Vector3 v) { //如果特效没有启用则不进行播放 if (es.isEnabled) { yield return(new WaitForSeconds(es.DelayTime)); } else { yield break; } switch (es.moveType) { case BulletStruct.MoveType.TargetObject: { for (int i = 0; i < EnemyList.Count; ++i) { Transform firePoint = mBodyIdent.xFirePoint; if (!firePoint) { firePoint = this.transform; firePoint = mBodyIdent.xHeadPoint; if (!firePoint) { firePoint = this.transform; } PlayBulletToTarget(es, firePoint, EnemyList[i].transform); } else { if (firePoint.childCount > 0) { for (int j = 0; j < firePoint.childCount; ++j) { Transform child = firePoint.GetChild(j); PlayBulletToTarget(es, child, EnemyList[i].transform); } } else { PlayBulletToTarget(es, firePoint, EnemyList[i].transform); } } } } break; case BulletStruct.MoveType.Line: { Transform firePoint = mBodyIdent.xFirePoint; if (!firePoint) { firePoint = mBodyIdent.xHeadPoint; if (!firePoint) { firePoint = this.transform; } PlayBulletToLine(es, firePoint, v); } else { if (firePoint.childCount > 0) { for (int j = 0; j < firePoint.childCount; ++j) { Transform child = firePoint.GetChild(j); PlayBulletToLine(es, child, v); } } else { PlayBulletToLine(es, firePoint, v); } } } break; default: break; } }
IEnumerator WaitMoveBulletToLine(BulletStruct es, GameObject bullet, Vector3 v) { BulletTrace xBulletTrace = new BulletTrace(); xBulletTrace.target = null; xBulletTrace.bullet = bullet; xBulletTrace.Index = es.Index; xBulletTrace.gameID = this.gameObject.GetInstanceID(); xBulletTrace.movetype = es.moveType; mxBulletTraceInfo.Add(xBulletTrace); Vector3 vForward = this.gameObject.transform.forward; Vector3 vTargetPos = vForward * es.Distance + bullet.transform.position; if (v != Vector3.zero) { vTargetPos = v; } float fDis = Vector3.Distance(vTargetPos, bullet.transform.position); /* * Tweener t = bullet.transform.DOMove(vTargetPos, fDis / es.Speed); * t.SetEase(Ease.Linear); * t.OnComplete(delegate () * { * int arrayIndex = -1; * * for (int i = 0; i < mxBulletTraceInfo.Count; ++i) * { * if (mxBulletTraceInfo[i].bullet.GetInstanceID() == bullet.GetInstanceID()) * { * arrayIndex = i; * break; * } * } * * mxAnimationEvent.OnBulletTouchPositionEvent(this.gameObject, vTargetPos, es.AnimationType, mxBulletTraceInfo[arrayIndex].Index); * * mxBulletTraceInfo.RemoveAt(arrayIndex); * * * Destroy(bullet); * * if (es.TouchEffect) * { * GameObject _startEff = GameObject.Instantiate<GameObject>(es.TouchEffect, vTargetPos, Quaternion.identity); * _startEff.SetActive(true); * Destroy(_startEff, es.TouchEffLifeTime); * } * if (es.TouchAudio) * { * AudioClip _startEff = GameObject.Instantiate<AudioClip>(es.TouchAudio, vTargetPos, Quaternion.identity); * AudioSource.PlayClipAtPoint(_startEff, transform.position); * Destroy(_startEff, es.TouchEffLifeTime); * } * }); */ yield return(new WaitForEndOfFrame()); /* * while (true) * { * float fDis = Vector3.Distance (vTargetPos, go.transform.position); * if (fDis > fMinDis) * { * Vector3 _vec = vTargetPos - go.transform.position; * float fMoveDis = es.Speed * Time.deltaTime; * if (fMoveDis > fDis) * { * go.transform.position = vTargetPos; * } * else * { * go.transform.Translate (_vec.normalized * es.Speed * Time.deltaTime); * } * } * * if (fDis < fMinDis) * { * Destroy (go); * * if (es.TouchEffect) * { * GameObject _startEff = Instantiate (es.TouchEffect, vTargetPos, Quaternion.identity) as GameObject; * _startEff.SetActive (true); * Destroy (_startEff, es.TouchEffLifeTime); * } * if (es.TouchAudio) * { * AudioClip _startEff = Instantiate (es.TouchAudio, vTargetPos, Quaternion.identity) as AudioClip; * AudioSource.PlayClipAtPoint(_startEff, transform.position); * Destroy (_startEff, es.TouchEffLifeTime); * } * yield break; * } * * yield return new WaitForEndOfFrame (); * } */ }