IEnumerator CreateEnemy(SpwanPointEnemy point, E_EnemyType enemyType = E_EnemyType.None, RoundInfo.SpawnInfo spawnInfo = null) { if (enemyType == E_EnemyType.None) { enemyType = point.EnemyType; } //从缓存获取怪物 //GameObject prefab = Resources.Load<GameObject> ("Prefabs/Monster"); //Agent enemy = GameObject.Instantiate (prefab).GetComponent<Agent> (); Agent enemy = MissionZone.Instance.GetHuman(enemyType, point.transform); while (enemy == null) { yield return(new WaitForSeconds(0.5f)); enemy = MissionZone.Instance.GetHuman(enemyType, point.transform); } enemy.PrepareForStart(); CombatEffectsManager.Instance.PlaySpawnEffect(point.Transform.position, point.Transform.forward); MyGameZone.AddEnemy(enemy); EnemiesAlive.Add(enemy); if (spawnInfo != null && spawnInfo.WhenKilledStopSpawn) { ImportantAgent = enemy; } yield return(new WaitForSeconds(0.1f)); }
public GameObject GetHuman(E_EnemyType Type, Transform t) { int l = HumansCache.Length; GameObject g; for (int i = 0; i < l; i++) { if (HumansCache[i].EnemyType == Type) { g = HumansCache[i].Get(); if (g != null) { g.SendMessage("Activate", t); if (Type == E_EnemyType.MiniBoss01) { SpriteEffectsManager.Instance.CreateShadow(g, 1.5f, 1.5f); } else if (Type == E_EnemyType.BossOrochi) { SpriteEffectsManager.Instance.CreateShadow(g, 4, 4); } else { SpriteEffectsManager.Instance.CreateShadow(g, 1, 1); } } return(g); } } return(null); }
Agent CreateEnemy(SpwanPointEnemy point, E_EnemyType enemyType = E_EnemyType.None) { if (enemyType == E_EnemyType.None) { enemyType = point.EnemyType; } GameObject prefab = Resources.Load <GameObject>("Prefabs/Monster"); Agent enemy = GameObject.Instantiate(prefab).GetComponent <Agent>(); if (enemy != null) { enemy.transform.position = point.transform.position; } return(enemy); }
/// <summary> /// Gets the human. /// 获取怪物对象 /// </summary> /// <returns>The human.</returns> /// <param name="enemyType">Enemy type.</param> /// <param name="tran">Tran.</param> public Agent GetHuman(E_EnemyType enemyType, Transform tran) { int len = HumanCaches.Length; GameObject go; for (int i = 0; i < len; i++) { if (HumanCaches[i].EnemyType == enemyType) { go = HumanCaches[i].Get(); if (go != null) { //初始化相关 Agent a = go.GetComponent <Agent>(); a.Enable(); //设置位置 a.SetPosition(tran); //设置阴影 return(a); } } } return(null); }
public Agent GetNearestAliveEnemy(Vector3 center, float radius, Agent ignoreAgent, E_EnemyType enemyType) { float len; float nearestLen = radius * radius; Agent best = null; for (int i = 0; i < _Enemies.Count; i++) { Agent e = _Enemies[i]; if (e == ignoreAgent) { continue; } if (e.EnemyType != enemyType) { continue; } // Debug.Log("testing enemy " + e.name + " : " + e.Position.ToString()); if (e.IsAlive == false) { continue; } if (e.IsVisible == false) { continue; } len = (center - e.Position).sqrMagnitude; // Debug.Log("Distance is " + len.ToString()); if (len < nearestLen) { //if (ignoreAgent.debugGOAP) Debug.DrawLine(ignoreAgent.Position, e.Position); nearestLen = len; best = e; } } return(best); }
// 根据不同的怪物类型来生成对应的怪物 private Agent GenerateEnemyOnType(E_EnemyType type, Transform t) { switch (type) { case E_EnemyType.SwordsMan: { Agent prefabEnemy = Resources.Load <Agent>("Prefabs/Enemy/EnemySwordsman"); Agent enemy = Instantiate(prefabEnemy, t.position, t.rotation) as Agent; return(enemy); break; } case E_EnemyType.Peasant: { Agent prefabEnemy = Resources.Load <Agent>("Prefabs/Enemy/EnemyPeasant"); Agent enemy = Instantiate(prefabEnemy, t.position, t.rotation) as Agent; return(enemy); break; } case E_EnemyType.TwoSwordsMan: { Agent prefabEnemy = Resources.Load <Agent>("Prefabs/Enemy/EnemyDoubleSwordsman"); Agent enemy = Instantiate(prefabEnemy, t.position, t.rotation) as Agent; return(enemy); break; } case E_EnemyType.Bowman: { Agent prefabEnemy = Resources.Load <Agent>("Prefabs/Enemy/EnemyBowman"); Agent enemy = Instantiate(prefabEnemy, t.position, t.rotation) as Agent; return(enemy); break; } case E_EnemyType.PeasantLow: { Agent prefabEnemy = Resources.Load <Agent>("Prefabs/Enemy/EnemyPeasantEasy"); Agent enemy = Instantiate(prefabEnemy, t.position, t.rotation) as Agent; return(enemy); break; } case E_EnemyType.MiniBoss01: { Agent prefabEnemy = Resources.Load <Agent>("Prefabs/Enemy/EnemyMiniBoss"); Agent enemy = Instantiate(prefabEnemy, t.position, t.rotation) as Agent; return(enemy); break; } case E_EnemyType.SwordsManLow: { Agent prefabEnemy = Resources.Load <Agent>("Prefabs/Enemy/EnemySwordsmanEasy"); Agent enemy = Instantiate(prefabEnemy, t.position, t.rotation) as Agent; return(enemy); break; } case E_EnemyType.BossOrochi: { Agent prefabEnemy = Resources.Load <Agent>("Prefabs/Enemy/EnemyBossOrochi"); Agent enemy = Instantiate(prefabEnemy, t.position, t.rotation) as Agent; return(enemy); break; } default: { Agent prefabEnemy = Resources.Load <Agent>("Prefabs/Enemy/EnemyPeasantEasy"); Agent enemy = Instantiate(prefabEnemy, t.position, t.rotation) as Agent; return(enemy); break; } } }
/// <summary> /// 获取指定范围内指定类型的怪物 /// </summary> /// <param name="center">指定的中心</param> /// <param name="radius">范围半径</param> /// <param name="enemyType">怪物类型</param> /// <returns></returns> public Agent GetNearestAliveEnemy(Vector3 center, float radius, E_EnemyType enemyType) { return(null); }