public static Vector2 GetPositionInLimit(Vector2 MIN, Vector2 MAX) { if (TileCurrent == null) { Debug.Log("Tile Current không tồn tại, trả về giá trị mặc định"); return((MIN + MAX) / 2); } return(GetPositionInLimit(TileCurrent.WorldToCell(MIN), TileCurrent.WorldToCell(MAX), new Vector2(), false)); }
public static Vector2 GetPositionInLimit(Vector2 MIN, Vector2 MAX, Vector2 from, bool CanMoTo = true) { if (TileCurrent == null) { Debug.Log("Tile Current không tồn tại, trả về giá trị mặc định"); return(from); } return(GetPositionInLimit(TileCurrent.WorldToCell(MIN), TileCurrent.WorldToCell(MAX), from, CanMoTo)); }
public static Vector2 GetPositionInLimit(Vector3Int MIN, Vector3Int MAX, Vector2 center, bool CanMoTove = true) { List <Vector3Int> list = new List <Vector3Int>(); for (int i = MIN.y; i <= MAX.y; i++) { for (int j = MIN.x; j <= MAX.x; j++) { Vector3Int position = new Vector3Int(j, i, 0); if (TileCurrent.GetTile(position) == null) { if (CanMoTove) { if (CanMoveTo(center, new Vector2(position.x + 0.5f, position.y + 0.5f))) { ; } { list.Add(position); } } else { list.Add(position); } } } } if (list.Count == 0) { return(center); } int random = Random.Range(0, list.Count); Vector3Int a = list[random]; return((Vector2)((Vector3)a) + new Vector2(0.5f, 0.5f)); }
public static Vector2 GetPositionInGoundCurrent(Vector2Int halfsizeNear, Vector2 center, bool CanMoTo = true) { if (RoundBase.RoundCurrent == null) { Debug.Log("RoundCurrent Is Null"); return(center); } if (TileCurrent == null) { Debug.Log("Tile Current không tồn tại, trả về giá trị mặc định"); return(center); } Vector3Int centerCell = TileCurrent.WorldToCell(center); Vector3Int Min = centerCell - new Vector3Int(halfsizeNear.x - 1, halfsizeNear.y - 1, 0); Vector3Int Max = centerCell + new Vector3Int(halfsizeNear.x, halfsizeNear.y, 0); RoundEnemy.RoundCurrent.Data.GetCellLimit(out Vector2Int MIN, out Vector2Int MAX); MIN.x = Mathf.Max(MIN.x, Min.x); MIN.y = Mathf.Max(MIN.y, Min.y); MAX.x = Mathf.Min(Max.x, MAX.x); MAX.y = Mathf.Min(Max.y, MAX.y); Debug.Log(MIN + "&" + MAX); return(GetPositionInLimit(MIN, MAX, center, CanMoTo)); }