private static IEnumerator InternalRunClient(QNetGameInitializerData data, Action onDone)
        {
            // activate loading screen
            OnClientLoadingInfoUpdated?.Invoke(true, "LOADING LEVEL", $"Loading {data.LevelName}");
            OnClientLoadingStart?.Invoke();

            yield return(new WaitForSeconds(0.6f)); // wait some time, lol

            var sw = Stopwatch.StartNew();

            // load world fist
            LastMapState = QNetMapState.Loading;
            OnMapStateChanged?.Invoke(QNetMapState.Loading);
            var isLevelLoading = true;

            QNetLevelLoader.Load(data.LevelName, () => { isLevelLoading = false; });
            while (isLevelLoading)
            {
                yield return(new WaitForEndOfFrame());
            }

            OnLevelLoaded?.Invoke(data.LevelName);
            yield return(new WaitForEndOfFrame());

            // update lading screen
            OnClientLoadingInfoUpdated?.Invoke(true, "LOADING WORLD", "Waiting for server.");

            GameIsInitializing = false;
            GameInitialized    = true;
            JEMLogger.Log($"QNetUnity ClientRun main work took {sw.Elapsed.Milliseconds:0.00}ms.");
            onDone?.Invoke();
        }
示例#2
0
    private void GenerateBricks()
    {
        this.RemainingBricks    = new List <Bloque>();
        int[,] currentLevelData = this.levelsData[this.CurrentLevel];
        float currentSpawnX = initialBrickSpawnPositionX;
        float currentSpawnY = initialBrickSpawnPositionY;
        float zShift        = 0;

        for (int row = 0; row < this.maxRows; row++)
        {
            for (int col = 0; col < this.maxCols; col++)
            {
                int brickType = currentLevelData[row, col];
                if (brickType > 0)
                {
                    Bloque nuevoBloque = Instantiate(brickPrefab, new Vector3(currentSpawnX, currentSpawnY, 0.0f - zShift), Quaternion.identity) as Bloque;
                    nuevoBloque.Init(bricksContainer.transform, this.sprites[brickType - 1], this.brickColors[brickType], brickType);

                    this.RemainingBricks.Add(nuevoBloque);
                    zShift += 0.0001f;
                }
                currentSpawnX += shiftAmount;
                if (col + 1 == this.maxCols)
                {
                    currentSpawnX = initialBrickSpawnPositionX;
                }
            }
            currentSpawnY -= shiftAmount;
        }

        this.InitialBrickCount = this.RemainingBricks.Count;
        OnLevelLoaded?.Invoke();
    }
示例#3
0
 void OnSceneLoaded(Scene scene, LoadSceneMode mode)
 {
     if (scene.name != "_MainMenu")
     {
         levelLoaded?.Invoke();
         cam.GetComponent <Camera>().backgroundColor = colours[currentScene];
         var colorOverLifetime = cam.GetChild(1).GetComponent <ParticleSystem>().colorOverLifetime;
         colorOverLifetime.color = colours[currentScene];
         particleMaterial.color  = colours[currentScene];
     }
     Analytics.CustomEvent("level_start", new Dictionary <string, object>
     {
         { "level_index", currentScene }
     });
 }
    private void OnLoadOperationComplete(AsyncOperation ao)
    {
        if (_loadOperations.Contains(ao))
        {
            _loadOperations.Remove(ao);

            if (_loadOperations.Count == 0)
            {
                UpdateState(GameState.RUNNING);
            }
        }

        OnLevelLoaded.Invoke();

        Debug.Log("Load Complete");
    }
