【问题标题】:How to send struct with Photon如何使用 Photon 发送结构
【发布时间】:2018-04-18 08:14:09
【问题描述】:

我正在为一个学校项目创建一个基于光子的回合制纸牌游戏,但我不知道如何发送结构消息,包括结构卡和手, 谁能解决我的问题?有必要使用 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】:
    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) );
    

    【讨论】:

      猜你喜欢
      • 2011-04-06
      • 2013-11-04
      • 1970-01-01
      • 2019-08-05
      • 2023-01-02
      • 1970-01-01
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多