Exemplo n.º 1
0
    void GetSpawnPoints()
    {
        lastGameData = gameData.Clone();

        //Determine spawn-points based on the number of players
        float xPos   = charactersTransform.position.x - maxSpawnDistance;
        float offset = 2 * maxSpawnDistance / (nbOfPlayers + 1);

        for (int i = 1; i <= nbOfPlayers; i++)
        {
            xPos += offset;
            GameObject spawn = Instantiate(charactersTransform.gameObject);
            spawn.transform.position = charactersTransform.position + new Vector3(xPos, 0, 0);

            spawnPoints.Add(spawn.transform);
        }

        //Spawn a player on each spawn point and set their UI up
        int index = 0;

        foreach (JSONNode ID in gameData["Players"].Keys)
        {
            Transform t = spawnPoints[index];

            t.SetParent(charactersTransform);
            GameObject     character      = Instantiate(characterPrefab, t);
            PlayersManager playersManager = character.GetComponent <PlayersManager>();

            playersManager.playerID      = ID.Value;
            playersManager.nameText.text = "Name: " + gameData["Players"][ID.Value]["name"].Value;

            //Save to which transform the player ID is linked to becuase Dictionnaries are nor ordered
            getPlayerSpawn[ID.Value] = playersManager;

            index++;
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Loops through all children of a JSON object, and remove any that are null or empty.
    /// This help makes _customData objects compliant with BeatSaver schema in a reusable and smart way.
    /// </summary>
    /// <param name="obj">Object of which to loop through and remove all empty children from.</param>
    private JSONNode CleanObject(JSONNode obj)
    {
        if (obj is null)
        {
            return(null);
        }
        JSONNode clone = obj.Clone();

        foreach (string key in clone.Keys)
        {
            if (obj.HasKey(key) && (obj[key].IsNull || obj[key].AsArray?.Count <= 0 || string.IsNullOrEmpty(obj[key].Value)))
            {
                obj.Remove(key);
            }
        }
        return(obj);
    }