示例#5
0
    private void GenerateBricks()
    {
        // Initialise brick collection
        this.RemainingBricks = new List <Brick>();
        // Get the current level
        int[,] currentLevelData = this.LevelsData[this.currentLevel];
        // Iterate over the level and instantiate bricks
        float currentSpawnX = initialBrickSpawnPositionX;   // Set the current spawn position for x
        float currentSpawnY = initialBrickSpawnPositionY;   // Set the current spawn position for y
        float zShift        = 0;

        // Iterate over the rows
        for (int row = 0; row < this.maxRows; row++)
        {
            // Iterate over the columns
            for (int col = 0; col < this.maxCols; col++)
            {
                int brickType = currentLevelData[row, col];

                if (brickType > 0)
                {
                    // Instantiate the brick
                    Brick newBrick = Instantiate(brickPrefab, new Vector3(currentSpawnX, currentSpawnY, 0.0f - zShift), Quaternion.identity) as Brick;
                    newBrick.Init(bricksContainer.transform, this.Sprites[brickType - 1], this.BrickColours[brickType], brickType);
                    // Add remaining bricks collection
                    this.RemainingBricks.Add(newBrick);
                    zShift += 0.0001f;
                }

                // Shift the brick x position for the next iteration
                currentSpawnX += shiftAmount;
                // Check if we have reached the end of the columns
                if (col + 1 == this.maxCols)
                {
                    // Reset the current spawn position for x
                    currentSpawnX = initialBrickSpawnPositionX;
                }
            }

            // Shift the brick y position for the next iteration
            currentSpawnY -= shiftAmount;
        }

        this.InitialBricksCount = this.RemainingBricks.Count;
        OnLevelLoaded?.Invoke();
    }
        public virtual LevelEditorSaveData LoadLevel(LevelEditorSaveData data)
        {
            LevelSavingLoadingArgs args = new LevelSavingLoadingArgs(data, loadLocation);

            loadLocation = null;
            OnLevelLoading?.Invoke(this, args);
            if (args.Cancel)
            {
                LevelEditorLogger.Log("LevelEditorSaveManager loading was canceled.");
                return(new LevelEditorSaveData(null));
            }

            realObjectManager.DeleteAllObjects();
            realObjectManager.CreateObjectsFromSaveData(data);

            OnLevelLoaded?.Invoke(this, new LevelEventArgs(data));

            return(data);
        }
示例#7
0
    private IEnumerator LoadLevelRoutine(SceneReference level)
    {
        var activeLevel = levels.FirstOrDefault(l => l.ScenePath == currentLevel?.ScenePath);

        if (activeLevel != null)
        {
            var unloading = SceneManager.UnloadSceneAsync(activeLevel);
            yield return(new WaitUntil(() => unloading.isDone));
        }

        var loading = SceneManager.LoadSceneAsync(level, LoadSceneMode.Additive);

        yield return(new WaitUntil(() => loading.isDone));

        currentLevel = level;
        levelSelection.SetActive(false);

        OnLevelLoaded?.Invoke();
    }
示例#8
0
    //Genrate Bricks from Levels Data
    private void GenerateBricks()
    {
        // Intializing Remaining bricks collection before genrating bricks
        this.RemainingBricks    = new List <Brick>();
        int[,] currentLevelData = this.LevelsData[this.CurrentLevel];
        // need to get initial position to spawn bricks (for first brick only)
        float currentSpawnX = initialBrickSpawnPositionX;
        float currentSpawnY = initialBrickSpawnPositionY;

        float zShift = 0; // variable to put bricks near to camera to avoid overlapping

        for (int row = 0; row < this.maxRows; row++)
        {
            for (int col = 0; col < this.maxCols; col++)
            {
                //
                int brickType = currentLevelData[row, col];
                if (brickType > 0)
                {
                    Brick newBrick = Instantiate(brickPrefab, new Vector3(currentSpawnX, currentSpawnY, 0.0f - zShift), Quaternion.identity) as Brick;
                    newBrick.Init(bricksContainer.transform, this.Sprites[brickType - 1], this.BrickColors[brickType], brickType);

                    this.RemainingBricks.Add(newBrick);
                    zShift += 0.0001f;
                }

                //shifting after spwaing every new brick
                currentSpawnX += shiftAmount;

                if (col + 1 == this.maxCols)
                {
                    currentSpawnX = initialBrickSpawnPositionX;
                }
            }

            currentSpawnY -= shiftAmount;
        }

        this.initialBricksCount = this.RemainingBricks.Count;
        // invoking event after bricks have generated
        OnLevelLoaded?.Invoke();
    }
