//static int TestCount = 0; void SpawnAmmoParticleObj(XKNpcHealthCtrl healthScript = null) { if (AmmoType != PlayerAmmoType.ChuanTouAmmo) { //不是穿甲弹. if (IsCreatAmmoParticle == true) { //已经创建过爆炸粒子. return; } IsCreatAmmoParticle = true; } //if (AmmoType == PlayerAmmoType.DaoDanAmmo) //{ // TestCount++; // SSDebug.LogWarning("SpawnAmmoParticleObj -> healthScript ============= " + healthScript // + ", TestCount == " + TestCount // + ", time == " + Time.time.ToString("f3")); //} //if (TestCount >= 100) //{ // TestCount = 0; //} #if USE_SPHERE_HIT GameObject objParticle = null; GameObject hitObj = CheckPlayerAmmoOverlapSphereHit(1); if (hitObj == null) { switch (AmmoType) { case PlayerAmmoType.PuTongAmmo: break; default: objParticle = AmmoExplode; break; } } else { string tagHitObj = hitObj.tag; switch (AmmoType) { case PlayerAmmoType.PuTongAmmo: XKAmmoParticleCtrl ammoParticleScript = hitObj.GetComponent <XKAmmoParticleCtrl>(); if (ammoParticleScript != null && ammoParticleScript.PuTongAmmoLZ != null) { objParticle = ammoParticleScript.PuTongAmmoLZ; } else { switch (tagHitObj) { case "metal": objParticle = MetalParticle; break; case "concrete": objParticle = ConcreteParticle; break; case "dirt": objParticle = DirtParticle; break; case "wood": objParticle = WoodParticle; break; case "water": objParticle = WaterParticle; break; case "sand": objParticle = SandParticle; break; case "glass": objParticle = GlassParticle; break; default: objParticle = AmmoExplode; break; } } break; default: switch (tagHitObj) { case "dirt": objParticle = DirtParticle; break; case "water": objParticle = WaterParticle; break; default: objParticle = AmmoExplode; break; } break; } } if (objParticle == null) { return; } Vector3 pos = AmmoTran.position; Quaternion rot = AmmoTran.rotation; if (AmmoType == PlayerAmmoType.ChongJiBoAmmo) { if (healthScript != null) { //获取距离冲击波子弹最近的爆炸产生点. Transform tr = healthScript.GetAmmoLiZiMinDisSpawnPoint(transform); if (tr != null) { //冲击波子弹. pos = tr.position; rot = tr.rotation; } } else { //冲击波子弹没有击中npc时不产生自爆粒子. return; } } GameObject obj = (GameObject)Instantiate(objParticle, pos, rot); Transform tran = obj.transform; tran.parent = XkGameCtrl.PlayerAmmoArray; XkGameCtrl.CheckObjDestroyThisTimed(obj); SSPlayerAmmoBaoJi baoJiAmmo = obj.GetComponent <SSPlayerAmmoBaoJi>(); if (baoJiAmmo != null) { bool isDisplayBaoJi = false; if (healthScript != null) { if (healthScript.GetIsDaiJinQuanNpc() == true) { //代金券npc. isDisplayBaoJi = true; } //if (XkGameCtrl.GetInstance().m_SSDebugBaoJi != null) //{ // //测试爆击代金券npc. // XkGameCtrl.GetInstance().m_SSDebugBaoJi.IsHitDaiJinQuanNpc = healthScript.GetIsDaiJinQuanNpc(); //} } //else //{ // if (XkGameCtrl.GetInstance().m_SSDebugBaoJi != null) // { // //测试爆击代金券npc. // XkGameCtrl.GetInstance().m_SSDebugBaoJi.IsHitDaiJinQuanNpc = false; // } //} if (isDisplayBaoJi == true) { //初始化子弹爆炸粒子上的暴击效果. baoJiAmmo.Init(PlayerState); } else { //隐藏子弹爆炸粒子上的暴击效果. baoJiAmmo.HiddenBaoJi(); } } #else GameObject objParticle = null; GameObject obj = null; Transform tran = null; Vector3 hitPos = transform.position; RaycastHit hit; Vector3 forwardVal = Vector3.Normalize(AmmoEndPos - AmmoStartPos); if (AmmoType == PlayerAmmoType.PuTongAmmo) { float disVal = Vector3.Distance(AmmoEndPos, AmmoStartPos) + 10f; Physics.Raycast(AmmoStartPos, forwardVal, out hit, disVal, PlayerAmmoHitLayer); if (hit.collider != null) { XKAmmoParticleCtrl ammoParticleScript = hit.collider.GetComponent <XKAmmoParticleCtrl>(); if (ammoParticleScript != null && ammoParticleScript.PuTongAmmoLZ != null) { objParticle = ammoParticleScript.PuTongAmmoLZ; } else { string tagHitObj = hit.collider.tag; switch (tagHitObj) { case "metal": if (MetalParticle != null) { objParticle = MetalParticle; } break; case "concrete": if (ConcreteParticle != null) { objParticle = ConcreteParticle; } break; case "dirt": if (DirtParticle != null) { objParticle = DirtParticle; } break; case "wood": if (WoodParticle != null) { objParticle = WoodParticle; } break; case "water": if (WaterParticle != null) { objParticle = WaterParticle; } break; case "sand": if (SandParticle != null) { objParticle = SandParticle; } break; case "glass": if (GlassParticle != null) { objParticle = GlassParticle; } break; } if (objParticle == null) { objParticle = AmmoExplode; } } } else { objParticle = AmmoExplode; } } else { float disVal = Vector3.Distance(AmmoEndPos, AmmoStartPos) + 10f; Physics.Raycast(AmmoStartPos, forwardVal, out hit, disVal, PlayerAmmoHitLayer); if (hit.collider != null) { string tagHitObj = hit.collider.tag; switch (tagHitObj) { case "dirt": if (DirtParticle != null) { objParticle = DirtParticle; } break; case "water": if (WaterParticle != null) { objParticle = WaterParticle; } break; } if (objParticle == null) { objParticle = AmmoExplode; } } else { objParticle = AmmoExplode; } } if (objParticle == null) { return; } hitPos = explodePos; switch (AmmoType) { case PlayerAmmoType.DaoDanAmmo: Vector3 AmmoPos = transform.position - (transform.forward * 3f); Physics.Raycast(AmmoPos, forwardVal, out hit, 13f, XkGameCtrl.GetInstance().LandLayer); if (hit.collider != null) { Vector3 normalVal = hit.normal; Quaternion rotVal = Quaternion.LookRotation(normalVal); obj = (GameObject)Instantiate(objParticle, hitPos, rotVal); obj.transform.up = normalVal; } else { obj = (GameObject)Instantiate(objParticle, hitPos, transform.rotation); } break; case PlayerAmmoType.ChuanTouAmmo: obj = (GameObject)Instantiate(objParticle, explodePos, transform.rotation); break; default: obj = (GameObject)Instantiate(objParticle, hitPos, transform.rotation); break; } tran = obj.transform; tran.parent = XkGameCtrl.PlayerAmmoArray; XkGameCtrl.CheckObjDestroyThisTimed(obj); XkAmmoTieHuaCtrl tieHuaScript = obj.GetComponent <XkAmmoTieHuaCtrl>(); if (tieHuaScript != null && tieHuaScript.TieHuaTran != null) { Transform tieHuaTran = tieHuaScript.TieHuaTran; Vector3 AmmoPos = transform.position - (transform.forward * 3f); Physics.Raycast(AmmoPos, forwardVal, out hit, 13f, XkGameCtrl.GetInstance().PlayerAmmoHitLayer); if (hit.collider != null) { tieHuaTran.up = hit.normal; } } #endif }
internal void CheckPlayerBaoJiDengJi(PlayerAmmoType ammoType, PlayerEnum indexPlayer, XKNpcHealthCtrl npcHealth) { int indexVal = (int)indexPlayer - 1; if (indexVal >= 0 && indexVal <= 3) { if (m_TestBaoJiangData != null) { if (m_TestBaoJiangData.IsOpenTest == true) { if (m_TestBaoJiangData.IndexBaoJi >= 0 && m_TestBaoJiangData.IndexBaoJi <= 3) { //测试暴击数据信息. indexVal = m_TestBaoJiangData.IndexBaoJi; m_PlayerBaoJiDt[indexVal].BaoJiDengJi = indexVal; return; } } } switch (ammoType) { case PlayerAmmoType.DaoDanAmmo: case PlayerAmmoType.PaiJiPaoAmmo: case PlayerAmmoType.ChuanTouAmmo: case PlayerAmmoType.SanDanAmmo: case PlayerAmmoType.ChongJiBoAmmo: { if (Time.time - m_PlayerBaoJiDt[indexVal].TimeBaoJi > 0.05f) { //玩家导弹暴击间隔时间必须大于导弹发射的冷却时间. if (npcHealth != null && npcHealth.GetIsDaiJinQuanNpc() == true) { //只有代金券Npc才可以被暴击. if (Time.time - m_PlayerBaoJiDt[indexVal].TimeBaoJi <= m_TimeBaoJi) { //暴击间隔时间必须小于设定数值. m_PlayerBaoJiDt[indexVal].ShiWuCount = 0; if (m_PlayerBaoJiDt[indexVal].BaoJiDengJi < 3) { //最高4档. m_PlayerBaoJiDt[indexVal].BaoJiDengJi++; } if (m_PlayerBaoJiDt[indexVal].BaoJiDengJi > 3) { m_PlayerBaoJiDt[indexVal].BaoJiDengJi = 3; } } else { m_PlayerBaoJiDt[indexVal].ShiWuCount++; } //SSDebug.LogWarning("npcHealth ===================== " + npcHealth // + ", BaoJiDengJi ==== " + m_PlayerBaoJiDt[indexVal].BaoJiDengJi // + ", ShiWuCount ==== " + m_PlayerBaoJiDt[indexVal].ShiWuCount // + ", time ==== " + Time.time.ToString("f3")); m_PlayerBaoJiDt[indexVal].TimeBaoJi = Time.time; if (m_PlayerBaoJiDt[indexVal].ShiWuCount >= 1) { //失误次数超过n次重置暴击等级信息. //暴击失效. m_PlayerBaoJiDt[indexVal].Reset(); } } } break; } } } }
bool CheckAmmoHitObj(GameObject hitObjNpc, PlayerEnum playerIndex) { // BuJiBaoCtrl buJiBaoScript = hitObjNpc.GetComponent<BuJiBaoCtrl>(); // if (buJiBaoScript != null) { // buJiBaoScript.RemoveBuJiBao(playerIndex); //buJiBaoScript // return; // } bool isStopCheckHit = false; if (AmmoType != PlayerAmmoType.PaiJiPaoAmmo) { XKPlayerCheckCamera checkCam = hitObjNpc.GetComponent <XKPlayerCheckCamera>(); if (checkCam != null) { IsHitNpcAmmo = true; //SSDebug.LogWarning("MoveAmmoOnCompelteITween ============== 55555555555555555"); MoveAmmoOnCompelteITween(); return(true); } } XKNpcHealthCtrl healthScript = hitObjNpc.GetComponent <XKNpcHealthCtrl>(); if (healthScript != null && !healthScript.GetIsDeathNpc()) { /*Debug.Log("Unity:"+"CheckAmmoHitObj -> OnDamageNpc: " +"AmmoType "+AmmoType +", AmmoName "+AmmoTran.name +", NpcName "+healthScript.GetNpcName() +", AmmoDamageDis "+AmmoDamageDis);*/ bool isHitNpc = false; switch (AmmoType) { case PlayerAmmoType.ChuanTouAmmo: case PlayerAmmoType.PaiJiPaoAmmo: { if (NpcHealthList == null) { NpcHealthList = new List <XKNpcHealthCtrl>(); } if (!NpcHealthList.Contains(healthScript)) { NpcHealthList.Add(healthScript); isHitNpc = true; } break; } default: { IsHitNpcAmmo = true; //MoveAmmoOnCompelteITween(); isStopCheckHit = true; isHitNpc = true; break; } } if (isHitNpc) { int baoJiDamage = 0; if (AmmoType == PlayerAmmoType.ChuanTouAmmo || AmmoType == PlayerAmmoType.DaoDanAmmo || AmmoType == PlayerAmmoType.PaiJiPaoAmmo || AmmoType == PlayerAmmoType.SanDanAmmo || AmmoType == PlayerAmmoType.ChongJiBoAmmo) { //获取玩家对代金券npc的暴击伤害. XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.CheckPlayerBaoJiDengJi(AmmoType, PlayerState, healthScript); if (XkGameCtrl.GetInstance().m_CaiPiaoHealthDt != null && healthScript.GetIsDaiJinQuanNpc() == true) { baoJiDamage = XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.GetBaoJiDamage(PlayerState); } } //if (XkGameCtrl.GetInstance().m_CaiPiaoHealthDt != null && healthScript.GetIsDaiJinQuanNpc() == true) //{ // if (AmmoType == PlayerAmmoType.ChuanTouAmmo // || AmmoType == PlayerAmmoType.DaoDanAmmo // || AmmoType == PlayerAmmoType.PaiJiPaoAmmo // || AmmoType == PlayerAmmoType.SanDanAmmo) // { // //获取玩家对代金券npc的暴击伤害. // XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.CheckPlayerBaoJiDengJi(AmmoType, PlayerState, healthScript); // baoJiDamage = XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.GetBaoJiDamage(PlayerState); // } //} healthScript.OnDamageNpc(DamageNpc + baoJiDamage, PlayerState, AmmoType, IsAiFireAmmo); SpawnAmmoParticleObj(healthScript); } if (isStopCheckHit == true) { //停止子弹的伤害检测. if (AmmoType == PlayerAmmoType.ChongJiBoAmmo) { //冲击波子弹不允许调用MoveAmmoOnCompelteITween. } else { //SSDebug.LogWarning("MoveAmmoOnCompelteITween ============== 44444444444444444"); MoveAmmoOnCompelteITween(); } } } if (hitObjNpc != null) { NpcAmmoCtrl npcAmmoScript = hitObjNpc.GetComponent <NpcAmmoCtrl>(); if (npcAmmoScript != null) { npcAmmoScript.MoveAmmoOnCompelteITween(); } if (AmmoType == PlayerAmmoType.DaoDanAmmo || AmmoType == PlayerAmmoType.GaoBaoAmmo || AmmoType == PlayerAmmoType.PuTongAmmo || AmmoType == PlayerAmmoType.SanDanAmmo || AmmoType == PlayerAmmoType.ChongJiBoAmmo) { if (hitObjNpc.layer != LayerMask.NameToLayer("Default")) { //SSDebug.Log("hitObjNpc ===================================== " + hitObjNpc.name); IsHitNpcAmmo = true; if (AmmoType == PlayerAmmoType.ChongJiBoAmmo) { //冲击波子弹不允许在这里调用MoveAmmoOnCompelteITween,否则会被瞬间删除. } else { //SSDebug.LogWarning("MoveAmmoOnCompelteITween ============== 333333333333333"); MoveAmmoOnCompelteITween(); } isStopCheckHit = true; } } } return(isStopCheckHit); }