/// <summary> /// 获取彩票战车或boss. /// </summary> public GameObject GetCaiPiaoNpc() { XKNpcMoveCtrl npc = m_ZhanCheJPBossData.ZhanCheData.GetNpcMoveComByIndex(0); if (npc != null) { if (npc.IsEnterCameraBox && npc.GetIsDeathNPC() == false) { return(npc.gameObject); } } npc = m_ZhanCheJPBossData.JPBossData.GetNpcMoveComByIndex(0); if (npc != null) { if (npc.IsEnterCameraBox && npc.GetIsDeathNPC() == false) { return(npc.gameObject); } } npc = m_ZhanCheJPBossData.SuperJPBossData.GetNpcMoveComByIndex(0); if (npc != null) { if (npc.IsEnterCameraBox && npc.GetIsDeathNPC() == false) { return(npc.gameObject); } } return(null); }
void Update() { if (!XkGameCtrl.IsActivePlayerOne && !XkGameCtrl.IsActivePlayerTwo) { if (!XkGameCtrl.IsMoveOnPlayerDeath) { if (!IsStopAnimation) { IsStopAnimation = true; AnimatorCom.speed = 0f; } } } else { if (IsStopAnimation) { IsStopAnimation = false; AnimatorCom.speed = 1f; } } if (AnimatorCom != null && !AnimatorCom.enabled && AnimatorCom.runtimeAnimatorController != null && NpcScript != null && !NpcScript.GetIsDeathNPC()) { if (!NpcScript.IsAniMove) { AnimatorCom.enabled = true; } } }
void CheckAimNpcObj() { float dTime = Time.realtimeSinceStartup - TimeCheckAimNpcLast; if (dTime < 0.1f) { return; } TimeCheckAimNpcLast = Time.realtimeSinceStartup; if (AimSpawnPoint.Count <= 0) { AimNpcObj = null; //没有需要瞄准的npc. return; } float disVal = 999999f; GameObject npcObj = null; int max = AimSpawnPoint.Count; for (int i = 0; i < max; i++) { GameObject pointNpc = AimSpawnPoint[i].GetNpcLoopObj(); if (pointNpc == null) { continue; } if (pointNpc.transform.position == new Vector3(0f, -1800f, 0f)) { continue; } XKNpcMoveCtrl npcMoveScript = pointNpc.GetComponent <XKNpcMoveCtrl>(); if (npcMoveScript == null || npcMoveScript.GetIsDeathNPC()) { continue; } Transform pointNpcTran = pointNpc.transform; float disTmp = Vector3.Distance(PlayerTran.position, pointNpcTran.position); if (disTmp < disVal) { disVal = disTmp; npcObj = pointNpc; } } if (npcObj == null) { AimNpcObj = null; //没有找到需要瞄准的npc. return; } if (npcObj != AimNpcObj) { AimNpcObj = npcObj; //寻找并改变距离主角最近的npc. } }
public void OnDamageNpc(PlayerAmmoType state, PlayerEnum playerSt) { if (IsDeathNpc) { return; } if (NpcScript == null || (NpcScript != null && !NpcScript.GetIsWuDi())) { switch (state) { case PlayerAmmoType.PuTongAmmo: PuTongAmmoCount++; break; case PlayerAmmoType.GaoBaoAmmo: GaoBaoAmmoCount++; // Debug.Log(gameObject.name+":: GaoBaoAmmoCount "+GaoBaoAmmoCount+", MaxGaoBaoAmmo "+MaxGaoBaoAmmo // +", playerSt "+playerSt); break; case PlayerAmmoType.DaoDanAmmo: DaoDanAmmoCount++; // Debug.Log(gameObject.name+":: DaoDanAmmoCount "+MaxDaoDanAmmo+", MaxGaoBaoAmmo "+MaxDaoDanAmmo // +", playerSt "+playerSt); break; } } if (NpcShouJiFanKui != null) { NpcShouJiFanKui.PlayNpcDamageEvent(); } AmmoHurtCount++; if (MaxAmmoHurtLiZi > 0 && AmmoHurtCount >= MaxAmmoHurtLiZi) { if (HurtLiZiObj != null && !HurtLiZiObj.activeSelf) { HurtLiZiObj.SetActive(true); } } int puTongAmmoNum = MaxPuTongAmmo; //单机单人. if (XkGameCtrl.GameModeVal == GameMode.LianJi && XkPlayerCtrl.PlayerTranFeiJi != null && XkPlayerCtrl.PlayerTranTanKe != null) { if (XkGameCtrl.IsActivePlayerOne && XkGameCtrl.IsActivePlayerTwo) { puTongAmmoNum = LJMaxPuTongAmmoSR; //联机双人. } else { puTongAmmoNum = LJMaxPuTongAmmoSR; //联机单人. } } else { if (XkGameCtrl.IsActivePlayerOne && XkGameCtrl.IsActivePlayerTwo) { puTongAmmoNum = MaxPuTongAmmoSR; //单机双人. } } if (PuTongAmmoCount >= puTongAmmoNum || GaoBaoAmmoCount >= MaxGaoBaoAmmo || DaoDanAmmoCount >= MaxDaoDanAmmo) { if (IsDeathNpc) { return; } IsDeathNpc = true; CheckHiddenNpcObjArray(); bool isAddKillNpcNum = true; if (NpcScript != null && CannonScript != null) { if (NpcScript.GetIsDeathNPC()) { isAddKillNpcNum = false; } } if (!IsYouTongNpc) { if (Network.peerType != NetworkPeerType.Server) { if (isAddKillNpcNum) { XkGameCtrl.GetInstance().AddPlayerKillNpc(playerSt, NpcJiFen); } XkGameCtrl.GetInstance().AddYouLiangDian(YouLiangDian, playerSt); if (YouLiangDianUICtrl.GetInstance() != null) { YouLiangDianUICtrl.GetInstance().HandleNpcYouLiangDian(YouLiangDian, transform); } } } else { if (playerSt != PlayerEnum.Null) { CheckYouTongDamageNpc(); } } if (NpcScript != null) { if (CannonScript != null) { CannonScript.OnRemoveCannon(playerSt, 1); } NpcScript.TriggerRemovePointNpc(1, CannonScript); } else if (CannonScript != null) { CannonScript.OnRemoveCannon(playerSt, 1); } } }
void StartSpawnNpc() { if (!enabled || !gameObject.activeSelf) { return; } if (PointPlayerSt == PlayerEnum.Null) { return; } if (Network.peerType == NetworkPeerType.Disconnected) { switch (PointPlayerSt) { case PlayerEnum.PlayerOne: //if (!XkGameCtrl.IsActivePlayerOne) { // return; //} break; case PlayerEnum.PlayerTwo: //if (!XkGameCtrl.IsActivePlayerTwo) { // return; //} break; } } else { if (!GameTypeCtrl.IsTankVRStatic) { switch (Network.connections.Length) { case 0: if (PointPlayerSt == PlayerEnum.PlayerTwo && GameTypeCtrl.PlayerPCState == PlayerEnum.PlayerOne) { return; } if (PointPlayerSt == PlayerEnum.PlayerOne && GameTypeCtrl.PlayerPCState == PlayerEnum.PlayerTwo) { return; } break; } } } if (ScreenDanHeiCtrl.IsStartGame) { if ((XkGameCtrl.GameModeVal == GameMode.DanJiFeiJi && PointType == SpawnPointType.DiMian) || (XkGameCtrl.GameModeVal == GameMode.DanJiTanKe && PointType == SpawnPointType.KongZhong)) { return; } if (XkGameCtrl.GameModeVal == GameMode.LianJi && PointType == SpawnPointType.KongZhong && GameTypeCtrl.IsTankVRStatic) { return; } if (XkGameCtrl.GameModeVal == GameMode.LianJi && PointType == SpawnPointType.DiMian && !GameTypeCtrl.IsTankVRStatic) { return; } if (IsDoublePlayer && (!XkGameCtrl.IsActivePlayerOne || !XkGameCtrl.IsActivePlayerTwo)) { return; } } GameObject obj = null; XKHuoCheCtrl hcScript = NpcObj.GetComponent <XKHuoCheCtrl>(); if (hcScript != null) { obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation); if (obj == null) { //Debug.Log("StartSpawnNpc -> Cannot spawn HuoCheNpc!"); return; } obj.transform.parent = XkGameCtrl.MissionCleanup; HuoCheScript = obj.GetComponent <XKHuoCheCtrl>(); HuoCheScript.SetHuoCheInfo(this); //HuoCheScript.StartMoveHuoChe(NpcPath); NpcLoopObj = obj; return; } DaPaoScript = NpcObj.GetComponent <XKDaPaoCtrl>(); if (DaPaoScript != null) { // Debug.Log("Spawn Cannon... "); obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation); if (obj == null) { //Debug.Log("StartSpawnNpc -> Cannot spawn DaPaoNpc!"); return; } if (!IsHuoCheNpc) { obj.transform.parent = XkGameCtrl.MissionCleanup; } else { obj.transform.parent = transform.parent; } //XkGameCtrl.GetInstance().AddNpcTranToList(obj.transform); DaPaoScript = obj.GetComponent <XKDaPaoCtrl>(); DaPaoScript.SetSpawnPointScript(this); NpcLoopObj = obj; return; } if (IsRemoveSpawnPointNpc) { return; } //Debug.Log("SpawnPointAllNpc...NpcObj is "+NpcObj.name+", SpawnNpcCount "+SpawnNpcCount); if (ChildSpawnPoint.Length > 0) { //spawn fangZhenNpc GameObject fangZhenObj = SpawnPointNpc(NpcFangZhen, transform.position, transform.rotation); if (fangZhenObj == null) { //Debug.LogError("StartSpawnNpc -> Cannot spawn FangZhenNpc! NpcFangZhen "+NpcFangZhen.name); //fangZhenObj.name = "null"; return; } NpcFangZhenScript = fangZhenObj.GetComponent <XKNpcFangZhenCtrl>(); //NpcFangZhenScript.ActiveFangZhenNpc(); XKNpcMoveCtrl npcScript = null; Transform fangZhenTran = fangZhenObj.transform; fangZhenTran.parent = XkGameCtrl.MissionCleanup; obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation); if (obj == null) { //Debug.Log("StartSpawnNpc -> Cannot spawn FangZhenChildNpc --- 1"); return; } npcScript = obj.GetComponent <XKNpcMoveCtrl>(); if (npcScript != null) { npcScript.ActiveIsFangZhenNpc(); npcScript.SetNpcSpawnScriptInfo(this); } obj.transform.parent = fangZhenTran; for (int i = 0; i < ChildSpawnPoint.Length; i++) { obj = SpawnPointNpc(NpcObj, ChildSpawnPoint[i].position, ChildSpawnPoint[i].rotation); if (obj == null) { //Debug.LogWarning("StartSpawnNpc -> Cannot spawn FangZhenChildNpc --- index "+i); break; } npcScript = obj.GetComponent <XKNpcMoveCtrl>(); if (npcScript != null) { npcScript.ActiveIsFangZhenNpc(); npcScript.SetNpcSpawnScriptInfo(this); } obj.transform.parent = fangZhenTran; } NpcFangZhenScript.SetSpawnNpcInfo(this); NpcLoopObj = fangZhenObj; return; } if (NpcLoopObj != null && SpawnMaxNpc > 1) { if (IsRemoveSpawnPointNpc) { return; } XKNpcMoveCtrl npcScript = NpcLoopObj.GetComponent <XKNpcMoveCtrl>(); if (npcScript != null && !npcScript.GetIsDeathNPC()) { Invoke("StartSpawnNpc", LoopSpawnTime); return; } } if (SpawnNpcCount > 0) { int maxVal = NpcSpawnLoop.Length; int randVal = Random.Range(0, (maxVal + 1)); if (randVal == 0) { obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation); } else { randVal = randVal > maxVal ? maxVal : randVal; obj = SpawnPointNpc(NpcSpawnLoop[randVal - 1], transform.position, transform.rotation); } } else { obj = SpawnPointNpc(NpcObj, transform.position, transform.rotation); } if (obj == null) { //Debug.Log("StartSpawnNpc -> Cannot spawn PuTongNpc!"); return; } if (!IsHuoCheNpc) { obj.transform.parent = XkGameCtrl.MissionCleanup; } else { obj.transform.parent = transform.parent; } NpcScript[SpawnNpcCount] = obj.GetComponent <XKNpcMoveCtrl>(); if (NpcScript[SpawnNpcCount] != null) { NpcScript[SpawnNpcCount].SetSpawnNpcInfo(this); } NpcLoopObj = obj; SpawnNpcCount++; if (SpawnNpcCount >= SpawnMaxNpc) { return; } Invoke("StartSpawnNpc", LoopSpawnTime); }
public GameObject FindNpcObjFromNpcList(XKSpawnNpcPoint spawnCom, GameObject npcPrefab) { if (npcPrefab == null) { return(null); } GameObject npcObj = null; int max = NpcList.Count; XKNpcMoveCtrl npcMoveScript = null; XKDaPaoCtrl npcDaPaoScript = null; XKHuoCheCtrl npcHuoCheScript = null; XKNpcFangZhenCtrl npcFangZhenScript = null; if (max > 0 && NpcScriptSt != NpcScriptState.XKHuoChe) { for (int i = 0; i < max; i++) { if (NpcList[i] != null) { switch (NpcScriptSt) { case NpcScriptState.XKNpcMove: npcMoveScript = NpcList[i].GetComponent <XKNpcMoveCtrl>(); if (npcMoveScript != null && npcMoveScript.GetIsDeathNPC()) { GameObject realNpcObj = npcMoveScript.RealNpcTran.gameObject; if (!realNpcObj.activeSelf) { npcObj = NpcList[i]; } } break; case NpcScriptState.XKDaPao: npcDaPaoScript = NpcList[i].GetComponent <XKDaPaoCtrl>(); if (npcDaPaoScript != null && npcDaPaoScript.GetIsDeathNpc()) { npcDaPaoScript.SetSpawnPointScript(spawnCom); npcDaPaoScript.ResetNpcDaPaoInfo(); npcObj = NpcList[i]; } break; case NpcScriptState.XKHuoChe: break; case NpcScriptState.XKFangZhen: npcFangZhenScript = NpcList[i].GetComponent <XKNpcFangZhenCtrl>(); if (npcFangZhenScript != null && npcFangZhenScript.GetIsHiddenNpcObj() && !npcFangZhenScript.GetIsActiveFangZhen()) { npcObj = NpcList[i]; npcFangZhenScript.ActiveFangZhenNpc(); } break; } } if (npcObj != null) { break; } } } if (npcObj == null) { if (NpcScriptSt == NpcScriptState.Null) { npcMoveScript = npcPrefab.GetComponent <XKNpcMoveCtrl>(); if (npcMoveScript != null) { NpcScriptSt = NpcScriptState.XKNpcMove; } if (NpcScriptSt == NpcScriptState.Null) { npcDaPaoScript = npcPrefab.GetComponent <XKDaPaoCtrl>(); if (npcDaPaoScript != null) { NpcScriptSt = NpcScriptState.XKDaPao; } } if (NpcScriptSt == NpcScriptState.Null) { npcHuoCheScript = npcPrefab.GetComponent <XKHuoCheCtrl>(); if (npcHuoCheScript != null) { NpcScriptSt = NpcScriptState.XKHuoChe; } } if (NpcScriptSt == NpcScriptState.Null) { npcFangZhenScript = npcPrefab.GetComponent <XKNpcFangZhenCtrl>(); if (npcFangZhenScript != null) { NpcScriptSt = NpcScriptState.XKFangZhen; } } } switch (NpcScriptSt) { case NpcScriptState.XKNpcMove: npcObj = SpawnNpcByNpcPrefab(npcPrefab); break; case NpcScriptState.XKDaPao: npcObj = SpawnNpcByNpcPrefab(npcPrefab); break; case NpcScriptState.XKHuoChe: npcObj = SpawnNpcByNpcPrefab(npcPrefab); break; case NpcScriptState.XKFangZhen: npcObj = SpawnNpcByNpcPrefab(npcPrefab); break; } } return(npcObj); }
/// <summary> /// 清理暂时不用的npc数据. /// </summary> public void ClearNpcObj() { int max = NpcList.Count; int indexNpc = 0; GameObject[] npcArray = new GameObject[max]; XKNpcMoveCtrl npcMoveScript = null; XKDaPaoCtrl npcDaPaoScript = null; string npcName = "noRemovedNpc"; if (max > 0) { for (int i = 0; i < max; i++) { //统计暂时不用的npc. if (NpcList[i] != null) { switch (NpcScriptSt) { case NpcScriptState.XKNpcMove: npcMoveScript = NpcList[i].GetComponent <XKNpcMoveCtrl>(); if (npcMoveScript != null && npcMoveScript.GetIsDeathNPC()) { if (indexNpc == 0) { npcName = NpcList[i].name; } npcArray[indexNpc] = NpcList[i]; indexNpc++; } break; case NpcScriptState.XKDaPao: npcDaPaoScript = NpcList[i].GetComponent <XKDaPaoCtrl>(); if (npcDaPaoScript != null && npcDaPaoScript.GetIsDeathNpc()) { if (indexNpc == 0) { npcName = NpcList[i].name; } npcArray[indexNpc] = NpcList[i]; indexNpc++; } break; } } } for (int i = 0; i < indexNpc; i++) { if (npcArray[i] != null) { if (NpcList.Contains(npcArray[i])) { //清理列表. NpcList.Remove(npcArray[i]); } } } for (int i = 0; i < indexNpc; i++) { if (npcArray[i] != null) { //删除暂时不用的npc. Destroy(npcArray[i]); } } Debug.Log("Unity: ClearNpcObj -> max == " + max + ", NpcScriptSt == " + NpcScriptSt + ", npcName == " + npcName + ", cleanCount == " + indexNpc); } }