void Start() { gl = new GestureLibrary(libraryToLoad); player = GameObject.Find("Player"); gestureLineRenderer = GetComponent<LineRenderer>(); levelController = GetComponent<_LevelController>(); }
private void Awake() { Time.timeScale = 1; player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>(); // ========================== // Singleton initialization if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } // ========================== StartTimer(); // Generating current level bounds dynamically ********************** int maxX = 0, maxY = 0; foreach (_GridElement element in FindObjectsOfType <_GridElement>()) { maxX = (maxX < element.X ? element.X : maxX); maxY = (maxY < element.Y ? element.Y : maxY); } // ***************************************************************** // Array storing every tile on the map tiles = new _Tile[maxX + 1, maxY + 1]; // Filling the tiles array ***************************************** foreach (_Tile tile in FindObjectsOfType <_Tile>()) { if (tiles[tile.X, tile.Y] == null) { tiles[tile.X, tile.Y] = tile; } else { throw new DuplicatedTile(tiles[tile.X, tile.Y], tile); } } // ****************************************************************** // Filling inital tile informations (entities) ********************** foreach (_Entity obj in FindObjectsOfType <_Entity>()) { _Tile tile = tiles[obj.X, obj.Y]; try { if (obj is _Agent && tile is Floor) { (tile as Floor).agent = obj as _Agent; if (obj is Knight) { knights.Add(obj as Knight); } else if (obj is Monster) { monsters.Add(obj as Monster); } } else if (obj is Thing && tile is Floor) { (tile as Floor).thing = obj as Thing; } } catch (NullReferenceException) { throw new InvalidGridObjectPosition(obj); } } // ******************************************************************** // Creating knights and monsters arrays knightsTilemap = new bool[maxX + 1, maxY + 1]; monstersTilemap = new bool[maxX + 1, maxY + 1]; for (int i = 0; i < knightsTilemap.GetLength(0); i++) { for (int j = 0; j < knightsTilemap.GetLength(1); j++) { // Getting info from tile data if (tiles[i, j] is Wall) { knightsTilemap[i, j] = false; monstersTilemap[i, j] = false; } else if (tiles[i, j] is Floor) { knightsTilemap[i, j] = true; monstersTilemap[i, j] = true; } else if (tiles[i, j] is Door) { knightsTilemap[i, j] = true; monstersTilemap[i, j] = (tiles[i, j] as Door).Walkable; } } } }
private void OnDestroy() { instance = null; }