Hi,
after a request, please find an action that will store the photon players currently in the room in a set of arrayLists.
basically, it expects two list, one to store the players names, one to store their ids. I did it so, because if you only have names, you won't be able to do anything valuable, player's ID is always required for interactivity. I also prefer two arrayList instead of one hashtable because then it can grow and have more entries.
so, on one gameObject, create two arrayList, one named "Photon Player Name", and the other named "Photon Player ID". The action use them names as default, but you can change that if you want. then you simply need to call that action when the player is in a room and choose if you want to list all players, or only other players.
If you have any doubts on how to set it up, let me know.
I don't think I will include this action in the photon bundle, because it would mean shipping arrayMaker too. I might make a additional bundle just for arrayMaker/photon integration.
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.
using UnityEngine;
using System.Collections.Generic;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Photon")]
[Tooltip("Store the list of Photon players in an ArrayList")]
public class ArrayMakerGetPhotonPlayersInRoom : CollectionsActions
{
[ActionSection("Array referencing")]
[RequiredField]
[Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
[CheckForComponent(typeof(PlayMakerArrayListProxy))]
public FsmOwnerDefault gameObject;
[Tooltip("The ArrayList reference that will host the players names")]
public FsmString NameReference;
[Tooltip("The ArrayList reference that will host the players id")]
public FsmString IdReference;
[ActionSection("Options")]
[Tooltip("If true, list only other players.")]
public FsmBool otherPLayerOnly;
private PhotonPlayer[] players;
private string[] playerNames;
public override void Reset()
{
gameObject = null;
otherPLayerOnly = true;
NameReference = "Photon Player Name";
IdReference = "Photon Player ID";
}
public override void OnEnter()
{
if (otherPLayerOnly.Value){
players = PhotonNetwork.otherPlayers;
}else{
players = PhotonNetwork.playerList;
}
//
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
// -------- Player -----------//
// get each arrayList reference
PlayMakerArrayListProxy nameList = GetArrayListProxyPointer(go,NameReference.Value,false);
/*
if (nameList ==null)
{
nameList = go.AddComponent<PlayMakerArrayListProxy>();
nameList.referenceName = "Photon Player Name";
}
*/
PlayMakerArrayListProxy idList = GetArrayListProxyPointer(go,IdReference.Value,false);
/*
if (idList ==null)
{
idList = go.AddComponent<PlayMakerArrayListProxy>();
idList.referenceName = "Photon Player ID";
}
*/
nameList.arrayList.Clear();
idList.arrayList.Clear();
foreach (PhotonPlayer player in players)
{
nameList.arrayList.Add(player.name);
idList.arrayList.Add(player.ID);
}
}
}
}
bye,
Jean