Exemple #1
0
        private void Start()
        {
            //reset current level
            mCurrentLevel = 0;

            //get scene
            mScene = GetComponentInParent <SubScene>();

            //get current level from data
            Level currentLevel = mLevels[mCurrentLevel];

            //spawn a background for the game
            mCurrentBackground = ObjectPoolManager.Instance.Spawn(currentLevel.GetBackground().name,
                                                                  mScene.transform.position + new Vector3(0, 0, 10));

            //set it to be a child of scene
            mCurrentBackground.transform.parent = mScene.transform;

            //spawn a foreground for the game
            mCurrentForeground = ObjectPoolManager.Instance.Spawn(currentLevel.GetForeground().name,
                                                                  mScene.transform.position + new Vector3(0, -15.68f, 5),
                                                                  mScene.transform);

            //set it to be a child of scene
            mCurrentForeground.transform.parent = mScene.transform;

            mScene.GetServiceManager().CallActionWhenServiceIsLive(ApplicationConstants.SERVICE_LOCAL_LEVEL_BUILDER,
                                                                   () => { SetConfigurationInBuilder(currentLevel); });

            //mScene.GetEventManager().ListenToEvent(ApplicationConstants.BUILDER_IS_INITIALIZED, (string arg1, ActionParams arg2) => {
            //    SetConfigurationInBuilder(currentLevel);
            //});

            //mScene.GetEventManager().

            mScene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_CHANGE_TO_NEXT_WORLD, ChangeToNextLevel);
        }
Exemple #2
0
        void ChangeToNextLevel(string eventName, ActionParams actionParams)
        {
            Debug.Log("ChangeToNextLevel()");

            //Save old values
            GameObject oldBackground = mCurrentBackground;
            GameObject oldForeground = mCurrentForeground;

            //move the current level by 1 with modulo
            mCurrentLevel++;
            mCurrentLevel = mCurrentLevel % mLevels.Length;

            Level level = mLevels[mCurrentLevel];

            GameObject backgroundPrefab = level.GetBackground();

            if (backgroundPrefab == null)
            {
                Debug.Log("background prefab cannot be null");
            }
            //TODO FIX
            //Create the prefab in the correct place
            //ObjectPoolManager.Instance.Spawn();
            mCurrentBackground = ObjectPoolManager.Instance.Spawn(backgroundPrefab.name, mScene.transform.position +
                                                                  new Vector3(oldBackground.GetComponentInChildren <Renderer>().bounds.size.x, 0, 10));

            mCurrentBackground.transform.parent = mScene.transform;

            //move the cuurent bg prefab away
            mCurrentBackground.transform.DOMoveX(mCurrentBackground.transform.position.x -
                                                 oldBackground.GetComponentInChildren <Renderer>().bounds.size.x, 3);

            //move the new prefab into the scene
            oldBackground.transform.DOMoveX(oldBackground.transform.position.x -
                                            oldBackground.GetComponentInChildren <Renderer>().bounds.size.x, 3)
            .OnComplete(() => {
                ObjectPoolManager.Instance.Destroy(oldBackground.name, oldBackground);
            });


            GameObject foregroundPrefab = level.GetForeground();

            if (foregroundPrefab == null)
            {
                Debug.Log("Foreground prefab cannot be null");
            }

            //Spawn a new foreground
            mCurrentForeground = ObjectPoolManager.Instance.Spawn(foregroundPrefab.name, mScene.transform.position +
                                                                  new Vector3(oldForeground.GetComponentInChildren <Renderer>().bounds.size.x, -15.68f, 5), mScene.transform);

            //set it as child of scene
            mCurrentForeground.transform.parent = mScene.transform;

            //move the cuurent fg prefab away
            mCurrentForeground.transform.DOMoveX(mCurrentForeground.transform.position.x -
                                                 oldForeground.GetComponentInChildren <Renderer>().bounds.size.x, 3);

            //move the new prefab into the scene
            oldForeground.transform.DOMoveX(oldForeground.transform.position.x -
                                            oldForeground.GetComponentInChildren <Renderer>().bounds.size.x, 3)
            .OnComplete(() => {
                ObjectPoolManager.Instance.Destroy(oldForeground.name, oldForeground);
            });

            SetConfigurationInBuilder(level);
        }