void InitializeGrid() { if (transform.childCount > 0) { for (int i = 0; i < transform.childCount; i++) { Destroy(transform.GetChild(i).gameObject); } } cellTypesDictionary = new Dictionary <CellTypes, GameObject>(); Grid = new Cell[xLength, yLength]; emptyTiles = new List <Cell>(); //Load prefabs from the resources and set them to the dictionary. int n = System.Enum.GetNames(typeof(CellTypes)).Length; for (int i = 0; i < n; i++) { CellTypes tileType = (CellTypes)i; GameObject prefab = Instantiate(Resources.Load("Prefabs/" + tileType.ToString())) as GameObject; cellTypesDictionary.Add(tileType, prefab); prefab.SetActive(false); } }
private void Awake() { if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } cellTypesDictionary = new Dictionary <CellTypes, GameObject>(); powerupsPrefabsDict = new Dictionary <Powerups, GameObject>(); //Load prefabs from the resources and set them to the dictionary. int n = System.Enum.GetNames(typeof(CellTypes)).Length; for (int i = 0; i < n; i++) { CellTypes tileType = (CellTypes)i; GameObject prefab = Instantiate(Resources.Load("Prefabs/" + tileType.ToString())) as GameObject; cellTypesDictionary.Add(tileType, prefab); prefab.SetActive(false); } CreatePlayerAndEnemies(); CreatePowerupsDictionary(); }
/// <summary> /// Spawns tile at requested x and y matrix indeces. It overrides the previous entry and destroys the stale object. /// </summary> /// <param name="x">current row to spawn on</param> /// <param name="y">curreny column to spawn on</param> /// <param name="cellType">Cell type thet needs to be spawn</param> void SpawnTile(int x, int y, CellTypes cellType) { //if(cellType == CellTypes.RigidWall) //{ // Debug.Log("x: " + x + " - y:" + y); //} if (Grid[x, y] != null) //If there is already a cell in the given pos. { if (Grid[x, y].thisCellType == CellTypes.Grass) //And if it is grass { //DestroyImmediate(Grid[x, y].gameObject); emptyTiles.Remove(Grid[x, y]); Grid[x, y] = null; } } GameObject tile = Instantiate(cellTypesDictionary[cellType]); Sprite prefabSprite = tile.GetComponent <SpriteRenderer>().sprite; Cell cell = tile.GetComponent <Cell>(); tile.name = cellType.ToString() + "_" + x + "-" + y; cell.SetIDs(x, y); cell.isThisCellOnFire = false; Grid[x, y] = cell; cell.thisCellHasPower = Powerups.None; if (cellType == CellTypes.Grass && y < yLength - 3 && x > 2) //If it is grass, and avoids spawnign bots near player at game start. { emptyTiles.Add(cell); } if (cellType == CellTypes.SoftWall) { allSoftWalls.Add(cell); } gridOffset.x = -(xLength / 2); gridOffset.y = -(yLength / 2); if (yLength % 2 == 0) { gridOffset.y += 0.5f; } if (xLength % 2 == 0) { gridOffset.x += 0.5f; } tile.transform.position = GridToWorld(x, y); //Debug.Log(tile.name + " at: " + tile.transform.position); tile.transform.parent = transform; if (!tile.activeSelf) { tile.SetActive(true); } }
private void btnModeOnCLick(object sender, RoutedEventArgs e) { currentMode = currentMode + 1; if (currentMode == (CellTypes)4) { currentMode = (CellTypes)1; } btnMode.Content = currentMode.ToString(); }
public void ActionCall() { if (OnTrigger != null) { OnTrigger(); } else { Debug.LogError("Try to call empty trigger! Type: " + Type.ToString()); } }
/// <summary> /// 列类型 /// </summary> /// <param name="col"></param> /// <param name="cellType"></param> /// <returns></returns> public static GridColumn CellType(this GridColumn col, CellTypes cellType = CellTypes.String) { col.sType = cellType.ToString().ToLower(); return(col); }
public virtual string GetCell(CellTypes types) { return(BasePath + "/TableCells/" + types.ToString() + ".cshtml"); }
public override string ToString() => $"||:{type.ToString()}:||";