Beispiel #1
0
    public void DespawnObject(SpawnableObject obj)
    {
        switch (obj.RespawnType)
        {
        case RespawnType.DESTROY_ON_DESPAWN:
            // Debug.LogError("Destroying obj " + obj.gameObject.name + " due to RespawnType.DESTROY_ON_DESPAWN");
            ObjectPool.Remove(obj);
            Destroy(obj.gameObject);
            break;

        case RespawnType.RESPAWN_AFTER_TIME:
            //     Debug.LogError("Deactivating obj " + obj.gameObject.name + " due to RespawnType.RESPAWN");
            obj.SetRespawnTime();
            obj.gameObject.SetActive(false);
            break;

        case RespawnType.INSTANT_RESPAWN:
            //   Debug.LogError("Respawning obj " + obj.gameObject.name + " due to RespawnType.INSTANT_RESPAWN");
            RespawnObject(obj);
            break;
        }
    }
Beispiel #2
0
    public void Initialize() // Called by GameSceneManager
    {
        Debug.LogError("Initializing SpawnManager...");

        if (PredefinedPositions.Count <= 1)
        {
            Debug.LogError("IMPORTANT: SpawnManager needs more Predefined Positions!");
            return;
        }

        Debug.LogError("Spawning dynamic prefabs");
        var watch = System.Diagnostics.Stopwatch.StartNew();

        foreach (SpawnableObject prefab in SpawnablePrefabs)
        {
            if (prefab.SpawnType == SpawnType.MANUAL_PLACEMENT)
            {
                continue;
            }

            for (int i = 0; i < prefab.MaxInstances; i++)
            {
                SpawnableObject n = null;

                switch (prefab.SpawnType)
                {
                case SpawnType.RANDOM_PREDEFINED_POSITION:
                    n = Instantiate(prefab, GetRandomPredefinedPosition(), Quaternion.identity);
                    break;

                case SpawnType.RANDOM_MAP_POSITION:
                    n = Instantiate(prefab, GetRandomMapPosition(), Quaternion.identity);
                    break;

                case SpawnType.PLAYER_FORWARD:
                    n = Instantiate(prefab);
                    break;
                }

                if (n.AddRespawnTimeOnStart)
                {
                    n.SetRespawnTime();
                }
                if (n.ShouldStartInactive)
                {
                    n.gameObject.SetActive(false);
                }

                if (n != null)
                {
                    ObjectPool.Add(n);
                }
            }
        }
        watch.Stop();
        var elapsedMs = watch.ElapsedMilliseconds;

        Debug.LogError("Spawning dynamic prefabs took " + elapsedMs + " ms");

        // Spawn Invaders
        Queue <Transform> q = new Queue <Transform>(InvaderSpawnPoints);

        for (int i = 0; i < RemoteSettings.Instance.MAX_INVADERS; i++)
        {
            var s = q.Dequeue();
            InvaderController b = Instantiate(InvaderPrefab, s.position, Quaternion.identity);
            GameSceneManager.Instance.GameState.Invaders.Add(b);
            GameSceneManager.Instance.GameState.CurrentAliveInvaders++;
            GameUIController.Instance.RegisterInvader(b);
            q.Enqueue(s);
        }

        // Spawn player
        GameSceneManager.Instance.GameState.Player = Instantiate(PlayerPrefab, PlayerSpawnPoint.position, Quaternion.identity);

        // Initialize invaders target
        foreach (InvaderController i in GameSceneManager.Instance.GameState.Invaders)
        {
            i.target = GameSceneManager.Instance.GameState.Player.transform;
        }

        // Start update interval

        InvokeRepeating("UpdateInterval", UpdateRate, UpdateRate);

        Debug.LogError("SpawnManager is ready");
    }