protected virtual IEnumerator DeathCoroutine() { CNpcUnit unit = m_unit as CNpcUnit; if (unit == null) { Destroy(gameObject); yield break; } NavMeshAgent agent = GetComponent <NavMeshAgent>(); if (agent != null) { agent.isStopped = true; agent.SetDestination(transform.position); yield return(null); } if (unit.UnitData != null && unit.UnitData.PutItems != null) { GameObject putItemGo = CObjectPool.Inst.GetItem(); putItemGo.transform.position = transform.position; putItemGo.transform.rotation = Quaternion.identity; putItemGo.SetActive(true); CPutItem putItem = putItemGo.GetComponent <CPutItem>(); if (putItem != null) { CItemBase item = null; if (unit.UnitData.PutItems.Count > 0) { int nIdx = Random.Range(0, unit.UnitData.PutItems.Count); item = unit.UnitData.PutItems[nIdx]; } if (item != null) { putItem.SetItemData(item); } } } yield return(null); m_isDeathStart = true; yield return(new WaitForSeconds(m_fDeathWait)); m_unit.StayLevel = null; if (m_unit.SpawnedPoint != null) { m_unit.SpawnedPoint.RemoveUnitFromList(m_unit); } m_unit.SpawnedPoint = null; CObjectPool.Inst.PooledObject(gameObject, unit.UnitData, unit.UnitData.UnitType, unit.UnitData.Index); yield return(null); }
IEnumerator SpawnCoroutine() { if (GameManager.Inst != null) { while (CObjectPool.Inst == null) { yield return(null); } while (!CObjectPool.Inst.IsInit) { yield return(null); } while (!GameManager.Inst.IsGameEnd) { yield return(null); if (m_spawnList.Count >= m_maxCount) { continue; } if (m_spawnBase != null) { yield return(new WaitForSeconds(m_spwanDelay)); GameObject unitObj = CObjectPool.Inst.GetUnit(m_spawnBase.UnitType, m_spawnBase.Index); if (unitObj == null) { continue; } //GameObject unitObj = Instantiate(m_spawnBase.UnitPrefab, transform.position, Quaternion.identity); CNpcUnit unit = unitObj.GetComponent <CNpcUnit>(); if (unit == null) { Debug.LogError(m_spawnBase + "not contained unit component"); break; } m_spawnList.Add(unit); unitObj.transform.position = transform.position; unitObj.transform.rotation = Quaternion.identity; unitObj.SetActive(true); unit.ResetUnit(); yield return(null); unit.StayLevel = m_subLevel; unit.SpawnedPoint = this; if (m_ways.Count < 1) { continue; } int nIdx = Random.Range(0, m_ways.Count); unit.Movement.MoveWays = m_ways[nIdx].wayList; yield return(null); } } } yield return(null); }
protected virtual bool MoveTargetCheck() { if (m_moveWays == null) { return(false); } if (m_moveWays.Count < 1) { return(false); } if (m_moveTarget == null) { m_moveTarget = m_moveWays[0]; CurMoveWayIdx = 0; CurScareWayIdx = 0; } m_actCtrl.MoveAmount = 0f; if (m_moveTarget == null) { return(false); } MoveDir = m_moveTarget.position - transform.position; MoveDir = MoveDir.normalized; m_actCtrl.MoveAmount = MoveDir.magnitude; if (m_unit.Status.CurState == State.Normal) { m_navAgent.isStopped = false; m_navAgent.speed = m_unit.Status.BaseStst.moveSpeed; if (Vector3.Distance(transform.position, m_moveTarget.position) <= 0.5f) { if (!m_switch) { CurMoveWayIdx++; } else { CurMoveWayIdx--; } if (CurMoveWayIdx >= m_moveWays.Count) { m_actCtrl.MoveAmount = 0f; m_actCtrl.RestAction(); CurMoveWayIdx = m_moveWays.Count - 1; m_switch = true; } if (CurMoveWayIdx < 0) { m_actCtrl.MoveAmount = 0f; m_actCtrl.RestAction(); CurMoveWayIdx = 0; m_switch = false; } } m_moveTarget = m_moveWays[CurMoveWayIdx]; m_moveTargetPos = m_moveTarget.position; return(true); } else if (m_unit.Status.CurState == State.Scare) { m_navAgent.isStopped = false; m_navAgent.speed = m_unit.Status.BaseStst.moveSpeed * 2f; m_actCtrl.IsRun = true; if (m_moveState == MoveState.SCARE) { if (Vector3.Distance(transform.position, m_moveTarget.position) <= 1f) { CNpcUnit npc = m_unit as CNpcUnit; if (m_unit != null) { m_unit.StayLevel = null; if (m_unit.SpawnedPoint != null) { m_unit.SpawnedPoint.RemoveUnitFromList(m_unit); } m_unit.SpawnedPoint = null; } m_actCtrl.IsRun = false; CObjectPool.Inst.PooledObject(gameObject, npc.UnitData, npc.UnitData.UnitType, npc.UnitData.Index); return(false); } } else { if (m_unit == null || m_unit.StayLevel == null) { m_moveTarget = m_moveWays[CurMoveWayIdx]; } else { if (m_unit.StayLevel.ConnectLinks.Count > 0) { int nRand = Random.Range(0, m_unit.StayLevel.ConnectLinks.Count); m_moveTarget = m_unit.StayLevel.ConnectLinks[nRand].transform; m_moveTargetPos = m_moveTarget.position; } else { m_moveTarget = m_moveWays[CurMoveWayIdx]; m_moveTargetPos = m_moveTarget.position; } } m_moveState = MoveState.SCARE; return(true); } } return(false); }