Exemple #1
0
    public void LoadScene()
    {
        GameObject checkpoint = null;

        switch (Application.loadedLevelName)
        {
        case "JumpArena":
        case "Platforms And Enemies":
            _orderedSceneCheckpoints = new List <Checkpoint>(GameObject.FindObjectsOfType <Checkpoint>());
            _orderedSceneCheckpoints.Sort((a, b) => b.index.CompareTo(a.index));

            _currentCheckpointIndex = 0;
            checkpoint = _orderedSceneCheckpoints[_currentCheckpointIndex].gameObject;
            break;

        default:
            // TODO (Roman): don't hardcode tags
            _orderedSceneCheckpoints = new List <Checkpoint>(GameObject.FindObjectsOfType <Checkpoint>());
            _orderedSceneCheckpoints.Sort((a, b) => a.index.CompareTo(b.index));

            _currentCheckpointIndex = 0;
            checkpoint = _orderedSceneCheckpoints[_currentCheckpointIndex].gameObject;
            break;
        }

        #region object pool maintenance
        ObjectPoolingManager objectPoolingManager = ObjectPoolingManager.Instance;

        // TODO (Roman): some logging

        objectPoolingManager.DeactivateAndClearAll();

        objectPoolingManager.RegisterPool(gameSettings.pooledObjects.basicPowerUpPrefab.prefab, gameSettings.pooledObjects.basicPowerUpPrefab.initialSize, int.MaxValue);
        objectPoolingManager.RegisterPool(gameSettings.pooledObjects.basicBullet.prefab, gameSettings.pooledObjects.basicBullet.initialSize, int.MaxValue);
        objectPoolingManager.RegisterPool(gameSettings.pooledObjects.defaultEnemyDeathParticlePrefab.prefab, gameSettings.pooledObjects.defaultEnemyDeathParticlePrefab.initialSize, int.MaxValue);
        objectPoolingManager.RegisterPool(gameSettings.pooledObjects.defaultPlayerDeathParticlePrefab.prefab, gameSettings.pooledObjects.defaultPlayerDeathParticlePrefab.initialSize, int.MaxValue);

        MonoBehaviour[] monoBehaviours = GameObject.FindObjectsOfType <MonoBehaviour>();
        Dictionary <string, ObjectPoolRegistrationInfo> gameObjectTypes = new Dictionary <string, ObjectPoolRegistrationInfo>();
        for (int i = 0; i < monoBehaviours.Length; i++)
        {
            IObjectPoolBehaviour objectPoolBehaviour = monoBehaviours[i] as IObjectPoolBehaviour;
            if (objectPoolBehaviour != null)
            {
                foreach (ObjectPoolRegistrationInfo objectPoolRegistrationInfo in objectPoolBehaviour.GetObjectPoolRegistrationInfos())
                {
                    if (gameObjectTypes.ContainsKey(objectPoolRegistrationInfo.gameObject.name))
                    {
                        if (gameObjectTypes[objectPoolRegistrationInfo.gameObject.name].totalInstances < objectPoolRegistrationInfo.totalInstances)
                        {
                            gameObjectTypes[objectPoolRegistrationInfo.gameObject.name] = objectPoolRegistrationInfo.Clone();
                        }
                    }
                    else
                    {
                        gameObjectTypes[objectPoolRegistrationInfo.gameObject.name] = objectPoolRegistrationInfo.Clone();
                    }
                }
            }
        }

        Logger.Info("Registering " + gameObjectTypes.Count + " objects at object pool.");
        foreach (ObjectPoolRegistrationInfo objectPoolRegistrationInfo in gameObjectTypes.Values)
        {
            objectPoolingManager.RegisterPool(objectPoolRegistrationInfo.gameObject, objectPoolRegistrationInfo.totalInstances, int.MaxValue);
        }
        #endregion

        PlayerController playerController = Instantiate(GameManager.instance.player, checkpoint.transform.position, Quaternion.identity) as PlayerController;

        playerController.spawnLocation = checkpoint.transform.position;

        this.player = playerController;
#if !FINAL
        _sceneStartTime = Time.time;
#endif
    }