Exemplo n.º 1
0
    public float UpdateScore(string scoreType, string playerGuid, float value, ScoreSetType setType = ScoreSetType.delta)
    {
        // Returns the new assigned value

        // Create the dictionary key if it doesn't exist
        if (!this.scoreList.ContainsKey(scoreType))
        {
            this.scoreList[scoreType] = new Dictionary <string, float>();
        }

        float newValue = -1;

        if (setType == ScoreSetType.delta)
        {
            float beforeValue = 0;
            this.scoreList[scoreType].TryGetValue(playerGuid, out beforeValue);

            newValue = beforeValue + value;
        }
        else        //(setType == ScoreSetType.absolute)
        {
            newValue = value;
        }

        this.scoreList[scoreType][playerGuid] = newValue;

        // Fire the event
        //Debug.Log("Firing Score Updated Event");
        ScoreData scoreData = new ScoreData();

        scoreData.scoreType = scoreType;
        scoreData.guid      = playerGuid;
        scoreData.value     = newValue;
        this.OnScoreUpdated(this, new ScoreActivityEventArgs(scoreData));

        // Tell the others the score
        if (Network.isServer)
        {
            networkView.RPC("RPCUpdateScore", RPCMode.OthersBuffered, scoreType, playerGuid, newValue);
        }

        return(newValue);
    }
Exemplo n.º 2
0
	public float UpdateScore(string scoreType, string playerGuid, float value, ScoreSetType setType = ScoreSetType.delta) 
	{
		// Returns the new assigned value

		// Create the dictionary key if it doesn't exist
		if(!this.scoreList.ContainsKey(scoreType))
			this.scoreList[scoreType] = new Dictionary<string, float>();

		float newValue = -1;
		if(setType == ScoreSetType.delta)
		{
			float beforeValue = 0;
			this.scoreList[scoreType].TryGetValue(playerGuid, out beforeValue);

			newValue = beforeValue + value;
		}
		else//(setType == ScoreSetType.absolute)
		{
			newValue = value;
		}

		this.scoreList[scoreType][playerGuid] = newValue;

		// Fire the event
		//Debug.Log("Firing Score Updated Event");
		ScoreData scoreData = new ScoreData();
		scoreData.scoreType = scoreType;
		scoreData.guid = playerGuid;
		scoreData.value = newValue;
		this.OnScoreUpdated(this, new ScoreActivityEventArgs(scoreData));

		// Tell the others the score
		if(Network.isServer)
			networkView.RPC("RPCUpdateScore", RPCMode.OthersBuffered, scoreType, playerGuid, newValue);

		return newValue;
	}