Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
    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));
                }
            }
        }
    }
Exemplo n.º 3
0
    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);
    }
Exemplo n.º 4
0
    //Constructor AKA Set up Data
    public Foot_Soldier()
    {
        Class = UnitClass.Foot_Soldier;

        TileType[] additional = { TileType.River };
        Walkable.AddRange(additional);
    }
Exemplo n.º 5
0
 public void AddWalkablePath(Walkable walkable)
 {
     if (!m_possiblePaths.Contains(walkable))
     {
         m_possiblePaths.Add(walkable);
     }
 }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
    public Block(Vector2 location, Walkable identity, Area area) : this()
    {
        this.identity.Add(identity);

        this.location = location;
        this.area     = area;
    }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
    public BuildingBlock(Vector2 location, Walkable identity, Area area) : base(location, identity, area)
    {
        this.landlords = null;
        this.building  = null;

        pathLocations = new List <Vector3>();
    }
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
 public virtual Dictionary <string, string> ToDictionary()
 {
     return(new Dictionary <string, string>
     {
         { "row", Row.ToString() },
         { "col", Col.ToString() },
         { "walkable", Walkable.ToString() }
     });
 }
Exemplo n.º 13
0
    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>();
        }
    }
Exemplo n.º 14
0
 public void UpdateColor(Walkable isWalkable)
 {
     if (isWalkable == Walkable.Passable)
     {
         rend.material.color = defaultColor;
     }
     else
     {
         rend.material.color = Color.red;
     }
 }
Exemplo n.º 15
0
    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);
            }
        }
    }
Exemplo n.º 17
0
    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;
    }
Exemplo n.º 19
0
    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);
    }
Exemplo n.º 20
0
    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);
    }
Exemplo n.º 21
0
    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);
            }
        }
    }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        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;
            }
        }
Exemplo n.º 24
0
        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;
            }
        }
Exemplo n.º 25
0
    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]);
            }
        }
    }
Exemplo n.º 26
0
    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");
            }
        }
    }
Exemplo n.º 27
0
    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();
                    }
                }
            }
        }
    }
Exemplo n.º 28
0
    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);
    }
Exemplo n.º 29
0
    // 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);
    }
Exemplo n.º 30
0
    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");
        }
    }
Exemplo n.º 31
0
 // Use this for initialization
 void Start()
 {
     walkable = GetComponent <Walkable>();
 }
Exemplo n.º 32
0
        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);
        }
Exemplo n.º 33
0
 public Node(int x, int y, Walkable walkable)
     : this(x, y, 0, walkable)
 {
 }