Esempio n. 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag != "enemy")
        {
            return;
        }
        gm.GetComponent <WaveHandler>().resetCurrentEnemyOnKill(collision.gameObject);
        health -= 1;
        if (health <= 0)
        {
            for (int i = 0; i < gm.GetComponent <WaveHandler>().allEnemies.Count; i++)
            {
                Destroy(gm.GetComponent <WaveHandler>().allEnemies[i]);
            }
            for (int i = 0; i < gm.GetComponent <GameStateHandler>().currentWave.Count; i++)
            {
                Destroy(gm.GetComponent <GameStateHandler>().currentWave[i]);
            }
            gm.GetComponent <WaveHandler>().allEnemies.Clear();
            gm.GetComponent <GameStateHandler>().currentWave.Clear();
            gm.GetComponent <GameStateHandler>().waveNumber = 0;
            gm.GetComponent <TwitterManagerScript>().currentGameUserJSON = null;
            gameUserJSON  = null;
            followerCount = 0;


            Invoke("switchSceneToStart", 0.5f);
        }
    }
Esempio n. 2
0
 public void clearContent()
 {
     health        = 3;
     gameUserJSON  = null;
     followerCount = 0;
     userName      = "";
 }
    void handleJSONFile(FriendsIds _friendsIds, FriendUsers _friendUsers)
    {
        bool userExisted = true;

        if (!File.Exists(userJSONFilePath))
        {
            //create a new JSON file to edit and write the basic structure to it.
            string starterJSONText      = "{\"ids\": {}, \"users\": {}, \"lastAccess\": {}}";
            byte[] starterJSONByteArray = System.Text.Encoding.ASCII.GetBytes(starterJSONText);
            logHandler.writeToLog("creating new file: " + userJSONFilePath, Color.green);
            File.WriteAllBytes(userJSONFilePath, starterJSONByteArray);
            userExisted = false;
        }

        string       dataAsJson    = File.ReadAllText(userJSONFilePath);
        GameUserJSON _gameUserJSON = JsonUtility.FromJson <GameUserJSON>(dataAsJson);

        _gameUserJSON.ids   = _friendsIds;
        _gameUserJSON.users = _friendUsers;

        if (!userExisted)
        {
            _gameUserJSON.lastAccess = System.DateTime.Now.ToString();
        }


        currentGameUserJSON = _gameUserJSON;
        GetComponent <GameStateHandler>().player.GetComponent <Player>().gameUserJSON  = currentGameUserJSON;
        GetComponent <GameStateHandler>().player.GetComponent <Player>().followerCount = _friendsIds.ids.Count;
        dataAsJson = JsonUtility.ToJson(_gameUserJSON);
        File.WriteAllText(userJSONFilePath, dataAsJson);
        GetComponent <JSONEnemyHandler>().loadJSONDataToEnemies(currentGameUserJSON);
        //write back to the file path the modified gameUserJSON
    }
 public void loadJSONDataToEnemies(GameUserJSON baseJSON)
 {
     for (int i = 0; i < baseJSON.ids.ids.Count; i++)
     {
         GameObject newEnemyGO = Instantiate(enemy);
         newEnemyGO.transform.position = new Vector3(0, 0, 0);
         newEnemyGO.SetActive(false);
         newEnemyGO.hideFlags = HideFlags.HideInHierarchy;
         StartCoroutine(fetchImageFromURL(baseJSON.users.items[i].profile_image_url.Replace("_normal", ""),
                                          baseJSON.users.items[i], newEnemyGO));
         GetComponent <WaveHandler>().allEnemies.Add(newEnemyGO);
     }
 }
    private void populateContentContainer()
    {
        for (int i = 0; i < previousJSONFiles.Length; i++)
        {
            GameObject newExistingUser = Instantiate(existingUserTextGO, contentContainer.transform, false);
            string     userName        = Path.GetFileName(previousJSONFiles[i]).Replace(".json", "");
            string     lastAccessDate  = File.GetLastAccessTime(previousJSONFiles[i]).ToString();

            string       dataAsJson   = File.ReadAllText(previousJSONFiles[i]);
            GameUserJSON gameUserJSON = JsonUtility.FromJson <GameUserJSON>(dataAsJson);

            newExistingUser.GetComponent <PreviousUserButtonScript>().assocUserName = userName;
            newExistingUser.GetComponentInChildren <Text>().text = userName + " - " + gameUserJSON.lastAccess;
        }
    }
    public void onUserSelected(string _userName)
    {
        //JSONEnemyHelperGO.GetComponent<JSONEnemyHandler>().loadJSONDataToEnemies(currentGameUserJSON);
        logHandler.writeToLog(_userName + " is being loaded up...", Color.blue);
        userJSONFilePath = Path.Combine(Application.streamingAssetsPath, _userName + ".json");

        //if we are not in debug mode, check if there is a JSON file already created, default to
        //use the most recently made JSON file
        if (!debugMode)
        {
            //create and set the player to the precreated JSON data
            if (File.Exists(userJSONFilePath))
            {
                string       dataAsJson    = File.ReadAllText(userJSONFilePath);
                GameUserJSON _gameUserJSON = JsonUtility.FromJson <GameUserJSON>(dataAsJson);
                handleJSONFile(_gameUserJSON.ids, _gameUserJSON.users);
            }
            //if not, then just make a new JSON file from loading
            else
            {
                updateJSONFile(_userName);
            }
        }
        //if it is in debug mode...
        else
        {
            if (File.Exists(userJSONFilePath))
            {
                string       dataAsJson    = File.ReadAllText(userJSONFilePath);
                GameUserJSON _gameUserJSON = JsonUtility.FromJson <GameUserJSON>(dataAsJson);
                handleJSONFile(_gameUserJSON.ids, _gameUserJSON.users);
            }
            else
            {
                logHandler.writeToLog("Tried to access " + userJSONFilePath + " but it did not exsist", Color.red);
            }
        }
    }