예제 #1
0
    private void NodaCheck()
    {
        List <Vector2Int> dirVectors = new List <Vector2Int> {
            Vector2Int.right, Vector2Int.left, Vector2Int.up, Vector2Int.down
        };

        foreach (var item in dirVectors)
        {
            Vector2Int vector = open[0] + item;

            if (characterProvider.IsExistsPosition(vector) && characterProvider.Get(vector.x, vector.y) == null)
            {
                if (close.IndexOf(vector) == -1)
                {
                    if (path.IndexOf(vector) == -1)
                    {
                        path.Add(vector);
                        pathlink.Add(open[0]);
                        open.Add(vector);
                    }
                }
            }
        }

        close.Add(open[0]);
        open.RemoveAt(0);
    }
예제 #2
0
    public void SelectPosition(Vector2Int position)
    {
        if (characterProvider.IsExistsPosition(position) == false)
        {
            return;
        }

        var character = characterProvider.Get(position.x, position.y);

        if (character != null)
        {
            if (selectedCharacter != character)
            {
                if (selectedCharacter != null)
                {
                    selectedCharacter.OnMoved -= MovedCharacterHandler;
                    selectedCharacter.Unselect();
                }

                selectedCharacter = character;
                selectionSound.Play();
                character.Select();
                var pos = Vector2Int.RoundToInt(character.transform.localPosition);
                pathFinder.CreatePathMap(pos);
            }
        }
        else if (selectedCharacter != null && pathFinder.IsInPathMap(position))
        {
            selectionSound.Play();
            gameWorldInput.enabled = false;
            pathFinder.DestroyPathMarkers();
            var startPosition = Vector2Int.RoundToInt(selectedCharacter.transform.localPosition);
            var path          = pathFinder.GetPath(startPosition, position);

            selectedCharacter.OnMoved += MovedCharacterHandler;
            selectedCharacter.StartMove(path);
        }
    }