public void UnSpawnbin() { if (TileManagerProxy.Get().GetTile(GetCoordinates()).GetTileObject() == null) { return; } Destroy(TileManagerProxy.Get().GetTile(GetCoordinates()).GetTileObject().gameObject); ms_BinNumber--; }
public void SpawnBin(int binNumber) { if (!TileManagerProxy.Get().GetTile(GetCoordinates()).IsEmpty()) { new DialogueEvent("Cannot Spawn").Push(); CommandStackProxy.Get().PopCommand().Undo(); return; } StartCoroutine(SpawnRountine(binNumber)); }
public void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (GetActiveSceneName() == "Level") { TileManagerProxy.Get().Reset(); GoalManagerProxy.Get().Reset(); CommandStackProxy.Get().Reset(); m_NumberOfMove = 0; string levelName = GetCurrentLevelName(); m_LevelDimension = LevelParser.GenLevel("/" + levelName + ".txt"); new LevelEvent(m_CurrentLevel, true).Push(); new BinSpawnEvent(true, 0).Push(); new DialogueEvent(levelName + "-start").Push(); } }
public static TileCoordinates GenLevel(string filename) { filename = Application.streamingAssetsPath + filename; string[] lines = File.ReadAllLines(filename); int x = 0; int y = 0; foreach (string line in lines) { string[] lienOfTile = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); x = 0; foreach (string tileInfo in lienOfTile) { string[] words = tileInfo.Split(','); ETileType tileType = ms_CharToTileType[words[0]]; if (tileType == ETileType.None) { x++; continue; } GameObject tileGameObject = GameObject.Instantiate(RessourceManager.LoadPrefab("Tile")); tileGameObject.transform.position = new Vector3(x.ToWorldUnit(), y.ToWorldUnit(), 0); Tile tile = tileGameObject.AddComponent <Tile> (); tile.SetCoordinates(new TileCoordinates(x, y)); tile.SetType(tileType); TileManagerProxy.Get().AddTile(tile); if (words.Length > 1) { ETileObjectType tileObjectType = (ETileObjectType)Enum.Parse(typeof(ETileObjectType), (String)words.GetValue(1), true); GameObject tileObjectGameObject = GameObject.Instantiate(RessourceManager.LoadPrefab("TileObject_" + words[1])); tileObjectGameObject.transform.position = new Vector3(x.ToWorldUnit(), y.ToWorldUnit(), 0); TileObject tileObject = tileObjectGameObject.GetComponent <TileObject> (); tileObject.Init(tileObjectType, x, y, words.SubArray(2, -1)); tile.SetTileObject(tileObject); } x++; } y--; } return(new TileCoordinates(x, y)); }
private bool CanMoveTo(int xDir, int yDir) { if (m_IsMoving || m_IsTurning) { return(false); } Tile nextTruckTile = TileManagerProxy.Get().GetTile(((int)transform.position.x).ToTileUnit() + xDir, ((int)transform.position.y).ToTileUnit() + yDir); if (m_Bin == null) { return(nextTruckTile != null && nextTruckTile.IsEmpty()); } else { TileCoordinates facingCoordinate = GetFacingTileCoordinates(); Tile nextBarrelTile = TileManagerProxy.Get().GetTile(new TileCoordinates(facingCoordinate.x + xDir, facingCoordinate.y + yDir)); return(nextBarrelTile != null && nextTruckTile != null && nextTruckTile.IsEmpty() && nextBarrelTile.IsEmpty()); } }
IEnumerator SpawnRountine(int binNumber) { m_Animator.SetBool("IsSpawning", true); SoundManagerProxy.Get().PlayMultiple(m_FallingSound); UpdaterProxy.Get().SetPause(true); yield return(new WaitForSeconds(1f)); GameObject binGameObject = GameObject.Instantiate(m_BinPrefab); TileCoordinates coordinates = GetCoordinates(); binGameObject.transform.position = new Vector3(coordinates.x.ToWorldUnit(), coordinates.y.ToWorldUnit(), 0); Bin bin = binGameObject.GetComponent <Bin> (); bin.Init(ETileObjectType.Bin, coordinates.x, coordinates.y, new string[] { binNumber.ToString() }); bin.SetSpawnedCommandNumber(); TileManagerProxy.Get().SetTileObject(coordinates, bin); ms_BinNumber++; UpdaterProxy.Get().SetPause(false); m_Animator.SetBool("IsSpawning", false); }
// This should be called before any other gameobject awakes private void Awake () { // Singleton pattern : this is the only case where it should be used if(ms_Instance == null) { ms_Instance = this; DontDestroyOnLoad (gameObject); // Keep the Updater first, as the other members might want to register to it m_Logger = new UnityLogger (); LoggerProxy.Open (m_Logger); m_Updater = new Updater (); UpdaterProxy.Open (m_Updater); m_GameEventManager = new GameEventManager (); GameEventManagerProxy.Open (m_GameEventManager); m_InputManager = new InputManager (); InputManagerProxy.Open (m_InputManager); m_LevelManager = new LevelManager (); LevelManagerProxy.Open (m_LevelManager); m_TileManager = new TileManager (); TileManagerProxy.Open (m_TileManager); m_CommandStack = new CommandStack (); CommandStackProxy.Open (m_CommandStack); m_GoalManager = new GoalManager (); GoalManagerProxy.Open (m_GoalManager); m_SoundManager = new SoundManager (); SoundManagerProxy.Open (m_SoundManager); m_SoundManager.SetMusicSource (m_MusicSource); m_SoundManager.SetFXSource (m_EfxSource); m_GameFlowHSM = new GameFlowHSM (); m_GameFlowHSM.Start (typeof (GameFlowMenuState)); } else if (ms_Instance != this) { Destroy (gameObject); return; } }
private bool CanTurn(int newFacingDirection) { if (m_IsMoving || m_IsTurning) { return(false); } if (m_Bin == null) { return(true); } else { TileCoordinates currentTileCoordinates = new TileCoordinates(((int)transform.position.x).ToTileUnit(), ((int)transform.position.y).ToTileUnit()); TileCoordinates oldFacingTileOffset = ms_NeighboorTiles[m_FacingDirection]; TileCoordinates newFacingOffset = ms_NeighboorTiles[(EFacingDirection)newFacingDirection]; TileCoordinates passingTileOffset = oldFacingTileOffset + newFacingOffset; Tile nextTile = TileManagerProxy.Get().GetTile(currentTileCoordinates + newFacingOffset); Tile passingTile = TileManagerProxy.Get().GetTile(currentTileCoordinates + passingTileOffset); return(passingTile != null && passingTile.CanTurn() && nextTile != null && nextTile.IsEmpty()); } }
private Tile GetFacingTile() { return(TileManagerProxy.Get().GetTile(GetFacingTileCoordinates())); }