public override void markAoEPattern(Vector2i root) { TileMarker tileMarker = TileMarker.Instance; //grenade is radius 1, so simply mark the 5 tiles manually rather than iterating if (!tileMarker.attackTiles.ContainsKey(root)) { tileMarker.addAttackTile(root); } if (!tileMarker.attackTiles.ContainsKey(new Vector2i(root.x - 1, root.y))) { tileMarker.addAttackTile(new Vector2i(root.x - 1, root.y)); } if (!tileMarker.attackTiles.ContainsKey(new Vector2i(root.x + 1, root.y))) { tileMarker.addAttackTile(new Vector2i(root.x + 1, root.y)); } if (!tileMarker.attackTiles.ContainsKey(new Vector2i(root.x, root.y - 1))) { tileMarker.addAttackTile(new Vector2i(root.x, root.y - 1)); } if (!tileMarker.attackTiles.ContainsKey(new Vector2i(root.x, root.y + 1))) { tileMarker.addAttackTile(new Vector2i(root.x, root.y + 1)); } }
public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("terrain", _terrain, _terrain.GetType()); info.AddValue("color", $"{TileColor.R},{TileColor.G},{TileColor.B}", typeof(string)); info.AddValue("descr", Descr, Descr.GetType()); info.AddValue("tilemarker", TileMarker, TileMarker.GetType()); }
public DrawableTilePoint() : base(null) { this.Center(); AddInternal(Marker = new TileMarker().Center()); OnNewResult += (x, y) => OnHit(); OnRevertResult += (x, y) => OnRevert(); }
public static TileMarker CreateMarker(TileLayer layer, Texture _outline) { Vector2 _tileSize = new Vector2(); if (layer.usePrefab) { _tileSize = layer.prefabsTileSize[layer.prefabIndex]; } else { _tileSize = layer.tileSize; } GameObject go = new GameObject("Marker"); go.transform.parent = layer.transform; go.transform.localScale = new Vector3(0.5f * _tileSize.y, 0.5f * _tileSize.x, 0.5f); Quaternion quaternion = go.transform.localRotation; quaternion.eulerAngles = new Vector3(0, 180, 90); go.transform.localRotation = quaternion; TileMarker marker = go.AddComponent <TileMarker>(); go.AddComponent <MeshRenderer>(); Material mat = new Material(Shader.Find("2DTile")); go.GetComponent <MeshRenderer>().material = new Material(mat); go.AddComponent <MeshFilter>(); go.GetComponent <MeshFilter>().mesh = NewMesh(); GameObject goOut = new GameObject("Outline"); goOut.transform.parent = layer.transform; goOut.transform.localScale = new Vector3(0.5f * _tileSize.y, 0.5f * _tileSize.x, 0.5f); Quaternion quaternionOut = go.transform.localRotation; quaternionOut.eulerAngles = new Vector3(0, 180, 90); goOut.transform.localRotation = quaternionOut; goOut.AddComponent <MeshRenderer>(); Material matOut = new Material(Shader.Find("2DTile")); goOut.GetComponent <MeshRenderer>().material = new Material(matOut); goOut.GetComponent <MeshRenderer>().sharedMaterial.mainTexture = _outline; goOut.AddComponent <MeshFilter>(); goOut.GetComponent <MeshFilter>().mesh = NewMesh(); goOut.transform.parent = go.transform; goOut.transform.position = new Vector3(go.transform.position.x, go.transform.position.y, -0.1f); go.GetComponent <TileMarker>().outline = goOut; return(marker); }
void OnEnable() { Tools.current = Tool.View; Tools.viewTool = ViewTool.FPS; layer = target as TileLayer; DestroyMarker(); if (boxTex == null) { boxTex = new Texture2D(1, 1); boxTex.SetPixel(0, 0, new Color(0, 0.5f, 1f, 0.4f)); boxTex.Apply(); } if (markerTex == null) { UpdateOutline(Color.black); } marker = TileMarker.CreateMarker(layer, markerTex); if (layer.mat != null) { UpdateMarker(); } if (layer.tiles == null) { GameObject go = new GameObject("Tiles"); go.transform.parent = layer.transform; go.transform.position = new Vector3(0, 0, 0); layer.tiles = go; } if (layer.objects == null) { GameObject go = new GameObject("Objects"); go.transform.parent = layer.transform; go.transform.position = new Vector3(0, 0, 0); layer.objects = go; } }
// marks PURPLE TILES of all possible coverages for selection public override void markAoEAim(Vector2i root) { TileMarker tileMarker = TileMarker.Instance; unit.calcCombatStats(); int range = Mathf.Max((int)(unit.combatEnergyAtk * 0.5f), 3); // minimum beam size is 3x3 (length extendable) // mark left beam for (int i = -1; i <= 1; i++) { if (unit.pos.y + i < 0 || unit.pos.y + i > MapScript.Instance.mapHeight) { continue; // don't process tiles outside of map } for (int j = Mathf.Max(root.x - range, 0); j < root.x; j++) { Vector2i mark = new Vector2i(j, root.y + i); if (mark.Distance(unit.pos) == 2 && mark.x != unit.pos.x && mark.y != unit.pos.y) { if (!tileMarker.attackTiles.ContainsKey(mark)) { //tiles directly diagonal to unit are ambiguous; mark with attack tile instead of AoE tileMarker.addAttackTile(mark); } } else { tileMarker.addAoETile(mark); } } } // mark right beam for (int i = -1; i <= 1; i++) { if (unit.pos.y + i < 0 || unit.pos.y + i > MapScript.Instance.mapHeight) { continue; // don't process tiles outside of map } for (int j = Mathf.Min(root.x + range, MapScript.Instance.mapWidth); j > root.x; j--) { Vector2i mark = new Vector2i(j, root.y + i); if (mark.Distance(unit.pos) == 2 && mark.x != unit.pos.x && mark.y != unit.pos.y) { //tiles directly diagonal to unit are ambiguous; mark with attack tile instead of AoE if (!tileMarker.attackTiles.ContainsKey(mark)) { //tiles directly diagonal to unit are ambiguous; mark with attack tile instead of AoE tileMarker.addAttackTile(mark); } } else { tileMarker.addAoETile(mark); } } } // mark up beam for (int i = -1; i <= 1; i++) // i represents x now instead of y { if (unit.pos.x + i < 0 || unit.pos.x + i > MapScript.Instance.mapWidth) { continue; // don't process tiles outside of map } for (int j = Mathf.Min(root.y + 1, MapScript.Instance.Width); j <= root.y + range; j++) { Vector2i mark = new Vector2i(root.x + i, j); if (mark.Distance(unit.pos) == 2 && mark.x != unit.pos.x && mark.y != unit.pos.y) { if (!tileMarker.attackTiles.ContainsKey(mark)) { //tiles directly diagonal to unit are ambiguous; mark with attack tile instead of AoE tileMarker.addAttackTile(mark); } } else { tileMarker.addAoETile(mark); } } } // mark down beam for (int i = -1; i <= 1; i++) // i represents x now instead of y { if (unit.pos.x + i < 0 || unit.pos.x + i > MapScript.Instance.mapWidth) { continue; // don't process tiles outside of map } for (int j = Mathf.Max(root.y - 1, 0); j >= root.y - range; j--) { Vector2i mark = new Vector2i(root.x + i, j); if (mark.Distance(unit.pos) == 2 && mark.x != unit.pos.x && mark.y != unit.pos.y) { if (!tileMarker.attackTiles.ContainsKey(mark)) { //tiles directly diagonal to unit are ambiguous; mark with attack tile instead of AoE tileMarker.addAttackTile(mark); } } else { tileMarker.addAoETile(mark); } } } }
public override void markAoEPattern(Vector2i root) // root is redundant (always this weapon's unit) { TileMarker tileMarker = TileMarker.Instance; int range = Mathf.Max((int)(unit.combatEnergyAtk * 0.5f), 3); // minimum beam size is 3x3 (length extendable) if (root == new Vector2i(unit.pos.x - 1, unit.pos.y) || unit.pos.x - root.x > 1) { // mark beam to left of unit direction = new Vector2i(-1, 0); root = unit.pos; for (int j = -1; j <= 1; j++) { if (unit.pos.y + j < 0 || unit.pos.y + j > MapScript.Instance.mapHeight) { continue; // don't process tiles outside of map } for (int i = Mathf.Max(root.x - range, 0); i < root.x; i++) { tileMarker.addAttackTile(new Vector2i(i, root.y + j)); } } } else if (root == new Vector2i(unit.pos.x + 1, unit.pos.y) || unit.pos.x - root.x < -1) { // mark beam to right of unit direction = new Vector2i(1, 0); root = unit.pos; for (int j = -1; j <= 1; j++) { if (unit.pos.y + j < 0 || unit.pos.y + j > MapScript.Instance.mapHeight) { continue; // don't process tiles outside of map } for (int i = Mathf.Min(root.x + range, MapScript.Instance.mapHeight); i > root.x; i--) { tileMarker.addAttackTile(new Vector2i(i, root.y + j)); } } } else if (root == new Vector2i(unit.pos.x, unit.pos.y + 1) || unit.pos.y - root.y < -1) { // mark beam above unit direction = new Vector2i(0, 1); root = unit.pos; for (int j = -1; j <= 1; j++) { if (unit.pos.x + j < 0 || unit.pos.x + j > MapScript.Instance.mapWidth) { continue; // don't process tiles outside of map } for (int i = Mathf.Min(root.y + range, MapScript.Instance.mapHeight); i > root.y; i--) { tileMarker.addAttackTile(new Vector2i(root.x + j, i)); } } } else if (root == new Vector2i(unit.pos.x, unit.pos.y - 1) || unit.pos.y - root.y > 1) { // mark beam below unit direction = new Vector2i(0, -1); root = unit.pos; for (int j = -1; j <= 1; j++) { if (unit.pos.x + j < 0 || unit.pos.x + j > MapScript.Instance.mapHeight) { continue; // don't process tiles outside of map } for (int i = Mathf.Max(root.y - range, 0); i < root.y; i++) { tileMarker.addAttackTile(new Vector2i(root.x + j, i)); } } } }
public override void markAoEPattern(Vector2i root) // root is redundant (always this weapon's unit) { TileMarker tileMarker = TileMarker.Instance; //mark all diagonal tiles from unit Vector2i curr = new Vector2i(unit.pos.x - 1, unit.pos.y + 1); // up left while (curr.x >= 0 && curr.y < MapScript.Instance.mapHeight) { if (curr.Distance(unit.pos) > max) { // keep track of maximum distance attack max = curr.Distance(unit.pos); } tileMarker.addAttackTile(curr); curr.x--; curr.y++; } // up right curr = new Vector2i(unit.pos.x + 1, unit.pos.y + 1); while (curr.x < MapScript.Instance.mapWidth && curr.y < MapScript.Instance.mapHeight) { if (curr.Distance(unit.pos) > max) { // keep track of maximum distance attack max = curr.Distance(unit.pos); } tileMarker.addAttackTile(curr); curr.x++; curr.y++; } // down left curr = new Vector2i(unit.pos.x - 1, unit.pos.y - 1); while (curr.x >= 0 && curr.y >= 0) { if (curr.Distance(unit.pos) > max) { // keep track of maximum distance attack max = curr.Distance(unit.pos); } tileMarker.addAttackTile(curr); curr.x--; curr.y--; } // down right curr = new Vector2i(unit.pos.x + 1, unit.pos.y - 1); while (curr.x < MapScript.Instance.mapWidth && curr.y >= 0) { if (curr.Distance(unit.pos) > max) { // keep track of maximum distance attack max = curr.Distance(unit.pos); } tileMarker.addAttackTile(curr); curr.x++; curr.y--; } }