public void WriteXml(XmlWriter writer) { writer.WriteAttributeString("Type", Type.ToString()); writer.WriteAttributeString("X", X.ToString()); writer.WriteAttributeString("Y", Y.ToString()); writer.WriteAttributeString("Walkable", Walkable.ToString()); }
private void OnDrawGizmos() { Gizmos.DrawWireCube(transform.position, new Vector3(worldSize.x, 1, worldSize.y)); if (grid != null) { Walkable playerWalkable = walkableFromWorldPos(target); foreach (Walkable n in grid) { if (n == playerWalkable) { Gizmos.color = Color.yellow; Gizmos.DrawCube(n.worldPos, Vector3.one * (walkableDiameter - .1f)); } if (path != null && path.Contains(n)) { Gizmos.color = Color.blue; Gizmos.DrawCube(n.worldPos, Vector3.one * (walkableDiameter - .1f)); } else { Gizmos.color = n.walkable ? Color.green : Color.red; Gizmos.DrawCube(n.worldPos, Vector3.one * (walkableDiameter - .1f)); } } } }
public List <Walkable> getNeighbours(Walkable walkable) { List <Walkable> neighbours = new List <Walkable>(); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (x == 0 && y == 0) { continue; } int checkX, checkY; checkX = walkable.gridX + x; checkY = walkable.gridY + y; if (checkX >= 0 && checkX < gridSizeX && checkY >= 0 && checkY < gridSizeY) { neighbours.Add(grid[checkX, checkY]); } } } return(neighbours); }
//Constructor AKA Set up Data public Foot_Soldier() { Class = UnitClass.Foot_Soldier; TileType[] additional = { TileType.River }; Walkable.AddRange(additional); }
public void AddWalkablePath(Walkable walkable) { if (!m_possiblePaths.Contains(walkable)) { m_possiblePaths.Add(walkable); } }
static void Main(string[] args) { // Creating a human Human baby = new Boy("Stamat"); Console.WriteLine(baby.Introduce()); Console.WriteLine(new string('-', 60)); // Human is learning to walk var walkableBaby = new Walkable(baby); Console.WriteLine(walkableBaby.Introduce()); Console.WriteLine(new string('-', 60)); // Human is learning to talk var talkableBaby = new Talkable(walkableBaby); Console.WriteLine(talkableBaby.Introduce()); Console.WriteLine(new string('-', 60)); // Human is learning to eat by it's self var selfFeedableBaby = new SelfFeedable(talkableBaby); Console.WriteLine(selfFeedableBaby.Introduce()); Console.WriteLine(new string('-', 60)); }
public Block(Vector2 location, Walkable identity, Area area) : this() { this.identity.Add(identity); this.location = location; this.area = area; }
public Node(int x, int y, int size, Walkable walkable) { mapXPosition = x; mapYPosition = y; this.walkable = walkable; rect = new Rectangle(x*size, y*size, size, size); }
public Node(int x, int y, int size, Walkable walkable) { mapXPosition = x; mapYPosition = y; this.walkable = walkable; rect = new Rectangle(x * size, y * size, size, size); }
public BuildingBlock(Vector2 location, Walkable identity, Area area) : base(location, identity, area) { this.landlords = null; this.building = null; pathLocations = new List <Vector3>(); }
public Node(Walkable _walkable, Vector3 _worldPos, int _gridX, int _gridY, float _height, int _penalty) { walkable = _walkable; worldPosition = _worldPos; gridX = _gridX; gridY = _gridY; height = _height; movementPenalty = _penalty; }
public virtual Dictionary <string, string> ToDictionary() { return(new Dictionary <string, string> { { "row", Row.ToString() }, { "col", Col.ToString() }, { "walkable", Walkable.ToString() } }); }
private void GetCurrentCube() { Ray ray = new Ray(m_playerTransform.position, -transform.up); RaycastHit raycastHit; if (Physics.Raycast(ray, out raycastHit, Mathf.Infinity, m_walkableMask)) { m_currentCube = raycastHit.transform.GetComponent <Walkable>(); } }
public void UpdateColor(Walkable isWalkable) { if (isWalkable == Walkable.Passable) { rend.material.color = defaultColor; } else { rend.material.color = Color.red; } }
private void Awake() { SceneManager.sceneLoaded += OnSceneLoaded; var spawnPoint = GetComponentInChildren <PlayerSpawnPoint>().transform; spawnPosition = spawnPoint.position; spawnRotation = spawnPoint.rotation; _walkable = GetComponent <Walkable>(); }
// 경로 생성 private void BuildPath() { Transform cube = clickedCube; // 클릭한 큐브가 현재큐브와 같지 않을 때까지 while (cube != currentCube) { // 실제 이동할 경로에 삽입 finalPath.Add(cube); // 클릭한 큐브의 이전큐브가 None일 때 if (cube.GetComponent <Walkable>().previousBlock != null) { cube = cube.GetComponent <Walkable>().previousBlock; } else { break; } } if (finalPath.Count > 0) { bool walk = false; for (int i = 0; i < currentCube.GetComponent <Walkable>().possiblePaths.Count; i++) { WalkPath walkCube = currentCube.GetComponent <Walkable>().possiblePaths[i]; if (walkCube.target.Equals(finalPath[finalPath.Count - 1]) && walkCube.active) { walk = true; break; } } if (!walk) { finalPath.Clear(); } else { pastCube = currentCube.GetComponent <Walkable>(); nextCube = finalPath[finalPath.Count - 1].GetComponent <Walkable>(); transform.LookAt(nextCube.GetWalkPoint()); timing = 0; anim.SetBool("Walking", true); } } }
private int getDistance(Walkable walkableA, Walkable walkableB) { int disX, disY; disX = Mathf.Abs(walkableA.gridX - walkableB.gridX); disY = Mathf.Abs(walkableA.gridY - walkableB.gridY); if (disX > disY) { return(14 * disY + 10 * (disX - disY)); } return(14 * disX + 10 * (disY - disX)); }
void FollowPath() { if (finalPath.Count == 0) { return; } // 타일을 체크하여 플레이어 레이어 설정 LayerCheck(nextCube.transform); // 보간 적용 transform.position = Vector3.Lerp(pastCube.GetWalkPoint(), nextCube.GetWalkPoint(), timing); // 다음 경로 설정 if (timing >= 1.0f) { timing = 0; pastCube = finalPath.Last().GetComponent <Walkable>(); finalPath.Last().GetComponent <Walkable>().previousBlock = null; finalPath.RemoveAt(finalPath.Count - 1); if (finalPath.Count > 0) { nextCube = finalPath.Last().GetComponent <Walkable>(); if (!currentCube.GetComponent <Walkable>().dontRotate) { transform.LookAt(nextCube.GetWalkPoint()); } return; } else { LayerCheck(nextCube.transform); anim.SetBool("Walking", false); if (currentCube.Equals(GameManager.instance.clearCube)) { anim.SetBool("Clear", true); GameManager.instance.Clear = true; } } } timing += Time.deltaTime * moveSpeed; }
private void Clear() { Moving = false; if (m_path != null) { for (int i = 0; i < m_path.Count; i++) { m_path[i].PreviousWalkable = null; } m_path = null; } m_currentCube = m_clickedCube; transform.SetParent(m_currentCube.transform); }
private List <Walkable> getPath(Walkable endWalkable) { List <Walkable> path = new List <Walkable>(); Walkable currentWalkable = endWalkable; while (currentWalkable.parent != null) { path.Add(currentWalkable); currentWalkable = currentWalkable.parent; } path.Reverse(); return(path); }
private void createGrid() { grid = new Walkable[gridSizeX, gridSizeY]; Vector3 bottomLeft = transform.position - Vector3.right * worldSize.x / 2 - Vector3.forward * worldSize.y / 2; for (int x = 0; x < gridSizeX; x++) { for (int y = 0; y < gridSizeY; y++) { Vector3 worldPoint = bottomLeft + Vector3.right * (x * walkableDiameter + walkableRadius) + Vector3.forward * (y * walkableDiameter + walkableRadius); bool walkable = !Physics.CheckSphere(worldPoint, walkableRadius, wallMask); grid[x, y] = new Walkable(walkable, worldPoint, x, y); } } }
public void should_walk() { var node1 = new Walkable(); var node2 = new Walkable { Parent = node1 }; var node3 = new Walkable { Parent = node2 }; var result = node3.Walk(x => x.Parent).ToList(); result.ShouldTotal(3); result[0].ShouldEqual(node3); result[1].ShouldEqual(node2); result[2].ShouldEqual(node1); }
public PathNode(int x, int y, int size, Walkable walkable) { mapXPosition = x; mapYPosition = y; this.walkable = walkable; rect = new Rectangle(x * size, y * size, size, size); switch (walkable) { case Walkable.Walkable: state = NodeState.Unknown; break; case Walkable.Blocked: state = NodeState.Closed; break; } }
public void FromNode(Node node) { mapXPosition = node.MapXPosition; mapYPosition = node.MapYPosition; this.walkable = node.Walkable; int size = node.Rectangle.Width; rect = new Rectangle(mapXPosition * size, mapYPosition * size, size, size); switch (walkable) { case Walkable.Walkable: state = NodeState.Unknown; break; case Walkable.Blocked: state = NodeState.Closed; break; } }
void CreateGrid() { grid = new Node[gridSizeX, gridSizeY]; Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2; for (int x = 0; x < gridSizeX; x++) { for (int y = 0; y < gridSizeY; y++) { Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius); bool walkable = !(Physics.CheckSphere(worldPoint, nodeRadius * checkRadiusModifier, unwalkableMask)); int movementPenalty = 0; float height = 0; // raycast if (walkable) { Ray ray = new Ray(worldPoint + Vector3.up * 50, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, walkableMask)) { // Determine the movement penalty of the terrain type walkableRegionsDictionary.TryGetValue(hit.collider.gameObject.layer, out movementPenalty); // Get the height of a block worldPoint.y = height = (hit.transform.position.y + hit.collider.bounds.extents.y); } } Walkable walkableEnum = Walkable.Passable; if (!walkable) { walkableEnum = Walkable.Impassable; } //worldPoint.y = Mathf.Clamp(worldPoint.y, 0.1f, Mathf.Infinity); grid[x, y] = new Node(walkableEnum, worldPoint, x, y, height, movementPenalty); DrawGrid(grid[x, y]); } } }
private void OnGUI() { GUILayout.Label("Drag an object with a walkable component and click bake to bake its nodes"); source = (Walkable)EditorGUILayout.ObjectField(source, typeof(Walkable), true); if (source != null) { if (GUILayout.Button("Bake")) { Debug.Log("Baking begun"); source.Bake(); Debug.Log("Baking finished"); } if (GUILayout.Button("Clear")) { source.Clear(); Debug.Log("Navigation cleared"); } } }
private void TouchRaycast(Vector3 mousePosition) { if (!Moving && !Rotator.Rotating) { var screenRay = m_camera.ScreenPointToRay(mousePosition); RaycastHit touchRaycastHit; if (Physics.Raycast(screenRay, out touchRaycastHit, Mathf.Infinity, m_walkableMask)) { var walkable = touchRaycastHit.transform.GetComponent <Walkable>(); if (walkable) { m_path = PathFinder.FindPath(m_currentCube, walkable); if (m_path.Count > 0) { m_clickedCube = walkable; FollowPath(); } } } } }
public static List <Walkable> FindPath(Walkable start, Walkable end) { List <Walkable> path = new List <Walkable>(); List <Walkable> previousWalkables = new List <Walkable>(); List <Walkable> nextWalkables = new List <Walkable>(); bool pathFound = false; if (CalculatePathsFromCurrent(start, nextWalkables, previousWalkables, end)) { pathFound = true; } else { while (nextWalkables.Count > 0) { var currentWalkable = nextWalkables[0]; nextWalkables.RemoveAt(0); if (CalculatePathsFromCurrent(currentWalkable, nextWalkables, previousWalkables, end)) { pathFound = true; break; } } } if (pathFound) { var currentWalkable = end; path.Add(end); while (currentWalkable.PreviousWalkable != start) { currentWalkable = currentWalkable.PreviousWalkable; path.Insert(0, currentWalkable); } } return(path); }
// returns true if current contains goes to end walkable private static bool CalculatePathsFromCurrent(Walkable current, List <Walkable> next, List <Walkable> previousWalkables, Walkable end) { bool containsEndWalkable = false; var possiblePaths = current.PossiblePaths; for (int i = 0; i < possiblePaths.Count; i++) { if (!previousWalkables.Contains(possiblePaths[i])) { next.Add(possiblePaths[i]); possiblePaths[i].PreviousWalkable = current; if (possiblePaths[i] == end) { containsEndWalkable = true; // no need to continue searching anymore break; } } } previousWalkables.Add(current); return(containsEndWalkable); }
public Group(Skill skill, Actor[] actors, Attributes attributes, Resource resource, Vector3 location, int currentBlockIndex, Direction enterDirection) { this.state = PlayerState.Normal; this.identity = Walkable.Human; this.skill = skill; this.actors = actors; this.currentActor = 0; this.attributes = attributes; this.resource = resource; this.location = location; this.currentBlockIndex = currentBlockIndex; this.startBlockIndex = currentBlockIndex; this.enterDirection = enterDirection; this.scout = new Scout(this); this.inJailTime = 0; if (playerBuildingList == null) { playerBuildingList = new GameObject("PlayerBuildingList"); } }
// Use this for initialization void Start() { walkable = GetComponent <Walkable>(); }
public void should_walk() { var node1 = new Walkable(); var node2 = new Walkable { Parent = node1 }; var node3 = new Walkable { Parent = node2 }; var result = node3.Walk(x => x.Parent).ToList(); result.ShouldTotal(3); result[0].ShouldEqual(node3); result[1].ShouldEqual(node2); result[2].ShouldEqual(node1); }
public Node(int x, int y, Walkable walkable) : this(x, y, 0, walkable) { }