示例#9
0
    private void GenerateBricks()
    {
        RemainingBricks         = new List <Brick>();
        int[,] currentLevelDate = LevelData[currentLevel];
        float currentSpawnX = initialBrickSpawnPosX;
        float currentSpawnY = initialBrickSpawnPosY;

        float zShift = 0;

        for (int row = 0; row < maxRows; row++)
        {
            for (int col = 0; col < maxCols; col++)
            {
                int BrickType = currentLevelDate[row, col];

                if (BrickType > 0)
                {
                    Brick newBrick = Instantiate(brickPrefab, new Vector3(currentSpawnX, currentSpawnY, 0.0f - zShift), Quaternion.identity) as Brick;
                    newBrick.Init(brickContainer.transform, Sprites[BrickType - 1], BrickColors[BrickType], BrickType);

                    RemainingBricks.Add(newBrick);
                    zShift += 0.0001f;
                }

                currentSpawnX += shiftAmount;
                if (col + 1 == maxCols)
                {
                    currentSpawnX = initialBrickSpawnPosX;
                }
            }

            currentSpawnY -= shiftAmount;
        }

        InitialBrickCount = RemainingBricks.Count;
        OnLevelLoaded?.Invoke();
    }
示例#10
0
        private void PrepareLevel()
        {
            if (currentLevel == null)
            {
                Debug.Log(" # -LvlCntr- # Current Level Not Found or not loaded");
                return;
            }

            actorsController = new AIActorsController();
            triggersManager  = new TriggersManager(FindObjectsOfType <Trigger>());

            spawnPoints   = FindObjectsOfType <SpawnPoint>();
            levelSettings = FindObjectOfType <LevelSettings>();

            triggersManager.Init();

            if (levelSettings != null)
            {
                PlayerManager.Instance().TeleportToPoint(levelSettings.spawnPointId);
                levelSettings.Apply();
            }

            OnLevelLoaded?.Invoke();
        }
示例#11
0
 public void LevelLoad()
 {
     OnLevelLoaded?.Invoke();
 }
