void Awake() { switch (FanWeiState) { case PointState.Qian: _InstanceQian = this; break; case PointState.Hou: _InstanceHou = this; break; case PointState.Zuo: _InstanceZuo = this; break; case PointState.You: _InstanceYou = this; break; } MeshRenderer mesh = gameObject.GetComponent <MeshRenderer>(); if (mesh != null) { Destroy(mesh); } MeshFilter meshFt = gameObject.GetComponent <MeshFilter>(); if (meshFt != null) { Destroy(meshFt); } }
void Awake() { switch (FanWeiState) { case PointState.Qian: _InstanceQian = this; break; case PointState.Hou: _InstanceHou = this; break; case PointState.Zuo: _InstanceZuo = this; break; case PointState.You: _InstanceYou = this; break; } }
void CheckDisGameCamera() { if (m_FanWeiHou == null) { m_FanWeiHou = XKPlayerMvFanWei.GetInstanceHou(); } if (DeathExplodePoint == null) { DeathExplodePoint = transform; } if (XkPlayerCtrl.GetInstanceFeiJi() != null) { GameCameraTr = XkPlayerCtrl.GetInstanceFeiJi().transform; } if (GameCameraTr == null) { Debug.LogWarning("Unity:" + "CheckDisGameCamera -> GameCameraTr is null"); return; } Vector3 vecA = GameCameraTr.forward; Vector3 vecB = Vector3.zero; Vector3 posA = DeathExplodePoint.position; Vector3 posB = GameCameraTr.position; posA.y = posB.y = 0f; vecB = posA - posB; vecA.y = vecB.y = 0f; if (Vector3.Dot(vecA, vecB) <= 0f) { return; } DisCamera = MinDisCamera; //Debug.Log("Unity:"+"DisCamera "+DisCamera); }
/** * key == 0 -> 检测子弹打中的物体. * key == 1 -> 检测子弹打中的物体, 并且用来调用爆炸特效. */ GameObject CheckPlayerAmmoOverlapSphereHit(int key = 0) { bool isBreak = false; GameObject obj = null; float disDamage = key == 0 ? AmmoDamageDis : 0.2f; XKPlayerMvFanWei playerMvFanWei = null; Collider[] hits = Physics.OverlapSphere(AmmoTran.position, disDamage, PlayerAmmoHitLayer); foreach (Collider c in hits) { // Don't collide with triggers if (c.isTrigger || IsChuanJiaDanHitCamColForward) { continue; } if (AmmoType != PlayerAmmoType.PaiJiPaoAmmo) { playerMvFanWei = c.GetComponent <XKPlayerMvFanWei>(); if (playerMvFanWei != null) { if (playerMvFanWei.FanWeiState == PointState.Hou) { continue; } if (playerMvFanWei.FanWeiState == PointState.Qian) { if (AmmoType != PlayerAmmoType.ChuanTouAmmo) { isBreak = true; obj = c.gameObject; MoveAmmoOnCompelteITween(); break; } else { IsChuanJiaDanHitCamColForward = true; break; } } } } switch (key) { case 0: isBreak = CheckAmmoHitObj(c.gameObject, PlayerState); if (isBreak) { break; } break; case 1: isBreak = true; obj = c.gameObject; break; } } return(obj); }
public void OnDamageNpc(int damageNpcVal = 1, PlayerEnum playerSt = PlayerEnum.Null, PlayerAmmoType pAmmoType = PlayerAmmoType.Null, bool isAiFireAmmo = false) { if (IsDeathNpc) { return; } if (pAmmoType == PlayerAmmoType.SanDanAmmo) { if (Time.time - TimeSanDanDamage < XKPlayerGlobalDt.GetInstance().TimeShouDongDaoDan) { //对于玩家的主炮散弹在同一次发射内只计算一次伤害. //SSDebug.LogWarning("************* pAmmoType ====== " + pAmmoType); return; } TimeSanDanDamage = Time.time; } if (pAmmoType == PlayerAmmoType.ChuanTouAmmo) { if (XKPlayerMvFanWei.GetInstanceQian() != null && XKPlayerCamera.GetInstanceFeiJi() != null) { Vector3 forwardVecCam = XKPlayerCamera.GetInstanceFeiJi().transform.forward; Vector3 posA = transform.position; Vector3 posB = XKPlayerMvFanWei.GetInstanceQian().transform.position; forwardVecCam.y = posA.y = posB.y = 0f; Vector3 vecBA = posA - posB; if (Vector3.Dot(forwardVecCam, vecBA) >= 0f) { //npc在镜头前方范围之外,不受玩家子弹伤害. return; } } } if (IsBackDaiJinQuanNpcBlood == true) { //代金券npc重置血值后,给一定时间的无敌状态. if (Time.time - m_TimeLastBackDaiJinQuanNpcBlood <= 0.5f) { return; } else { IsBackDaiJinQuanNpcBlood = false; } } //switch (NpcJiFen) //{ // case NpcJiFenEnum.Boss: // if (!XKBossXueTiaoCtrl.GetInstance().GetIsCanSubXueTiaoAmount()) // { // if (NpcDamageCom != null) // { // NpcDamageCom.PlayNpcDamageEvent(); // } // return; // } // break; //} if (NpcDamageCom != null) { NpcDamageCom.PlayNpcDamageEvent(); } if (NpcScript != null) { if (NpcScript.IsCaiPiaoZhanChe == true && NpcScript.IsEnterCameraBox == false) { //彩票战车和boss没有进入摄像机盒子,不计算伤害. return; } } if (CountActivePlayer != XkGameCtrl.PlayerActiveNum) { if (CountActivePlayer != 0) { //fix PuTongAmmoCount. int indexValTmp = CountActivePlayer - 1; int puTongAmmoNumTmp = MaxPuTongAmmo[indexValTmp]; indexValTmp = XkGameCtrl.PlayerActiveNum - 1; if (indexValTmp >= 0) { float healthPer = (float)PuTongAmmoCount / puTongAmmoNumTmp; //int oldPuTongAmmoCount = PuTongAmmoCount; PuTongAmmoCount = (int)(healthPer * MaxPuTongAmmo[indexValTmp]); /*Debug.Log("Unity:"+"fix npc health -> PuTongAmmoCount "+PuTongAmmoCount +", oldPuTongAmmoCount "+oldPuTongAmmoCount);*/ } } CountActivePlayer = XkGameCtrl.PlayerActiveNum; } if (NpcScript == null || (NpcScript != null && !NpcScript.GetIsWuDi())) { PuTongAmmoCount += damageNpcVal; } int indexVal = XkGameCtrl.PlayerActiveNum - 1; indexVal = indexVal < 0 ? 0 : indexVal; int puTongAmmoNum = MaxPuTongAmmo[indexVal]; if (NpcScript != null) { if (NpcScript.IsZhanCheNpc || NpcScript.IsJPBossNpc) { if (XkGameCtrl.GetInstance().m_GamePlayerAiData.IsActiveAiPlayer == true) { //当没有玩家激活游戏时,彩票战车和JPBoss采用原血量的一定比例来计算. puTongAmmoNum = (int)(XkGameCtrl.GetInstance().m_ZhanCheBossBloodPer *puTongAmmoNum); } } } /*if (NpcJiFen == NpcJiFenEnum.Boss) * { * float bossAmount = (float)(puTongAmmoNum - PuTongAmmoCount) / puTongAmmoNum; * bossAmount = bossAmount < 0f ? 0f : bossAmount; * if (XKBossXueTiaoCtrl.GetInstance() != null) * { * XKBossXueTiaoCtrl.GetInstance().SetBloodBossAmount(bossAmount, this); * } * }*/ if (NpcScript != null) { if (NpcScript.IsCaiPiaoZhanChe == true) { if (XkGameCtrl.GetInstance() != null && XKPlayerFenShuCtrl.GetInstance() != null) { if (pAmmoType == PlayerAmmoType.DaoDanAmmo || pAmmoType == PlayerAmmoType.PaiJiPaoAmmo || pAmmoType == PlayerAmmoType.ChuanTouAmmo || pAmmoType == PlayerAmmoType.SanDanAmmo || pAmmoType == PlayerAmmoType.ChongJiBoAmmo) { int jiFenVal = XkGameCtrl.GetInstance().m_DaoDanHitBossJiFen; //XKPlayerFenShuCtrl.GetInstance().ShowPlayerFenShu(playerSt, GetJiFen(jiFenVal)); XKPlayerFenShuCtrl.GetInstance().ShowPlayerFenShu(playerSt, jiFenVal); } } float bloodAmount = (float)(puTongAmmoNum - PuTongAmmoCount) / puTongAmmoNum; bloodAmount = bloodAmount < 0f ? 0f : bloodAmount; bool isCanJiBao = true; if (XkGameCtrl.GetInstance().m_GamePlayerAiData.IsActiveAiPlayer == true) { //没有玩家激活游戏时,Ai都认为是可以击爆战车或Boss. } else { //有玩家激活游戏. if (XkGameCtrl.GetInstance().m_CaiPiaoHealthDt != null) { isCanJiBao = XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.m_CurrentTotalHealthDt.IsCanJiBao; } } if (isCanJiBao == false) { //不允许被玩家击爆的代金券npc. if (IsBloodToStage02 == false) { if (bloodAmount <= 0.24f) { //强制保留一定的血量. m_BloodAmoutValue = bloodAmount = 0.24f; IsBloodToStage02 = true; m_TimeLastBloodToStage = Time.time; PuTongAmmoCount = puTongAmmoNum - 1; } } else if (IsBloodToStage01 == false) { float minBloodAmount = 0.12f; //最小极限血值. if (m_BloodAmoutValue > minBloodAmount) { //血值已经降到最低阶段. float dTimeVal = 0.4f; if (XkGameCtrl.GetInstance().m_CaiPiaoHealthDt != null) { dTimeVal = XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.m_TimeNoDead; } if (Time.time - m_TimeLastBloodToStage >= dTimeVal) { //每次间隔一定时间减少一定血值. m_TimeLastBloodToStage = Time.time; float subBloodAmount = 0.02f; //每次减少的血值. if (m_BloodAmoutValue > minBloodAmount) { m_BloodAmoutValue -= subBloodAmount; if (m_BloodAmoutValue < minBloodAmount) { //强制保护的血值信息. m_BloodAmoutValue = minBloodAmount; IsBloodToStage01 = true; } } } } bloodAmount = m_BloodAmoutValue; PuTongAmmoCount = puTongAmmoNum - 1; //强制保留一定的血值. } else { float minBloodAmount = 0.03f; //最小极限血值. if (m_BloodAmoutValue > minBloodAmount) { //血值已经降到最低阶段. float dTimeVal = 0.4f; if (XkGameCtrl.GetInstance().m_CaiPiaoHealthDt != null) { dTimeVal = XkGameCtrl.GetInstance().m_CaiPiaoHealthDt.m_TimeNoDead; } if (Time.time - m_TimeLastBloodToStage >= dTimeVal) { //每次间隔一定时间减少一定血值. m_TimeLastBloodToStage = Time.time; float subBloodAmount = 0.01f; //每次减少的血值. if (m_BloodAmoutValue > minBloodAmount) { m_BloodAmoutValue -= subBloodAmount; if (m_BloodAmoutValue < minBloodAmount) { //强制保护的血值信息. m_BloodAmoutValue = minBloodAmount; } } } } bloodAmount = m_BloodAmoutValue; PuTongAmmoCount = puTongAmmoNum - 1; //强制保留一定的血值. } } //彩票战车和boss的血条UI信息更新. SSUIRoot.GetInstance().m_GameUIManage.SetDaiJinQuanNpcXueTiaoAmount(bloodAmount); if (XkGameCtrl.GetInstance().m_GamePlayerAiData.IsActiveAiPlayer == true) { //没有玩家激活游戏时,Ai都认为是不可以击爆JPBoss特殊武器的. } else { //JPBoss受到玩家子弹伤害. if (NpcScript.IsJPBossNpc == true) { NpcScript.OnDamageJPBossWeapon(bloodAmount); } } } } /*Debug.Log("Unity:"+"OnDamageNpc -> " +", nameNpc "+NpcNameInfo +", puTongAmmoNum "+puTongAmmoNum);*/ if (PuTongAmmoCount >= puTongAmmoNum) { if (NpcScript != null) { if (NpcScript.IsZhanCheNpc) { //战车npc是否可以被击爆的判断. if (XkGameCtrl.GetInstance().IsCaiPiaoHuLuePlayerIndex == false && NpcScript.m_IndexPlayerJiBao != playerSt) { //不是可以击爆战车npc的玩家. return; } if (XkGameCtrl.GetInstance().m_GamePlayerAiData.IsActiveAiPlayer == true) { //没有激活任何玩家. } else { if (!XkPlayerCtrl.GetInstanceFeiJi().m_SpawnNpcManage.m_CaiPiaoDataManage.m_GameCaiPiaoData.GetIsChuCaiPiaoByDeCaiState(SSCaiPiaoDataManage.GameCaiPiaoData.DeCaiState.ZhanChe, NpcScript.m_DaiJinQuanState)) { //战车彩池的彩票积累的不够. return; } } } if (NpcScript.IsJPBossNpc) { //JPBoss是否可以被击爆的判断. if (XkGameCtrl.GetInstance().IsCaiPiaoHuLuePlayerIndex == false && NpcScript.m_IndexPlayerJiBao != playerSt) { //不是可以击爆JPBoss的玩家. return; } if (XkGameCtrl.GetInstance().m_GamePlayerAiData.IsActiveAiPlayer == true) { //没有激活任何玩家. } else { if (!XkPlayerCtrl.GetInstanceFeiJi().m_SpawnNpcManage.m_CaiPiaoDataManage.m_GameCaiPiaoData.GetIsChuCaiPiaoByDeCaiState(SSCaiPiaoDataManage.GameCaiPiaoData.DeCaiState.JPBoss)) { //JPBoss彩池的彩票积累的不够. return; } } } } if (IsDeathNpc) { return; } IsDeathNpc = true; if (IsOpenCameraShake) { XKPlayerCamera.GetInstanceFeiJi().HandlePlayerCameraShake(); } if (NpcJiFen == NpcJiFenEnum.Boss && BossXieZiScript != null) { BossXieZiScript.ResetBossXieZiShouBiInfo(); } if (BoxColCom != null) { BoxColCom.enabled = false; } CheckSpawnDaoJuCom(playerSt); CheckNpcDeathExplode(playerSt); CheckHiddenNpcObjArray(); // bool isAddKillNpcNum = true; // if (NpcScript != null && CannonScript != null) { // if (NpcScript.GetIsDeathNPC()) { // isAddKillNpcNum = false; // Debug.Log("Unity:"+"name "+NpcScript.name+", isAddKillNpcNum "+isAddKillNpcNum); // } // } if (!IsYouTongNpc) { switch (NpcJiFen) { case NpcJiFenEnum.Boss: if (GameTimeBossCtrl.GetInstance() != null && GameTimeBossCtrl.GetInstance().GetTimeBossResidual() > 0) { XkGameCtrl.GetInstance().AddPlayerKillNpc(PlayerEnum.Null, NpcJiFen, GetJiFen()); } break; default: XkGameCtrl.GetInstance().AddPlayerKillNpc(playerSt, NpcJiFen, GetJiFen()); ShowPiaoFen(playerSt); break; } // if (isAddKillNpcNum) { // switch (NpcJiFen) { // case NpcJiFenEnum.Boss: // if (GameTimeBossCtrl.GetInstance().GetTimeBossResidual() > 0) { // XkGameCtrl.GetInstance().AddPlayerKillNpc(PlayerEnum.Null, NpcJiFen, JiFenVal); // } // break; // default: // XkGameCtrl.GetInstance().AddPlayerKillNpc(playerSt, NpcJiFen, JiFenVal); // break; // } // } } else { CheckYouTongDamageNpc(); } if (NpcScript != null) { if (CannonScript != null) { CannonScript.OnRemoveCannon(playerSt, 1); } if (NpcJiFen != NpcJiFenEnum.Boss && NpcScript.GetIsBossNpc()) { return; } NpcScript.TriggerRemovePointNpc(1, CannonScript, pAmmoType); if (NpcScript.IsCaiPiaoZhanChe) { SSCaiPiaoDataManage.GameCaiPiaoData.DeCaiState deCaiType = SSCaiPiaoDataManage.GameCaiPiaoData.DeCaiState.ZhanChe; //彩票boss或战车npc. if (NpcScript.GetIsBossNpc()) { deCaiType = SSCaiPiaoDataManage.GameCaiPiaoData.DeCaiState.JPBoss; } else { if (XkPlayerCtrl.GetInstanceFeiJi() != null) { XkPlayerCtrl.GetInstanceFeiJi().AddGetZhanCheDaiJinQuanPlayer(XKPlayerMoveCtrl.GetInstance(playerSt)); } } if (XkPlayerCtrl.GetInstanceFeiJi().m_SpawnNpcManage.m_CaiPiaoDataManage != null) { if (isAiFireAmmo == false) { //只有被玩家击爆的代金券npc才允许出彩. XkPlayerCtrl.GetInstanceFeiJi().m_SpawnNpcManage.m_CaiPiaoDataManage.m_GameCaiPiaoData.SubGameDeCaiValByDeCaiState(playerSt, deCaiType, SSCaiPiaoDataManage.SuiJiDaoJuState.BaoXiang, NpcScript.m_DaiJinQuanState); } //else //{ //被Ai坦克击爆的代金券npc不允许出彩. //SSDebug.Log("The DaiJinQuan was killed by AiTank"); //} } } else { //普通npc被击杀. //if (XkGameCtrl.GetInstance().m_PlayerJiChuCaiPiaoData != null && DeathExplodePoint != null) //{ // //随机送出正常得彩. // XkGameCtrl.GetInstance().m_PlayerJiChuCaiPiaoData.CheckPlayerSongPiaoInfo(playerSt, DeathExplodePoint.position); //} } } else if (CannonScript != null) { CannonScript.OnRemoveCannon(playerSt, 1); //炮台类npc被击杀. //if (XkGameCtrl.GetInstance().m_PlayerJiChuCaiPiaoData != null && DeathExplodePoint != null) //{ // //随机送出正常得彩. // XkGameCtrl.GetInstance().m_PlayerJiChuCaiPiaoData.CheckPlayerSongPiaoInfo(playerSt, DeathExplodePoint.position); //} } } }
/** * key == 0 -> 检测子弹打中的物体. * key == 1 -> 检测子弹打中的物体, 并且用来调用爆炸特效. */ GameObject CheckPlayerAmmoOverlapSphereHit(int key = 0) { GameObject obj = null; #if !TEST_CLOSE_SPHER_HIT bool isBreak = false; float disDamage = key == 0 ? AmmoDamageDis : 0.5f; XKPlayerMvFanWei playerMvFanWei = null; Collider[] hits = Physics.OverlapSphere(AmmoTran.position, disDamage, PlayerAmmoHitLayer); Collider col = null; int length = hits.Length; //Debug.Log("length ======================== " + length); for (int i = 0; i < length; i++) { col = hits[i]; if (col == null) { continue; } // Don't collide with triggers if (col.isTrigger || IsChuanJiaDanHitCamColForward) { continue; } if (AmmoType == PlayerAmmoType.PaiJiPaoAmmo || AmmoType == PlayerAmmoType.ChongJiBoAmmo) { //范围伤害类型子弹. //迫击炮和冲击波子弹需要忽略主角碰撞范围. } else { //非范围伤害类型子弹. playerMvFanWei = col.GetComponent <XKPlayerMvFanWei>(); if (playerMvFanWei != null) { if (playerMvFanWei.FanWeiState == PointState.Hou) { continue; } if (playerMvFanWei.FanWeiState == PointState.Qian) { IsHitNpcAmmo = true; if (AmmoType != PlayerAmmoType.ChuanTouAmmo) { isBreak = true; obj = col.gameObject; //SSDebug.LogWarning("MoveAmmoOnCompelteITween ============== 111111111111"); MoveAmmoOnCompelteITween(); break; } else { IsChuanJiaDanHitCamColForward = true; break; } } } } switch (key) { case 0: isBreak = CheckAmmoHitObj(col.gameObject, PlayerState); if (isBreak) { break; } break; case 1: isBreak = true; obj = col.gameObject; break; } } #endif return(obj); }
void Init() { m_FanWeiHou = XKPlayerMvFanWei.GetInstanceHou(); }