//根据list中的单位,加载prefab同时加载到格子里面 //最好直接把prefab中的脚本换掉 private void loadPrefab() { for (int i = 0; i < 2; i++) { for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { //该位置的单位不为空 if (battleData.hasCharacterInGrid(i, x, y)) { int id = battleData.GetCharacterList()[i, x, y].GetId(); //加载prefab GameObject obj = Resources.Load("Prefabs/character/" + id) as GameObject; obj = Instantiate(obj); //Debug.Log(obj.GetComponent<Character>().GetInstanceID()); obj.SetActive(false); GridUnit grid = GetGridUnitByVector3(new Vector3Int(i, x, y)); //获取对应格子 obj.transform.SetParent(CharacterTransform); //设置位置 //设置位置测试 obj.transform.position = grid.gameObject.transform.position; //重置list中的character battleData.GetCharacterList()[i, x, y] = obj.GetComponentInChildren <Character>(); //往格子里加单位 grid.SetCharacter(battleData.GetCharacterList()[i, x, y]); //设置character中自己的坐标 battleData.GetCharacterList()[i, x, y].SetLocation(new Vector3Int(i, x, y)); } } } } }
/** * Return a gradient noise texture at block coordinates. */ public static Texture2D Create(GridUnit InGridUnit) { Color[] pix = new Color[TEX_SIZE * TEX_SIZE]; Texture2D tex = new Texture2D(TEX_SIZE, TEX_SIZE); for (int y = 0; y < TEX_SIZE; y++) { for (int x = 0; x < TEX_SIZE; x++) { float xCoord = InGridUnit.x + ((float)x / TEX_SIZE); float yCoord = InGridUnit.y + ((float)y / TEX_SIZE); float sample = Mathf.PerlinNoise(xCoord, yCoord); pix[y * TEX_SIZE + x] = new Color(sample, sample, sample, 1f); } } tex.SetPixels(pix); tex.Apply(); tex.wrapMode = TextureWrapMode.Clamp; return(tex); }
/// <summary> /// Check if gridUnit has been accounted for already - if not, switch accounted for to true /// </summary> /// <param name="gUnit"></param> /// <returns>bool representing whether grid unit has been accounted for previously or not</returns> private static Boolean IsGridUnitAccountedFor(GridUnit gUnit) { try { // Check that grid unit is not outside bounds of the grid if (gUnit.X < 0 || gUnit.Y < 0 || gUnit.X >= WIDTH || gUnit.Y >= HEIGHT) { //outside of bounds return(true); } GridUnit coordinateToCheck = grid[gUnit.X, gUnit.Y]; if (coordinateToCheck.AccountedFor) { //already account for return(true); } coordinateToCheck.AccountedFor = true; //had not yet been accounted for return(false); } catch (Exception e) { //Log.Error(e, "IsGridUnitAccountedFor()"); return(true); } }
/// <summary> /// Create grid units for a barren land rectangle /// </summary> /// <param name="bounds"></param> /// <returns>List of grid units in barren land rectangle</returns> private static List <GridUnit> FillIndividualBarrenLandGridUnits(Int32[] bounds) { try { List <GridUnit> barrenLandGridUnits = new List <GridUnit>(); if (bounds.Length < 4) { return(barrenLandGridUnits); } //Loop through endpoints for (int i = bounds[0]; i <= bounds[2]; i++) { for (int j = bounds[1]; j <= bounds[3]; j++) { // create new grid unit for each coordinate within rectangle endpoints GridUnit barrenLandGridUnit = new GridUnit(i, j); //barrenLandGridUnit.setIsBarren(true); //then add to barrenLandGridUnits list barrenLandGridUnits.Add(barrenLandGridUnit); } } //return all grid units for input coordinates return(barrenLandGridUnits); } catch (Exception e) { //Log.Error(e, "FillIndividualBarrenLandGridUnits()"); return(new List <GridUnit>()); } }
/// <summary> /// Check through grid, find first unaccounted for point, /// fill the fertile area directly connected to that point, and return the total area /// </summary> /// <param name="land"></param> /// <param name="xValue"></param> /// <param name="yValue"></param> /// <returns>List of area of each fertile land plot</returns> private static List <Int32> CheckForUnaccountedAreasAndCountFertileLand(List <Int32> land, int xValue, int yValue) { try { for (int y = yValue; y < HEIGHT; y++) { for (int x = xValue; x < WIDTH; x++) { GridUnit tile = grid[x, y]; if (!tile.AccountedFor) { int totalFertileArea = FillFertileLandAreas(x, y); land.Add(totalFertileArea); CheckForUnaccountedAreasAndCountFertileLand(land, x, y); } } } return(land); } catch (Exception e) { //Log.Error(e, "CheckForUnaccountedAreasAndCountFertileLand()"); return(new List <Int32>()); } }
public void FindAllGridUnits() { //this method gets called often on enemy turns and could be bad for performance. gridUnits = new List <GridUnit> (); player = GameObject.FindGameObjectWithTag("Player").GetComponent <GridUnit> (); gridUnits.Add(player); GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject enemy in enemies) { GridUnit tempGU = (enemy.GetComponent <GridUnit>()); if (tempGU != null) { gridUnits.Add(tempGU); } } GameObject[] obstacles = GameObject.FindGameObjectsWithTag("obstacle"); foreach (GameObject obs in obstacles) { GridUnit tempGU = obs.GetComponent <GridUnit>(); if (tempGU != null) { gridUnits.Add(tempGU); } } }
public override void Affect(GridUnit targetedUnit) { BasicDamageEffect(targetedUnit, 1); Tutorial.PlayedACardLevel5 = true; S.TutorialInst.TurnOffArrows(); }
public void ReloadLevel() { if (level == null) { Debug.Log("当前地图为空"); return; } int x = level.X; int y = level.Y; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (GridController.Instance.DicGrid.ContainsKey(i * 10 + j)) { continue; } GameObject grid = Instantiate(Resources.Load("Prefabs/Grid")) as GameObject; GridUnit mgrid = grid.AddComponent <GridUnit>(); mgrid.GridId = GridController.Instance.GetGridID(i, j); grid.transform.SetParent(GridController.Instance.GridControllerTransform, false); GridController.Instance.DicGrid[mgrid.GridId] = mgrid; mgrid.GridType = GridController.Instance.GetNewType(mgrid.GridId); mgrid.Init(); grid.transform.SetAsFirstSibling(); } } }
void Start() { useGUILayout = false; playerGU = gameObject.GetComponent <GridUnit>(); unitSFX = gameObject.GetComponent <UnitSFX>(); ResetLife(); }
public void CreateGrids() { DeleteGrids(); GridList.Clear(); float widthOffset = (Col - 1) * GridWidth / 2f; float heightOffset = Row * GridHeight / 2f; float posX = StartX - widthOffset; float posY = StartY - heightOffset; for (int i = 0; i < Row; i++) { posX = StartX - widthOffset; for (int j = 0; j < Col; j++) { GameObject grid = GameObject.Instantiate(GridPrefab); grid.transform.SetParent(GridContainer); grid.transform.localPosition = new Vector3(posX, posY); grid.transform.localScale = Vector3.one; grid.name = "Grid_" + i + "_" + j; GridUnit unit = grid.GetComponent <GridUnit>(); int colorIndex = Random.Range(0, ColorList.Length); unit.SetColor(ColorList[colorIndex]); unit.SetValue(Random.Range(1, 10)); GridList.Add(unit); posX += GridWidth; } posY += GridHeight; } }
public override void Affect(GridUnit targetedUnit) { BasicDamageEffect (targetedUnit, 1); Tutorial.PlayedACardLevel5 = true; S.TutorialInst.TurnOffArrows(); }
GridUnit newGrid(int id, Vector3Int pos) { var u = new GridUnit(id, pos); u.go = Instantiate(prefabs[id].go, poolGrid, true); return(u); }
} // InitGameGrid() // Initialize the internal market grid public void InitMarketGrid() { if (!hasAuthority) { Debug.Log(debug + "No authority to initialize the internal market grid!"); return; } // Market Grid #################################### marketGrid = new GridUnit[Mathf.CeilToInt((float)GameManager.masterDeck.marketCardDeck.Count() / (float)GameManager.height), GameManager.height]; maxMarketStack = new int[GameManager.height]; int marketWidth = Mathf.CeilToInt((float)GameManager.masterDeck.marketCardDeck.Count() / (float)GameManager.height); for (int x = 0; x < marketWidth; x++) { for (int y = 0; y < GameManager.height; y++) { // Draw a card from the Market Card deck // Card card = Card.CreateInstance<Card>(); CardData card; if (GameManager.DrawCard(GameManager.masterDeckMutable.marketCardDeck, GameManager.masterDeck.marketCardDeck, out card, false)) { // Debug.Log("[GridManager] Saving card at [" + x + ", " + y + "]"); // Connect the drawn card to the internal grid marketGrid[x, y] = new GridUnit(card: card, x: x, y: y); // Debug.Log("[GridManager] Card saved: " + marketGrid[x, y].card); } } // y } // x } // InitMarketGrid()
void OnTriggerEnter2D(Collider2D col) { if (col.name.StartsWith("GridUnit")) { currentGrid = col.GetComponent <GridUnit> (); } }
//通过点击设置网格类型 private void SetGridType(GridType selectType) { GridUnit clicked = SelectGrid(); if (clicked && last != clicked) { clicked.gridUnitData.gridType = selectType; if (selectType == GridType.From) { if (from != null) { from.gridUnitData.gridType = GridType.None; } from = clicked; } else if (selectType == GridType.To) { if (to != null) { to.gridUnitData.gridType = GridType.None; } to = clicked; } Refresh(); last = clicked; } }
bool InRetainBounds(GridUnit g) { return(g.x > bottomLeftGrid.x - 6 && g.x < topRightGrid.x + 6 && g.y > bottomLeftGrid.y - 6 && g.y < topRightGrid.y + 6); }
public void UpdatePositionByGrid(GridUnit gridUnit) { if (BattleUnit != null) { transform.localPosition = gridUnit.LocalPosition; } }
private NavigationData GetEmptyNavigationData(GridUnit _thisGrid, NavigationData _preGrid, int _G, int _H) { //优先从池子里取出 NavigationData nd = null; if (curUsedIdx < navigationDataPool.Count) { nd = navigationDataPool[curUsedIdx]; } else { nd = new NavigationData(); navigationDataPool.Add(nd); } ++curUsedIdx; nd.thisGrid = _thisGrid; nd.preGrid = _preGrid; nd.G = _G; nd.H = _H; nd.F = _G + _H; nd.open = true; nd.thisGrid.tempRef = nd; return(nd); }
public void MoveToTargetGrid(GridUnit gridUnit, bool stopMoveAnim) { if (gridUnit == null) { animator.SetBool("Run", false); return; } foreach (Transform child in transform) { child.LookAt(gridUnit.LocalPosition); } if (animator.GetBool("Run") == false) { animator.SetBool("Run", true); } BattleUnit.EnterGrid(gridUnit); transform.DOMove(gridUnit.LocalPosition, 0.5f).OnComplete(() => { BattleUnit.BattleUnitState = BattleUnitState.Wait; if (stopMoveAnim) { animator.SetBool("Run", false); } }); }
private void LineClear(List <int> linesToClear) { GameEngine.instance.lineDelayf++; if (GameEngine.instance.lineDelayf >= (int)Math.Floor(GameEngine.instance.lineDelay) && GameEngine.instance.lineDelay >= 1) { gameAudio.PlayOneShot(audioLineFall); linecleared = false; for (int i = 0; i < linesToClear.Count; i++) { /* The initial index of lineToDrop is calculated by taking the index of the first line * that was cleared then adding 1 to indicate the index of the line above the cleared line, * then the value i is subtracted to compensate for any lines already cleared. */ for (int lineToDrop = linesToClear[i] + 1 - i; lineToDrop < gridSizeY; lineToDrop++) { for (int x = 0; x < gridSizeX; x++) { GridUnit curGridUnit = fullGrid[x, lineToDrop]; if (curGridUnit.isOccupied) { MoveTileDown(curGridUnit); } } } } } }
//战场中铺设格子(信息,不做显示) public void Init(int width, int height) { if (width <= 0 || height <= 0) { return; } MapWidth = width; MapHeight = height; MapGrids = new GridUnit[MapWidth, MapHeight]; for (int i = 0; i < MapHeight; i++) { for (int j = 0; j < MapWidth; j++) { GridUnit gridUnit = new GridUnit(MapId, i, j); gridUnit.LocalPosition = new Vector3( j * GameConst.Map_GridWith + (((i & 1) == 1) ? GameConst.Map_GridWith * 0.5f : 0f), 0, -i * GameConst.Map_GridOffsetY); gridUnit.GridType = GridType.Normal; MapGrids[j, i] = gridUnit; } } GenerateBorn(); TidyGridList(); }
void showEnemySquares() { GridUnit tempGU = flashingEnemy.GetComponent <GridUnit>(); S.GridControlInst.MakeSquares(flashingEnemy.AttackTargetType, flashingEnemy.AttackMinRange, flashingEnemy.AttackMaxRange, tempGU.xPosition, tempGU.yPosition, false); }
public void Reset() { targetBattleUnit = null; movePath = null; battleSkill = null; skillTargetGrid = null; skillTargetBattleUnit = null; }
public void Recycle() { battleSkill = null; targetBattleUnit = null; targetGridUnit = null; score = 0; effectedCount = 0; }
public override void Play() { GridUnit playerGU = playerObj.GetComponent <GridUnit> (); FindAndAffectUnits((int)playerGU.xPosition, (int)playerGU.yPosition); base.Play(); }
//创建事件 public static T CreateEvent <T>(GridUnitEventType gridUnitEventType, GridUnit grid) where T : GridUnitEvent, new() { var e = new T(); e.grid = grid; e.gridUnitEventType = gridUnitEventType; return(e); }
public GridLength(int value, GridUnit unit) { if (value < 0) { throw new ArgumentException("Value cannot be negative.", nameof(value)); } Value = unit != GridUnit.Auto ? value : 0; Unit = unit; }
/// <summary> /// タイルを一行下に動く /// </summary> /// <param name="curGridUnit"></param> private void MoveTileDown(GridUnit curGridUnit) { TileController curTile = curGridUnit.tileOnThisGrid.GetComponent <TileController>(); curTile.MoveTile(Vector2Int.down); curTile.SetTile(); curGridUnit.tileOnThisGrid = null; curGridUnit.isOccupied = false; }
//实例化单元格 private GridUnit InstantiateGridUnit(int row, int column) { GridUnit gu = Instantiate(gridUnitPrefab, gridUnitRoot); gu.gridUnitData = currentMapData.gridUnitDatas[row, column]; gu.name = string.Format("GridUnit_{0}_{1}", row, column); gu.Refresh(); return(gu); }
private static GridUnit ParseGridUnitAttribute([NotNull] this XElement element) { var attr = element.Attribute("gridunit"); if (attr == null) { return(GridUnit.UNKNOWN_UNITS); } return(GridUnit.ByResolution(Int32.Parse(attr.Value))); }
public void Add(GridUnit u) { u.go.transform.position = Vector3.Scale(u.pos, gridUnitSize); if (coverLocalScale) { u.go.transform.localScale = gridUnitSize; } units.Add(u); units.Sort(SortList); }
public override void Affect(GridUnit targetedUnit) { BasicStunEffect (targetedUnit); }
public override void Affect(GridUnit targetedUnit) { BasicDamageEffect (targetedUnit, 1); }
/// <summary> /// Returns the position the other gridunit is in relation to this. /// If this gridunit is at [0, 0] and the other is at [0, 1] it returns "up" /// </summary> /// <param name="otherGU"></param> /// <returns></returns> public string AdjacentPosition(GridUnit otherGU) { return AdjacentPosition(new int[] { xPosition, yPosition }, new int[] { otherGU.xPosition, otherGU.yPosition }); }
public bool IsAdjacent(GridUnit unit) { return IsAdjacent(new int[] {unit.xPosition, unit.yPosition}, new int[] {xPosition, yPosition}); }
public void FindAllGridUnits() { //this method gets called often on enemy turns and could be bad for performance. gridUnits = new List<GridUnit> (); player = GameObject.FindGameObjectWithTag ("Player").GetComponent<GridUnit> (); gridUnits.Add (player); GameObject[] enemies = GameObject.FindGameObjectsWithTag ("Enemy"); foreach(GameObject enemy in enemies) { GridUnit tempGU = (enemy.GetComponent<GridUnit>()); if(tempGU != null) gridUnits.Add(tempGU); } GameObject[] obstacles = GameObject.FindGameObjectsWithTag("obstacle"); foreach (GameObject obs in obstacles) { GridUnit tempGU = obs.GetComponent<GridUnit>(); if(tempGU != null) gridUnits.Add(tempGU); } }
void Start() { useGUILayout = false; playerGU = gameObject.GetComponent<GridUnit>(); unitSFX = gameObject.GetComponent<UnitSFX>(); ResetLife (); }
public bool IsDiagonal(GridUnit unit) { return (Mathf.Abs(xPosition - unit.xPosition) == Mathf.Abs(yPosition - unit.yPosition)); }
public void BasicStunEffect(GridUnit gridUnit) { if(gridUnit.gameObject.tag == "Player") { Player player = gridUnit.gameObject.GetComponent<Player>(); player.StunnedForXTurns++; } if(gridUnit.gameObject.tag == "Enemy") { Enemy enemy = gridUnit.gameObject.GetComponent<Enemy>(); enemy.StunnedForXTurns++; } }
////////////////////////////////////// /// Utilities ////////////////////////////////////// public void BasicDamageEffect(GridUnit gridUnit, int damageTaken) { if(gridUnit.gameObject.tag == "Player") { Player player = gridUnit.gameObject.GetComponent<Player>(); player.TakeDamage(damageTaken, 0); } if(gridUnit.gameObject.tag == "Enemy") { Enemy enemy = gridUnit.gameObject.GetComponent<Enemy>(); enemy.TakeDamage(damageTaken); } }
public virtual void Affect(GridUnit x) { Debug.LogError("Card parentclass's Affect() was called. Bad!"); }