コード例 #1
0
ファイル: UIRoomView.cs プロジェクト: Solestis/SpyGameUnity5
 /// <summary>
 /// On recieving a mission through the PhotonNetwork, configure the newMissionWindow and activate the newMissionButton, both linked in Editor.
 /// </summary>
 /// <param name="missionData"></param>
 private void OnMissionRecieved(ExitGames.Client.Photon.Hashtable missionData)
 {
     object value;
     if (missionData.TryGetValue("missionTitle", out value))
     {
         newMissionWindow.titleText.text = value as string;
     }
     if (missionData.TryGetValue("missionDescription", out value))
     {
         newMissionWindow.descriptionText.text = value as string;
     }
     newMissionButton.gameObject.SetActive(true);
 }
コード例 #2
0
ファイル: Assignment.cs プロジェクト: Solestis/SpyGameUnity5
    /// <summary>
    /// Initializes a new instance of the <see cref="Assignment"/> class. Retrieves and deletes the target location and description from data. The remainder of data is saved as typeData.
    /// </summary>
    /// <param name="sequenceN">The sequence number of the assignment.</param>
    /// <param name="type">The type of assignment, must correspond with and assignment scene.</param>
    /// <param name="data">Hashtable containing the rest of the assignment data, including type specific data.</param>
    public Assignment(int sequenceN, string type, ExitGames.Client.Photon.Hashtable data = null)
    {
        assignmentType = type;
        sequenceNumber = sequenceN;

        assignmentState = Assignment.STATE_NEW;

        if (data != null)
        {
            object value;
            if (data.TryGetValue("missionDescription", out value))
            {
                description = (string)value;
                data.Remove("missionDescription");
            }
            typeData = data;
        }
    } 
コード例 #3
0
ファイル: vp_MPMaster.cs プロジェクト: Bakiet/EvilAwakening
	/// <summary>
	/// dumps a game state hashtable to the console
	/// </summary>
	public static void DumpGameState(ExitGames.Client.Photon.Hashtable gameState)
	{

		string s = "--- GAME STATE ---\n(click to view)\n\n";

		if (gameState == null)
		{
			Debug.Log("DumpGameState: Passed gamestate was null: assembling full gamestate.");
			gameState = AssembleGameState();
		}

		foreach (object key in gameState.Keys)
		{
			if (key.GetType() == typeof(int))
			{
				object player;
				gameState.TryGetValue(key, out player);
				s += vp_MPNetworkPlayer.GetName((int)key) + ":\n";

				foreach (object o in ((ExitGames.Client.Photon.Hashtable)player).Keys)
				{
					s += "\t\t" + (o.ToString()) + ": ";
					object val;
					((ExitGames.Client.Photon.Hashtable)player).TryGetValue(o, out val);
					s += val.ToString().Replace("(System.String)", "") + "\n";
				}
			}
			else
			{
				object val;
				gameState.TryGetValue(key, out val);
				s += key.ToString() + ": " + val.ToString();
			}
			s += "\n";
		}

		UnityEngine.Debug.Log(s);

	}
コード例 #4
0
ファイル: vp_MPMaster.cs プロジェクト: Bakiet/EvilAwakening
	protected virtual void ReceivePlayerState(ExitGames.Client.Photon.Hashtable gameState, PhotonMessageInfo info)
	{

		//Debug.Log("GOT PLAYER STATE!");

		if ((info.sender != PhotonNetwork.masterClient) ||
			(info.sender.isLocal))
			return;

		// -------- refresh stats of all included players --------

		foreach (vp_MPNetworkPlayer player in vp_MPNetworkPlayer.Players.Values)
		{

			if (player == null)
				continue;

			object stats;
			if (gameState.TryGetValue(player.ID, out stats) && (stats != null))
				player.Stats.SetFromHashtable((ExitGames.Client.Photon.Hashtable)stats);
			//else
			//    vp_MPDebug.Log("Failed to extract player " + player.ID + " stats from gamestate");

		}

		// -------- refresh all teams --------

		if(vp_MPTeamManager.Exists)
			vp_MPTeamManager.Instance.RefreshTeams();

	}
