コード例 #1
0
    private void SpawnRandomGroup()
    {
        if (pendingSpawns.Count == 0)
        {
            Debug.Assert(false, "Ran out of spawns");
            return;
        }
        int iPick = Random.Range(0, pendingSpawns.Count);

        MinionTemplate template = pendingSpawns [iPick];

        pendingSpawns.RemoveAt(iPick);

        Vector3 spawnPos = GetBestSpawnPoint();

        {
            // Create new game object
            GameObject go = new GameObject("EnemyMinion_" + template.name);

            // Create a minion and attach it to the actor's game object. Enemy minions are less permanent data structures than player ones, so they can just be chucked into the battlefield
            MinionTemplateManager mtm = Core.GetMinionTemplateManager();
            Minion minion             = mtm.CreateMinion(template);
            minion.transform.SetParent(go.transform);
            minion.transform.localPosition = Vector3.zero;

            // Fill it with actor components
            Actor_Enemy actor = go.AddComponent <Actor_Enemy>();
            actor.InitFromMinion(minion);
            actor.iWave = iCurrentWave;
            aiNumSpawnedPerWave [iCurrentWave]++;
            Vector2 randomOffset = Random.insideUnitCircle * Random.Range(0.0f, 0.5f);
            actor.transform.position = spawnPos + new Vector3(randomOffset.x, 0.0f, randomOffset.y);
            // Push the next member of the group back a bit
            spawnPos = new Vector3(spawnPos.x + 1.0f, spawnPos.y, spawnPos.z);

            // Add renderer to actor
            RenderActor render = Instantiate <RenderActor>(template.render);
            render.transform.SetParent(actor.transform);
            render.transform.localPosition = Vector3.zero;
            render.Init(actor);
            actor.render = render;

            // Add audio sources
            actor.soundEffect                       = go.AddComponent <AudioSource>();
            actor.soundEffect.clip                  = minion.template.soundEffect;
            actor.soundEffect.playOnAwake           = false;
            actor.soundEffect.outputAudioMixerGroup = Core.GetAudioManager().soundEffectGroup;

            // Add healthbar
            Healthbar healthbar = Instantiate <Healthbar>(mtm.healthbarPrefab);
            healthbar.transform.SetParent(actor.transform);
            healthbar.transform.localPosition = new Vector3(0.0f, template.fHeight - 1.0f, 0.0f);
            actor.healthbar = healthbar;

            actor.CalculateMyAggregateBuffs();

            // Store a reference for later
            enemyActors.Add(actor);
        }
    }