如何使用Photon发送struct

时间:2018-04-18 08:14:10

标签: c# serialization deserialization photon

我正在为一个学校项目创建一个基于回合的纸牌游戏,但是如何发送结构信息,包括结构卡和手, 有谁能解决我的问题?是否必须使用Photon.RegysterType()?我试图找到一些东西,但我找不到多少,而光子文档关于使用Photon.RegysterType()自定义类型的序列化我不太了解。

感谢答案:)

结构列表:

struct card
{
     internal string suit;
     internal string value;
}

struct Hand
{
     internal card[] hand;
     internal bool[] FinishedCards;
}

struct Message
{
     internal Hand Local, Remote;
     internal List Table, Deck;
     internal List StackLocal, StackRemote;
}

1 个答案:

答案 0 :(得分:0)

Here is one way:
    [Serializable]
    struct card
    {
         public string suit;
         public string value;
    }

    [Serializable]
    struct Hand
    {
         public card[] hand;
         public bool[] FinishedCards;
    }

    [Serializable]
    struct Message
    {
         public Hand Local, Remote;
         public List<card> Table, Deck;
         public List<card> StackLocal, StackRemote;
    }
...
view.RPC(nameof(RPCAcceptHand),Photon.Pun.RpcTarget.All,JsonUtility.ToJson(m) );