如何使用Photon发送struct

问题描述 投票:1回答:1

我正在为一个学校项目创建一个基于回合的纸牌游戏,但是idk如何发送结构信息,包括结构卡和手,任何人都可以解决我的问题?是否必须使用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;
}
c# serialization deserialization photon
1个回答
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) );
© www.soinside.com 2019 - 2024. All rights reserved.