Example #1
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();
    }
        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();
        }
Example #3
0
    static int LoadLevelAsync(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <string, OnAdditiveLevelLoaded>(L, 2))
            {
                SceneMgr obj  = (SceneMgr)ToLua.CheckObject <SceneMgr>(L, 1);
                string   arg0 = ToLua.ToString(L, 2);
                OnAdditiveLevelLoaded arg1 = (OnAdditiveLevelLoaded)ToLua.ToObject(L, 3);
                obj.LoadLevelAsync(arg0, arg1);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <int, OnLevelLoaded>(L, 2))
            {
                SceneMgr      obj  = (SceneMgr)ToLua.CheckObject <SceneMgr>(L, 1);
                int           arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                OnLevelLoaded arg1 = (OnLevelLoaded)ToLua.ToObject(L, 3);
                obj.LoadLevelAsync(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: SceneMgr.LoadLevelAsync"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    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");
    }
Example #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();
    }
Example #6
0
    /// <summary>
    /// 以异步-单独的方式加载场景(携程调用)
    /// </summary>
    /// <param name="levelIndex"></param>
    /// <param name="onLevelLoaded"></param>
    /// <returns></returns>
    private IEnumerator LoadTargetLevelAsync(int levelIndex, OnLevelLoaded onLevelLoaded)
    {
        if (SceneManager.GetActiveScene().buildIndex == levelIndex)
        {
            Debug.LogWarning(string.Format("索引为{0}的场景已经加载过了!", levelIndex));
        }
        AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(levelIndex, LoadSceneMode.Single);

        while (!asyncOperation.isDone)
        {
            yield return(asyncOperation);
        }
        currentScene = SceneManager.GetActiveScene();
        if (null != onLevelLoaded)
        {
            onLevelLoaded(levelIndex);
        }
    }
        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);
        }
Example #8
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();
    }
Example #9
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();
    }
Example #10
0
        public void LoadLevel(string LevelName, OnLevelLoaded OnLevelLoaded, bool ShowLoadingScreen = false)
        {
            bool value = currentlyLoadedScenes.Any(x => x == LevelName);

            if (value)
            {
                Debug.Log(string.Format("Current level ({0}) is already loaded into the game.", LevelName));
                return;
            }


            LevelLoadingData lld = new LevelLoadingData();

            lld.AO             = SceneManager.LoadSceneAsync(LevelName, LoadSceneMode.Additive);
            lld.SceneName      = LevelName;
            lld.onLevelLoaded += OnLevelLoaded;
            levelsLoading.Add(lld);

            if (ShowLoadingScreen)
            {
                ApplicationManager.Instance.ShowLoadingScreen();
            }
        }
Example #11
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();
    }
Example #12
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();
        }
Example #13
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;
 }
Example #14
0
 /// <summary>
 /// 以异步-单独的方式加载场景
 /// </summary>
 /// <param name="levelIndex"></param>
 /// <param name="onLevelLoaded"></param>
 public void LoadLevelAsync(int levelIndex, OnLevelLoaded onLevelLoaded)
 {
     StartCoroutine(LoadTargetLevelAsync(levelIndex, onLevelLoaded));
 }
        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.");
        }
Example #16
0
 public void LevelLoad()
 {
     OnLevelLoaded?.Invoke();
 }
        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.");
        }