コード例 #5
0
ファイル: vp_MPMaster.cs プロジェクト: Bakiet/EvilAwakening
	protected virtual void ReceiveGameState(ExitGames.Client.Photon.Hashtable gameState, PhotonMessageInfo info)
	{

		//vp_MPDebug.Log("GOT FULL GAMESTATE!");

		//DumpGameState(gameState);

		if ((info.sender != PhotonNetwork.masterClient) ||
			(info.sender.isLocal))
			return;

		//vp_MPDebug.Log("Gamestate updated @ " + info.timestamp);
		//Debug.Log("Gamestate updated @ " + info.timestamp);

		// -------- extract game phase, game time and duration --------

		// TODO: make generic method 'ExtractStat' that does this
		object phase;
		if ((gameState.TryGetValue("Phase", out phase) && (phase != null)))
			Phase = (GamePhase)phase;

		object timeLeft;
		object duration;
		if ((gameState.TryGetValue("TimeLeft", out timeLeft) && (timeLeft != null))
			&& (gameState.TryGetValue("Duration", out duration) && (duration != null)))
			vp_MPClock.Set((float)timeLeft, (float)duration);

		// -------- instantiate missing player prefabs --------

		vp_MPPlayerSpawner.Instance.InstantiateMissingPlayerPrefabs(gameState);
		
		// -------- refresh stats of all players --------

		ReceivePlayerState(gameState, info);

		// -------- refresh health of all non-player damage handlers --------

		foreach (vp_DamageHandler d in vp_DamageHandler.Instances.Values)
		{
			if (d == null)
				continue;
			if (d is vp_PlayerDamageHandler)
				continue;
			PhotonView p = d.GetComponent<PhotonView>();
			if (p == null)
				continue;
			object currentHealth;
			if (gameState.TryGetValue(-p.viewID, out currentHealth) && (currentHealth != null))
			{
				d.CurrentHealth = (float)currentHealth;
				if (d.CurrentHealth <= 0.0f)
					vp_Utility.Activate(d.gameObject, false);
			}
			else
				vp_MPDebug.Log("Failed to extract health of damage handler " + p.viewID + " from gamestate");
		}

		// -------- disable any pickups noted as currently disabled in the state --------

		//vp_MPDebug.Log("DISABLED PICKUPS: " + vp_MPPickupManager.Instance.Pickups.Keys.Count);

		foreach (int id in vp_MPPickupManager.Instance.Pickups.Keys)
		{

			List<vp_ItemPickup> p;
			vp_MPPickupManager.Instance.Pickups.TryGetValue(id, out p);
			if ((p == null) || (p.Count < 1) || p[0] == null)
				continue;

			object isDisabled;
			if (gameState.TryGetValue(id, out isDisabled) && (isDisabled != null))
				vp_Utility.Activate(p[0].transform.gameObject, false);

		}
		
		// -------- refresh all teams --------

		if(vp_MPTeamManager.Exists)
			vp_MPTeamManager.Instance.RefreshTeams();

	}
コード例 #6
0
	/// <summary>
	/// extracts a value from a provided player state hashtable given
	/// its string name
	/// </summary>
	public static object GetFromHashtable(ExitGames.Client.Photon.Hashtable hashTable, string stat)
	{
		m_Stat = null;
		hashTable.TryGetValue(stat, out m_Stat);
		return m_Stat;
	}
コード例 #7
0
	/// <summary>
	/// given a full game state, this method instantiates any 'missing'
	/// player prefabs, that is: players spawned by RPC from a previous
	/// master that would otherwise be invisible (non-existant) to players
	/// having joined post a master client handover. by default this is
	/// called from 'vp_MPMaster -> SyncGameState'
	/// </summary>
	public void InstantiateMissingPlayerPrefabs(ExitGames.Client.Photon.Hashtable gameState)
	{

		// fetch all photonviews	// TODO: optimize?
		PhotonView[] views = Component.FindObjectsOfType(typeof(PhotonView)) as PhotonView[];

		foreach (object o in gameState.Keys)
		{
			//Debug.Log("3: " + o.ToString());

			if (o.GetType() != typeof(int))
				continue;
			//Debug.Log("4 GAME STATE PLAYER -> " + o.ToString());

			int id = (int)o;
			bool hasView = false;
			foreach (PhotonView f in views)
			{
				//Debug.Log("5: " + f.ToString());

				if (f.ownerId == id)
					hasView = true;
			}
			if (hasView)
				continue;
			//Debug.Log("6: NEED TO SPAWN PLAYER -> " + o.ToString());

			object pp;
			if (!gameState.TryGetValue(o, out pp))
			{
				//Debug.Log("failed to get hashtable for player " + o.ToString());
				continue;
			}
			ExitGames.Client.Photon.Hashtable playerStats = pp as ExitGames.Client.Photon.Hashtable;
			if (playerStats == null)
			{
				//Debug.Log("failed to get hashtable for player " + o.ToString());
				continue;
			}

			PhotonPlayer player = vp_MPPlayerSpawner.GetPhotonPlayerById(id);
			if (player == null)
			{
				//Debug.Log("failed to get photonplayer by id");
				continue;
			}

			vp_MPPlayerSpawner.InstantiatePlayerPrefab(player, playerStats);

		}

	}