public static Cell GetCell(Vector3 pos) { var tilePos = Iso.Snap(pos); int index = instance.MapToIndex(tilePos); return(instance.map[index]); }
public static int OverlapBox(Vector2 center, Vector2 size, GameObject[] result) { int count = 0; if (result.Length == 0) { return(0); } int rows = Mathf.RoundToInt(size.y); int columns = Mathf.RoundToInt(size.x); int index = instance.MapToIndex(Iso.Snap(center - size / 2)); for (int row = 0; row < rows; ++row) { for (int column = 0; column < columns; ++column) { var gameObject = instance.map[index + column].gameObject; if (gameObject != null) { result[count] = gameObject; count += 1; if (count >= result.Length) { return(count); } } } index += instance.width; } return(count); }
void Update() { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePosition = Iso.MapToIso(mousePos); mouseTile = Iso.Snap(mousePosition); }
public static List <Step> BuildPath(Vector2 from_, Vector2 target_, float minRange = 0.1f, int size = 2, GameObject self = null, int depth = 100) { UnityEngine.Profiling.Profiler.BeginSample("BuildPath"); Vector2i from = Iso.Snap(from_); target = Iso.Snap(target_); path.Clear(); if (from == target) { UnityEngine.Profiling.Profiler.EndSample(); return(path); } openNodes.Clear(); Node.Recycle(closeNodes); Pathing.size = size; Pathing.self = self; Node startNode = Node.Get(); startNode.parent = null; startNode.pos = from; startNode.gScore = 0; startNode.hScore = Vector2i.manhattanDistance(from, target); startNode.score = int.MaxValue; startNode.directionIndex = -1; openNodes.Add(startNode); closeNodes.Add(startNode); int iterCount = 0; Node bestNode = startNode; while (openNodes.Count > 0) { Node node = openNodes.Take(); if (node.hScore < bestNode.hScore) { bestNode = node; } if (node.hScore <= minRange) { TraverseBack(node); break; } StepTo(node); iterCount += 1; if (iterCount > depth) { TraverseBack(bestNode); break; } } //foreach (Node node in closeNodes) //{ // Iso.DebugDrawTile(node.pos, Color.magenta, 0.3f); //} //foreach (Node node in openNodes) //{ // Iso.DebugDrawTile(node.pos, Color.green, 0.3f); //} UnityEngine.Profiling.Profiler.EndSample(); return(path); }
public static void SetBlocked(Vector3 pos, CollisionLayers value) { SetBlocked(Iso.Snap(pos), value); }
public static bool Passable(Vector3 pos, CollisionLayers mask, int size = 1, GameObject ignore = null) { return(Passable(Iso.Snap(pos), mask, size, ignore)); }
private int MapToIndex(Vector3 pos) { return(MapToIndex(Iso.Snap(pos))); }
public static void SetPassable(Vector3 pos, int sizeX, int sizeY, bool passable, GameObject gameObject) { SetPassable(Iso.Snap(pos), sizeX, sizeY, passable, gameObject); }