private bool CanSpawn(AISpawnData data) { if (data.m_AI != null) { return(false); } if (data.m_TimeToNextSpawn > 0f) { return(false); } float num = Vector3.Distance(Player.Get().transform.position, data.m_Position); return(num <= this.m_MaxDistance && num >= this.m_MinDistance); }
public void OnDestroyAI(AI ai) { if (this.m_SpawnersGroup) { this.m_SpawnersGroup.OnDestroyAI(ai); } for (int i = 0; i < this.m_AIDatas.Count; i++) { AISpawnData aispawnData = this.m_AIDatas[i]; if (aispawnData.m_AI == ai) { aispawnData.m_AI = null; aispawnData.m_TimeToNextSpawn = ((!ai.IsDead()) ? 0f : this.m_ResetTime); break; } } this.m_AICount--; }
private void Start() { BoxCollider component = base.gameObject.GetComponent <BoxCollider>(); Vector3 size = component.size; this.m_MinDistance = AIManager.Get().m_AIActivationRange * 0.7f; this.m_MaxDistance = AIManager.Get().m_AIActivationRange * 0.9f; int num = Mathf.Max(this.m_DayCount, this.m_NightCount); for (int i = 0; i < num; i++) { AISpawnData aispawnData = new AISpawnData(); aispawnData.m_Position = this.GetSpawnPosition(); if (aispawnData.m_Position != Vector3.zero) { this.m_AIDatas.Add(aispawnData); } } AIManager.Get().RegisterSpawner(this); }
private void SpawnObject(AISpawnData data) { Quaternion rotation = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(-180, 180), 0f); GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.m_Prefab, data.m_Position, rotation); gameObject.name = string.Format("{0} {1}", this.m_Prefab.name, base.transform.childCount); Vector3 vector = gameObject.transform.localScale; vector *= UnityEngine.Random.Range(this.m_MinScale, this.m_MaxScale); gameObject.transform.localScale = vector; AI component = gameObject.GetComponent <AI>(); component.m_Spawner = this; data.m_AI = component; if (this.m_SpawnersGroup) { this.m_SpawnersGroup.OnSpawnAI(component); } this.m_AICount++; }