示例#12
0
 /// <summary>
 /// The callback to be invoked when the SceneLoader loaded the level scene
 /// </summary>
 private void OnLevelSceneLoaded(AsyncOperationHandle <SceneInstance> handle)
 {
     OnLevelLoaded?.Invoke(
         _curLevelID, _levelDataManager.GetLevelData(_curLevelID));
     _levelSceneHandle = handle;
 }
        private static IEnumerator InternalRunServer(QNetConfiguration configuration)
        {
            var sw          = Stopwatch.StartNew();
            var targetLevel = ServerNextMapName;

            ServerIsInitializing = true;

            // load world fist
            LastMapState = QNetMapState.Loading;
            OnMapStateChanged?.Invoke(QNetMapState.Loading);
            var isLevelLoading = true;

            QNetLevelLoader.Load(targetLevel, () => { isLevelLoading = false; });
            while (isLevelLoading)
            {
                yield return(new WaitForEndOfFrame());
            }

            OnLevelLoaded?.Invoke(targetLevel);
            yield return(new WaitForEndOfFrame());

            // then load serialized object in memory
            // TODO: Write objects from save in to memory

            var time = DateTime.Now;
            var isWorldSerializing         = true;
            var worldSerializingLastAction = "not defined";

            QNetWorldSerializer.DeSerializeObjectsInMemory(() => { isWorldSerializing = false; }, action =>
            {
                time = DateTime.Now;
                worldSerializingLastAction = action;
            });
            while (isWorldSerializing)
            {
                yield return(new WaitForEndOfFrame());
            }

            if ((DateTime.Now - time).Seconds >= DeserializingTimeout)
            {
                ShutdownInitializing(worldSerializingLastAction);
                yield break;
            }

            LastMapState = QNetMapState.Loaded;
            OnMapStateChanged?.Invoke(QNetMapState.Loaded);

            // the initialize server
            QNetManager.StartServer(configuration);

            GameIsInitializing   = false;
            ServerIsInitializing = false;
            GameInitialized      = true;

            bool isWorldReady = false;

            OnWorldAndNetworkReady?.Invoke(() => { isWorldReady = true; });
            while (!isWorldReady)
            {
                yield return(new WaitForEndOfFrame());
            }

            // we need to call OnNetworkActive event
            for (var index = 0; index < QNetObjectBehaviour.SpawnedBehaviours.Length; index++)
            {
                var obj = QNetObjectBehaviour.SpawnedBehaviours[index];
                obj.OnNetworkActive();
            }

            for (var index = 0; index < QNetObjectBehaviour.PredefinedBehaviours.Length; index++)
            {
                var obj = QNetObjectBehaviour.PredefinedBehaviours[index];
                obj.OnInternalSpawned();
                obj.OnNetworkActive();
            }

            JEMLogger.Log($"QNetUnity ServerRun main work took {sw.Elapsed.Milliseconds:0.00}ms.");
        }
        private static IEnumerator InternalRunHost(QNetConfiguration configuration)
        {
            // load world first
            var targetLevel = ServerNextMapName;

            // activate loading screen
            OnClientLoadingInfoUpdated?.Invoke(true, "LOADING LEVEL", $"Loading {targetLevel}");
            OnClientLoadingStart?.Invoke();

            yield return(new WaitForSeconds(0.6f)); // wait some time, lol

            var sw = Stopwatch.StartNew();

            ServerIsInitializing = true;
            HostIsInitializing   = true;

            LastMapState = QNetMapState.Loading;
            OnMapStateChanged?.Invoke(LastMapState);

            var isLevelLoading = true;

            QNetLevelLoader.Load(targetLevel, () => { isLevelLoading = false; });
            while (isLevelLoading)
            {
                yield return(new WaitForEndOfFrame());
            }

            OnLevelLoaded?.Invoke(targetLevel);
            yield return(new WaitForEndOfFrame());

            // TODO: Write objects from save in to memory
            // TODO: Remove block of code below (DeSerializingObjects)

            // update lading screen
            OnClientLoadingInfoUpdated?.Invoke(true, "LOADING WORLD",
                                               $"DeSerializing {QNetWorldSerializer.SerializedObjectsInMemory} world objects.");

            var isWorldSerializing = true;
            var time = DateTime.Now;
            var worldSerializingLastAction = "not defined";

            QNetWorldSerializer.DeSerializeObjectsInMemory(() => { isWorldSerializing = false; }, action =>
            {
                time = DateTime.Now;
                worldSerializingLastAction = action;
            });
            while (isWorldSerializing)
            {
                yield return(new WaitForEndOfFrame());
            }

            if ((DateTime.Now - time).Seconds >= DeserializingTimeout)
            {
                ShutdownInitializing(worldSerializingLastAction);
                yield break;
            }

            LastMapState = QNetMapState.Loaded;
            OnMapStateChanged?.Invoke(LastMapState);

            // update loading screen
            OnClientLoadingInfoUpdated?.Invoke(true, "READY", "Setting up player.");

            // then initialize host
            QNetManager.StartHost(configuration);

            GameIsInitializing   = false;
            ServerIsInitializing = false;
            HostIsInitializing   = false;
            GameInitialized      = true;
            OnClientLoadingEnd?.Invoke();

            // the initialize client
            OnLoadClientSideContent?.Invoke();

            bool isWorldReady = false;

            OnWorldAndNetworkReady?.Invoke(() => { isWorldReady = true; });
            while (!isWorldReady)
            {
                yield return(new WaitForEndOfFrame());
            }

            // we need to call OnNetworkActive event
            for (var index = 0; index < QNetObjectBehaviour.SpawnedBehaviours.Length; index++)
            {
                var obj = QNetObjectBehaviour.SpawnedBehaviours[index];
                obj.OnNetworkActive();
            }

            for (var index = 0; index < QNetObjectBehaviour.PredefinedBehaviours.Length; index++)
            {
                var obj = QNetObjectBehaviour.PredefinedBehaviours[index];
                obj.OnInternalSpawned();
                obj.OnNetworkActive();
            }

            JEMLogger.Log($"QNetUnity RunHost main work took {sw.Elapsed.Milliseconds:0.00}ms.");
        }