using System.Runtime.CompilerServices; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Cell : MonoBehaviour { GameManager gameManager; public GameObject mask = null; //选中角色时在单元格上显示攻击范围 public Cell parent = null; public int cost = 99; //走在单元格上消耗的行动点数 public int damage = 0; //单元格对站在上面的角色造成的伤害 bool occupied = false; //是否有角色占着单元格 public Character currentCharacter; //当前单元格上的角色 public int gCost; //路径耗散 public int hCost; //预测耗散 public int fCost; //A*耗散 private void Awake() { gameManager = GameObject.Find("GameManager").GetComponent(); if(gameObject.tag == "Block") cost = 99; } public void SetOccupied(bool value) { occupied = value; } public bool GetOccupied() { return occupied; } public void SetMask(bool value) { mask.SetActive(value); } public void SetCurrentCharacter(Character character) { currentCharacter = character; } public Character GetCurrentCharacter() { return currentCharacter; } private void OnMouseEnter() { gameManager.ChangeCellInformation(cost, damage); } public List GetNeighbor() //寻找邻居节点 { RaycastHit2D[] hits ; List directions = new List {Vector2.up, Vector2.down, Vector2.left, Vector2.right}; List neighbors = new List(); foreach(var direction in directions) { hits = Physics2D.RaycastAll(transform.position,direction,1.0f,LayerMask.GetMask("Cells")); if(hits.GetLength(0) < 2) continue; Cell cell = hits[1].collider.GetComponent(); neighbors.Add(cell); } return neighbors; } public void CalculateCosts(Vector2 goal) { gCost = parent.gCost + cost + damage; hCost = GameSettlement.Manhattan(transform.position, goal); fCost = gCost + hCost; } }