コード例 #1
0
        EnemyInfo FindInactiveEnemy(EnemyType type)
        {
            EnemyInfo enemyInfo = new EnemyInfo();

            enemyInfo.identifier = -1;
            foreach (EnemyInfo info in inactiveEnemy)
            {
                if (info.type == type)
                {
                    enemyInfo = info;
                    break;
                }
            }
            return(enemyInfo);
        }
コード例 #2
0
        public EnemyInfo CreateEnemy(EnemyType type, Vector3 position, Quaternion quaternion, bool active = true)
        {
            EnemyInfo enemyInfo = FindInactiveEnemy(type);

            if (enemyInfo.identifier > 0)
            {
                enemyInfo.identifier                  = GenerateIdentifier();
                enemyInfo.type                        = type;
                enemyInfo.difficultyLevel             = GetDifficulty(type);
                enemyInfo.instance.transform.position = position;
                enemyInfo.instance.transform.rotation = quaternion;
                enemyInfo.instance.SetActive(true);
            }
            else
            {
                enemyInfo.identifier      = GenerateIdentifier();
                enemyInfo.type            = type;
                enemyInfo.difficultyLevel = GetDifficulty(type);

                if (!enemyPrefabs.ContainsKey(type))
                {
                    GameObject prefab = Resources.Load(GetPrefabPath(type)) as GameObject;
                    enemyPrefabs.Add(type, prefab);
                }

                enemyInfo.instance = Instantiate(enemyPrefabs[type], position, quaternion);
                if (active)
                {
                    activeEnemy.Add(enemyInfo);
                }
                else
                {
                    inactiveEnemy.Add(enemyInfo);
                }
            }

            return(enemyInfo);
        }