简体   繁体   English

Unity Photon room.SetCustomProperties无法正常工作

[英]Unity Photon room.SetCustomProperties Not Working

According to what I looked up online, most of the examples take in one parameter which is a single Hashtable . 根据我在网上查找的内容,大多数示例都采用一个参数,即一个Hashtable However, I kept getting an error saying there is no overload method that takes only one argument. 但是,我不断收到一个错误消息,说没有仅使用一个参数的重载方法。 It requires three. 它需要三个。 This is the example I came up with but I still get an error saying it has invalid arguments. 这是我想出的示例,但是仍然出现错误,指出它具有无效的参数。

How do I use room.SetCustomProperties ? 我如何使用room.SetCustomProperties

public void PlacingStone ()
{
    Hashtable setPlacingStone = new Hashtable {{ RoomProperties.PlacingStone, true }};
    Hashtable currentValues = new Hashtable {{ RoomProperties.PlacingStone,
    (bool) PhotonNetwork.room.customProperties [ RoomProperties.PlacingStone ] }};
    PhotonNetwork.room.SetCustomProperties ( setPlacingStone, currentValues, true );

    StartCoroutine ( "WaitOnStone" );
}

Your problem is that you are trying to use multiple hashtables. 您的问题是您正在尝试使用多个哈希表。 You can add different things to hashtables by doing: 您可以通过执行以下操作将不同的东西添加到哈希表中:

PhotonNetwork.room.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { 
    { RoomProperties.PlacingStone, true }, { RoomProperties.PlacingStone,
    (bool) PhotonNetwork.room.customProperties [ RoomProperties.PlacingStone ] } });

or 要么

Hashtable t = new Hashtable();
t.Add(RoomProperties.PlacingStone, true);
t.Add(RoomProperties.PlacingStone, (bool) PhotonNetwork.room.customProperties [ RoomProperties.PlacingStone ] );
PhotonNetwork.room.SetCustomProperties(t);

Thanks! 谢谢! The problem was the Photon Hashtables. 问题出在光子哈希表上。 I need to use those as you said and I also added using Hashtable = ExitGames.Client.Photon.Hashtable; 我需要使用您所说的那些,并且还使用Hashtable = ExitGames.Client.Photon.Hashtable; at the top of the page to make it easier. 在页面顶部以使其更容易。

using Hashtable = ExitGames.Client.Photon.Hashtable;

public void SetProperties () {
  Hashtable setPlacingStone = new Hashtable {{ RoomProperties.PlacingStone, true }

PhotonNetwork.room.SetCustomProperties ( setPlacingStone );

    StartCoroutine ( "WaitOnStone" );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM