public void GameStart() { Debug.Log("GameManager : GameStart()"); //Destroying all balls BallController[] balls = BallsHolderSingleton.Instance.balls.ToArray(); foreach (BallController ballC in balls) { GameObject.Destroy(ballC.gameObject); } bottomMenu.SetActive(false); startMenu.SetActive(false); leaderboardsObject.SetActive(false); bottomMenuCylinder.SetActive(true); SetGameSpeed(normalGameSpeed); //resetting all the objects so the player can play again //BlockMeshGen is will reset in the BLockGeneratorScript onLevelEvent.Invoke(LevelEvent.LEVEL_START); // After the initial start, immediately transition into the playing state GamePlay(); }
/* Unload the currently loaded level */ public void Unload() { metadata.SetLoadState(false); metadata = new LevelMetadata(); theGrid.ClearGrid(); LevelUnloadCompleted?.Invoke(); }
public static void TriggerEvent(string eventName) { LevelEvent thisEvent = null; if (instance.eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.Invoke(); } }
private IEnumerator DispatchOnLevelLoaded(Level level) { yield return(null); if (onLevelLoaded != null) { onLevelLoaded.Invoke(level); } }
void TogglePulled() { Pulled = !Pulled; Debug.Log("Level is pullled: " + Pulled); if (Pulled) { onPulled.Invoke(); } else { onUnpulled.Invoke(); } }
public virtual void ResetLevel() { if (instanciatedScene) { DestroyImmediate(instanciatedScene); } instanciatedScene = Instantiate(resetables); instanciatedScene.SetActive(true); player.transform.position = respawn.transform.position; player.ResetChanges(); player.gameObject.SetActive(true); OnLevelReset?.Invoke(); }
/// <summary> /// Проверить во всех ли выходах есть персонажи. Если да, вызывает <see cref="onLevelComplete.Invoke"> /// </summary> public void CheckExits() { if (isCompleted) { return; } foreach (var e in transform.GetComponentsInChildren <Exit>()) { if (!e.isOk) { return; } } isCompleted = true; Debug.Log("Level completed"); onLevelComplete.Invoke(this); }
public Promise <LevelMeta> FetchLevelMeta(string levelId, bool updateLocal = false) { return(new Promise <LevelMeta>((resolve, reject) => { RestClient.Get <OnlineLevel>(new RequestHelper { Uri = $"{Context.ApiUrl}/levels/{levelId}", Headers = Context.OnlinePlayer.GetRequestHeaders() }).Then(it => { var remoteMeta = it.GenerateLevelMeta(); if (updateLocal && LoadedLocalLevels.ContainsKey(levelId)) { var localLevel = LoadedLocalLevels[levelId]; localLevel.OnlineLevel = it; if (UpdateLevelMeta(localLevel, remoteMeta)) { Debug.Log($"Level meta updated for {localLevel.Id}"); OnLevelMetaUpdated.Invoke(localLevel); } } resolve(remoteMeta); }).CatchRequestError(error => { if (!error.IsNetworkError && (error.StatusCode == 404 || error.StatusCode == 403)) { if (error.StatusCode == 404) { Debug.Log($"Level {levelId} does not exist on the remote server"); } else { Debug.Log($"Level {levelId} cannot be accessed on the remote server"); } } else { Debug.LogError(error); } reject(error); }); })); }
public void DeleteLocalLevel(string id) { if (!LoadedLocalLevels.ContainsKey(id)) { Debug.LogWarning($"Warning: Could not find level {id}"); return; } var level = LoadedLocalLevels[id]; level.Record.AddedDate = DateTimeOffset.MinValue; level.SaveRecord(); Directory.Delete(Path.GetDirectoryName(level.Path) ?? throw new InvalidOperationException(), true); LoadedLocalLevels.Remove(level.Id); loadedPaths.Remove(level.Path); OnLevelDeleted.Invoke(level); }
void OnSceneLoaded(Scene scene, LoadSceneMode mode) { Debug.Log("Loading Scene " + scene.name); Level level = null; foreach (GameObject g in scene.GetRootGameObjects()) { level = g.GetComponent <Level>(); if (level != null) { level.player = player; // scene has a Level object, is a loaded level. init here if (currentLevel == null) // initial level needs to start up high so levels can load in below it. { Debug.Log("Scene " + scene.name + " is first level"); currentScene = scene; currentLevel = level; currentLevel.OnEndReached.AddListener(GoToNextLevel); level.Move(Vector3.up * levelSeparationDistance); StartLoadnext(); // player init stuff Debug.Log("* setting player " + player.transform.position + " to " + level.GetStartPoint().position); player.transform.position = level.GetStartPoint().position; } else { Debug.Log("Scene " + scene.name + " is a level"); loadedScene = scene; loadedLevel = level; level.AlignTo(currentLevel.GetGoalPoint()); } OnLevelLoaded.Invoke(level); return; } } Debug.Log("Scene " + scene.name + " has no Level script, ignoring..."); }
public IEnumerator Load(int level_guid) { loadedInDebug = false; AsyncPropAndTileSetup.Instance.LoadConfigs(); while (!TileProperties.Loaded || !PropProperties.Loaded) { yield return(new WaitForEndOfFrame()); } if (!didTriggerMetaUpdate) { StartCoroutine(RefreshLevelData()); } while (!hasUpdatedMetas) { yield return(new WaitForEndOfFrame()); } Unload(); //Find our metadata LevelMetadata ourMeta = null; foreach (LevelMetadata meta in LevelMetadata) { if (meta.levelGUID == level_guid) { ourMeta = meta; break; } } if (ourMeta == null) { Debug.LogError("Cannot find requested level GUID!"); yield break; } metadata = ourMeta; metadata.SetLoadState(false); Debug.Log("Loading level: " + metadata.levelName + " (GUID " + metadata.levelGUID + ")"); int invisibleProps = 0; int invisibleTiles = 0; string configFile = Application.streamingAssetsPath + "/LEVELS/" + metadata.levelName + ".dwb"; #if !UNITY_WEBGL if (File.Exists(configFile)) //It's ok not to exist if we're in editor { #endif //Load our level config levelData = null; StartCoroutine(FileLoader.Instance.LoadAsBytes(configFile, LoadCallback)); while (levelData == null || !levelData.CanRead) { yield return(new WaitForEndOfFrame()); } //Read our level config BinaryReader reader = new BinaryReader(levelData); int versionNum = reader.ReadInt32(); if (!(versionNum == LevelFileVersion.VERSION_NUM)) //This can allow through back-supported config versions { Debug.LogError("Tried to load an outdated level file!"); reader.Close(); yield break; } if (versionNum != LevelFileVersion.VERSION_NUM) { Debug.LogWarning("This level uses file version " + versionNum + " (latest is " + LevelFileVersion.VERSION_NUM + "). While this version is supported, please re-save the level in editor ASAP to keep updated with the latest features."); } int tileCount = reader.ReadInt32(); Vector2 gridDims = new Vector2(reader.ReadInt16(), reader.ReadInt16()); if (gridDims != theGrid.GridTileDims) { Debug.LogError("Grid resizing is unsupported! This level is invalid."); reader.Close(); yield break; } //Load occupiers int tileOccupierCount = reader.ReadInt32(); for (int i = 0; i < tileOccupierCount; i++) { Tile parentTile = theGrid.AllTiles[reader.ReadInt32()]; int enumIndex = reader.ReadInt16(); if (!Enum.IsDefined(typeof(TileTypes), enumIndex)) { Debug.LogError("ERROR! When loading, a tile's occupier was of a type that no longer exists."); continue; } //Populate the tile's occupier GameObject parentTileObject = null; parentTileObject = Instantiate(worldTileObject, parentTile.Position, Quaternion.identity) as GameObject; TileTypes tileType = (TileTypes)enumIndex; #if UNITY_EDITOR if (!TileProperties.IsVisibleInEditor(tileType)) { invisibleTiles++; } #endif parentTileObject.GetComponent <LevelTileEntity>().Initialise(tileType, parentTile, false); } //Load props int tilePropCount = reader.ReadInt32(); for (int i = 0; i < tilePropCount; i++) { if (versionNum == 13) { reader.BaseStream.Position += 4; } int enumIndex = reader.ReadInt16(); PropRotation rotation = (PropRotation)reader.ReadInt16(); int propTileCount = reader.ReadInt32(); List <Tile> propTiles = new List <Tile>(); for (int x = 0; x < propTileCount; x++) { propTiles.Add(theGrid.AllTiles[reader.ReadInt32()]); } if (!Enum.IsDefined(typeof(PropTypes), enumIndex)) { Debug.LogError("ERROR! When loading, a tile's prop was of a type that no longer exists."); continue; } PropTypes propType = (PropTypes)enumIndex; GameObject parentTileDecoratorObject = Instantiate(worldPropObject, propTiles[0].Position, Quaternion.identity) as GameObject; #if UNITY_EDITOR if (!PropProperties.IsVisibleInEditor(propType)) { invisibleProps++; } #endif parentTileDecoratorObject.GetComponent <LevelPropEntity>().Initialise(propType, propTiles, rotation, false); } //Load some metadata metadata.SetGoonCount(reader.ReadInt32()); metadata.SetHazardCount(reader.ReadInt32()); reader.Close(); //Refresh all sprites to get the right contexts for (int i = 0; i < Grid.AllTiles.Count; i++) { if (Grid.AllTiles[i].IsOccupied) { Grid.AllTiles[i].Occupier.RefreshSprite(); } } metadata.SetLoadState(true); #if !UNITY_WEBGL } else { //User is just starting to create this level metadata.SetLoadState(true); LevelEditor.Instance.SaveLevel(); } #endif //Show/hide grid depending on editor state GetComponent <SpriteRenderer>().enabled = IsInEditor; if (invisibleProps == 0 && invisibleTiles == 0) { Debug.Log("Level loaded without warnings!"); } else { Debug.LogWarning("Level loaded successfully, but contains " + invisibleProps + " deprecated props and " + invisibleTiles + " deprecated tiles. Consider updating this content."); } LevelLoadCompleted?.Invoke(); validateNextTick = true; }
// Update is called once per frame void Update() { if (levelTransition) { //Debug.Log("Transitioning from " + currentScene.name + " to " + loadedScene.name); // track replacement progress of the levels float moveAmount = levelReplacementSpeed * Time.deltaTime; if (levelProgess + moveAmount >= levelSeparationDistance) // if at our destination, do cleanup of transition // finish amy movement { moveAmount = levelSeparationDistance - levelProgess; Debug.Log(moveAmount); // cleanup levelProgess = levelSeparationDistance; levelTransition = false; currentLevel.OnEndReached.RemoveListener(GoToNextLevel); currentLevel.StartIcarus(currentScene); //SceneManager.UnloadSceneAsync(currentScene); currentScene = loadedScene; currentLevel = loadedLevel; currentLevel.OnEndReached.AddListener(GoToNextLevel); levelNamesIndex++; Vector3 movement = Vector3.up * moveAmount; // move both levels up by the amount required each update step foreach (GameObject g in currentScene.GetRootGameObjects()) { g.transform.position += movement; } foreach (GameObject g in loadedScene.GetRootGameObjects()) { g.transform.position += movement; } player.transform.position += playerSlide * moveAmount / levelSeparationDistance; Debug.Log("setting player " + player.transform.position + " to " + currentLevel.GetStartPoint().position); player.rb.isKinematic = false; //currentLevel.Respawn(); OnLevelTransitionComplete.Invoke(currentLevel); StartLoadnext(); } else { levelProgess += moveAmount; Vector3 movement = Vector3.up * moveAmount; // move both levels up by the amount required each update step foreach (GameObject g in currentScene.GetRootGameObjects()) { g.transform.position += movement; } foreach (GameObject g in loadedScene.GetRootGameObjects()) { g.transform.position += movement; } player.transform.position += playerSlide * moveAmount / levelSeparationDistance; } } }
IEnumerator BattleCoroutine(Hero _attacker, Hero _attacked) { DataManager.instance.gameState = GameState.Battle; onStartBattle.Invoke(_attacker, _attacked); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); // First the attacker attack onHeroAttack.Invoke(_attacker, _attacked); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); // If the attacked is alive, then attack if (_attacked.isAlive) { onHeroAttack.Invoke(_attacked, _attacker); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } // Check for speed superiority : // if one of them has 5 more in speed than the other // then attack a second time in the turn if (_attacker.speed >= _attacked.speed + 5) { onHeroAttack.Invoke(_attacker, _attacked); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } else if (_attacked.speed >= _attacker.speed + 5) { onHeroAttack.Invoke(_attacked, _attacker); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } battleCoroutine = null; onEndCutscene.Invoke(); // Wait the end of animation continueBattle = false; yield return(new WaitUntil(() => continueBattle)); if (_attacker.isAlive && _attacker.expChanged) { HeroExpInfo info = _attacker.CheckCurrentLevel(); onExpGain.Invoke(info); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } if (_attacked.isAlive && _attacked.expChanged) { HeroExpInfo info = _attacked.CheckCurrentLevel(); onExpGain.Invoke(info); continueBattle = false; yield return(new WaitUntil(() => continueBattle)); } DataManager.instance.gameState = GameState.Playing; onEndBattle.Invoke(); }