コード例 #1
0
ファイル: GameSave.cs プロジェクト: dihan48/OwlsFlyAway
    public void Save()
    {
        var nextIndexPrefab = _gameWorld.GetNextPrefabIndexs();

        var allCharacters = _characterProvider.GetAllFillPosition();

        SaveCharacter[] allSavedCharacters = new SaveCharacter[allCharacters.Count];

        for (int i = 0; i < allCharacters.Count; i++)
        {
            var x         = allCharacters[i].x;
            var y         = allCharacters[i].y;
            var character = _characterProvider.Get(x, y);

            if (character != null)
            {
                allSavedCharacters[i] = new SaveCharacter()
                {
                    prefabIndex = character.PrefabIndex, x = x, y = y
                };
            }
        }

        Save save = new Save()
        {
            score          = _score.Value,
            allCharacters  = allSavedCharacters,
            nextCharacters = nextIndexPrefab
        };

        string json = JsonUtility.ToJson(save);

        File.WriteAllText(filePath, json);
    }
コード例 #2
0
ファイル: GameWorld.cs プロジェクト: dihan48/OwlsFlyAway
    private void MovedCharacterHandler(Character character, Vector2Int moveTo)
    {
        if (selectedCharacter == character)
        {
            selectedCharacter.OnMoved -= MovedCharacterHandler;
            selectedCharacter.Unselect();
            selectedCharacter = null;
        }

        characterProvider.Move(moveTo, character);

        int countDeleteMatched = matcher.DeleteMatched();

        if (countDeleteMatched == 0)
        {
            RandomSpawn();
        }
        else
        {
            score.Add(countDeleteMatched);
            audioOwlSound.Play();
            if (characterProvider.GetAllFillPosition().Count == 0)
            {
                RandomSpawn();
            }

            saveGame.Save();
            gameWorldInput.enabled = true;
        }
    }
コード例 #3
0
    public void CreatePathMap(Vector2Int position)
    {
        DestroyPathMarkers();

        path.Clear();
        pathlink.Clear();
        open.Clear();
        close.Clear();

        close.AddRange(characterProvider.GetAllFillPosition());

        open.Add(position);

        while (open.Count > 0)
        {
            NodaCheck();
        }

        foreach (var item in path)
        {
            pathMarkers.Add(Instantiate(pathMarker, transform));
            pathMarkers[pathMarkers.Count - 1].transform.localPosition = new Vector3(item.x, item.y, 0);
        }
    }