/// <summary> /// 获取npc预制. /// </summary> GameObject GetNpcPrefab(NpcState type, SpawnPointState pointState) { GameObject[] npcPrefabGp = null; switch (type) { case NpcState.ZhanChe: { if (pointState == SpawnPointState.Left) { npcPrefabGp = m_NpcData.L_ZhanChePrefabGp; } else if (pointState == SpawnPointState.Right) { npcPrefabGp = m_NpcData.R_ZhanChePrefabGp; } else if (pointState == SpawnPointState.Up) { npcPrefabGp = m_NpcData.U_ZhanChePrefabGp; } else if (pointState == SpawnPointState.Down) { npcPrefabGp = m_NpcData.D_ZhanChePrefabGp; } break; } case NpcState.JPBoss: { npcPrefabGp = m_NpcData.JPBossPrefabGp; break; } case NpcState.SuperJPBoss: { npcPrefabGp = m_NpcData.SuperJPBossPrefabGp; break; } } if (npcPrefabGp == null || npcPrefabGp.Length <= 0) { Debug.LogWarning("Unity: not find npc! type ================ " + type); return(null); } GameObject npcPrefab = null; int rv = Random.Range(0, 100) % npcPrefabGp.Length; npcPrefab = npcPrefabGp[rv]; if (npcPrefab == null) { Debug.LogWarning("Unity: npcPrefab was null! rv ============ " + rv + ", type == " + type); } return(npcPrefab); }
private void OnTriggerEnter(Collider _collider) { if (detectionState != SpawnPointState.Disable) { return; } if (_collider.GetComponent <TDS_Player>()) { detectionState = SpawnPointState.Enable; isFirstWave = true; OnNextWave?.Invoke(); } }
public SpawnPoint(int theID, int triggerType = 0) { ID = theID; switch (triggerType) { case (int)SpawnPointType.step: state = SpawnPointState.inactive; break; case (int)SpawnPointType.start: state = SpawnPointState.activeWhenStart; break; } }
public SpawnPoint(int theID, int triggerType = 0) { ID = theID; switch (triggerType) { case (int)SpawnPointType.step: state = SpawnPointState.inactive; break; case (int)SpawnPointType.start: state = SpawnPointState.activeWhenStart; break; } }
IEnumerator SpawnItem() { state = SpawnPointState.SPAWNING; int randomItemIndex = Random.Range(0, 3); ItemController itemController = (ItemController)Instantiate(GameController.instance.itemPrefab, new Vector2(0f, 0f), Quaternion.identity).GetComponent <ItemController>(); ItemController.Type itemType = (ItemController.Type)randomItemIndex; itemController.transform.SetParent(this.transform, false); itemController.Init(itemType); state = SpawnPointState.WAITING; yield break; }
NpcSpawnData GetNpcSpawnData(NpcState npcType, SpawnPointState pointState) { if (pointState == SpawnPointState.Null) { //不产生战车、JPBoss和SuperJPBoss. return(null); } NpcSpawnData data = new NpcSpawnData(); //获取ncp预制. data.NpcPrefab = GetNpcPrefab(npcType, pointState); SSCreatNpcData creatNpcDt = GetCreatNpcData(npcType, pointState); if (creatNpcDt != null) { //获取npc路径. data.NpcPath = creatNpcDt.GetNpcPahtData(); //获取产生点组件. data.SpawnPoint = creatNpcDt.m_SpawnPoint; } return(data); }
/// <summary> /// 获取创建npc的组件. /// </summary> SSCreatNpcData GetCreatNpcData(NpcState npcType, SpawnPointState type) { SSCreatNpcData[] comGp = null; switch (type) { case SpawnPointState.Left: { if (npcType == NpcState.ZhanChe) { comGp = m_NpcData.LeftSpawnPointGp; } else { comGp = m_NpcData.Boss_LeftSpawnPointGp; } break; } case SpawnPointState.Right: { if (npcType == NpcState.ZhanChe) { comGp = m_NpcData.RightSpawnPointGp; } else { comGp = m_NpcData.Boss_RightSpawnPointGp; } break; } case SpawnPointState.Up: { if (npcType == NpcState.ZhanChe) { comGp = m_NpcData.UpSpawnPointGp; } else { comGp = m_NpcData.Boss_UpSpawnPointGp; } break; } case SpawnPointState.Down: { if (npcType == NpcState.ZhanChe) { comGp = m_NpcData.DownSpawnPointGp; } else { comGp = m_NpcData.Boss_DownSpawnPointGp; } break; } } if (comGp == null || comGp.Length <= 0) { Debug.LogWarning("Unity: not find CreatNpcData! type ================ " + type + ", npcType == " + npcType); return(null); } SSCreatNpcData com = null; int rv = Random.Range(0, 100) % comGp.Length; com = comGp[rv]; if (com == null) { Debug.LogWarning("Unity: com was null! rv ============ " + rv + ", type == " + type); } return(com); }
/// <summary> /// 创建npc. /// npcType 产生的npc类型. /// pointState 产生点的方位信息. /// </summary> void CreatNpcObj(NpcState npcType, SpawnPointState pointState) { //Debug.Log("Unity: CreatNpcObj -> npcType ====== " + npcType + ", pointState ======= " + pointState); if (pointState == SpawnPointState.Null) { //pointState为null时不用产生战车npc. return; } NpcSpawnData data = GetNpcSpawnData(npcType, pointState); if (data != null) { GameObject obj = data.CreatPointNpc(); if (obj != null) { XKNpcMoveCtrl npcMove = null; switch (npcType) { case NpcState.ZhanChe: { if (XkGameCtrl.GetInstance() != null && XkGameCtrl.GetInstance().m_AiPathGroup != null && XkGameCtrl.GetInstance().m_AiPathGroup.m_CameraMoveType != AiPathGroupCtrl.MoveState.YuLe) { XkGameCtrl.GetInstance().m_AiPathGroup.SetCameraMoveType(AiPathGroupCtrl.MoveState.Default); } m_ZhanCheJPBossData.ZhanCheData.AddNpcToList(obj); break; } case NpcState.JPBoss: { if (XkGameCtrl.GetInstance() != null && XkGameCtrl.GetInstance().m_AiPathGroup != null && XkGameCtrl.GetInstance().m_AiPathGroup.m_CameraMoveType != AiPathGroupCtrl.MoveState.YuLe) { XkGameCtrl.GetInstance().m_AiPathGroup.SetCameraMoveType(AiPathGroupCtrl.MoveState.Boss); } m_ZhanCheJPBossData.JPBossData.AddNpcToList(obj); npcMove = obj.GetComponent <XKNpcMoveCtrl>(); if (npcMove != null) { switch (pointState) { case SpawnPointState.Up: { npcMove.m_TriggerDir = SSTriggerCaiPiaoBossMove.TriggerDir.Qian; break; } case SpawnPointState.Down: { npcMove.m_TriggerDir = SSTriggerCaiPiaoBossMove.TriggerDir.Hou; break; } case SpawnPointState.Left: { npcMove.m_TriggerDir = SSTriggerCaiPiaoBossMove.TriggerDir.Zuo; break; } case SpawnPointState.Right: { npcMove.m_TriggerDir = SSTriggerCaiPiaoBossMove.TriggerDir.You; break; } } } if (XKBossLXCtrl.GetInstance() != null) { //播放boss来袭UI. XKBossLXCtrl.GetInstance().StartPlayBossLaiXi(); AudioBeiJingCtrl.StopGameBeiJingAudio(); } break; } case NpcState.SuperJPBoss: { if (XkGameCtrl.GetInstance() != null && XkGameCtrl.GetInstance().m_AiPathGroup != null && XkGameCtrl.GetInstance().m_AiPathGroup.m_CameraMoveType != AiPathGroupCtrl.MoveState.YuLe) { XkGameCtrl.GetInstance().m_AiPathGroup.SetCameraMoveType(AiPathGroupCtrl.MoveState.Boss); } m_ZhanCheJPBossData.SuperJPBossData.AddNpcToList(obj); npcMove = obj.GetComponent <XKNpcMoveCtrl>(); if (npcMove != null) { switch (pointState) { case SpawnPointState.Up: { npcMove.m_TriggerDir = SSTriggerCaiPiaoBossMove.TriggerDir.Qian; break; } case SpawnPointState.Down: { npcMove.m_TriggerDir = SSTriggerCaiPiaoBossMove.TriggerDir.Hou; break; } case SpawnPointState.Left: { npcMove.m_TriggerDir = SSTriggerCaiPiaoBossMove.TriggerDir.Zuo; break; } case SpawnPointState.Right: { npcMove.m_TriggerDir = SSTriggerCaiPiaoBossMove.TriggerDir.You; break; } } } if (XKBossLXCtrl.GetInstance() != null) { //播放boss来袭UI. XKBossLXCtrl.GetInstance().StartPlayBossLaiXi(); AudioBeiJingCtrl.StopGameBeiJingAudio(); } break; } } } } }
/// <summary> /// 获取战车、JPBoss和SuperJPBoss的产生点方位. /// </summary> public SpawnPointState GetSpawnPointState() { if (!IsOpenLeft && !IsOpenRight && !IsOpenUp && !IsOpenDown) { return(SpawnPointState.Null); } SpawnPointState type = SpawnPointState.Null; int rv = 0; int count = 0; bool isFindPointState = false; do { count++; for (int i = 0; i < 4; i++) { if (count >= 3) { //超过3次检索就不再随机了. rv = 1; } else { rv = Random.Range(0, 100) % 2; } switch (i) { case 0: { if (IsOpenLeft && rv == 1) { type = SpawnPointState.Left; isFindPointState = true; } break; } case 1: { if (IsOpenRight && rv == 1) { type = SpawnPointState.Right; isFindPointState = true; } break; } case 2: { if (IsOpenUp && rv == 1) { type = SpawnPointState.Up; isFindPointState = true; } break; } case 3: { if (IsOpenDown && rv == 1) { type = SpawnPointState.Down; isFindPointState = true; } break; } } if (isFindPointState) { break; } } } while (!isFindPointState); return(type); }
void ItemPicked() { state = SpawnPointState.COUNTING; spawnCountdown = timeBetweenSpawns; }
public SpawnPoint() { state = SpawnPointState.inactive; }
public SpawnPoint() { state = SpawnPointState.inactive; }