【问题标题】:Photon, how to sync image and text via PhotonView or RPC?Photon,如何通过 PhotonView 或 RPC 同步图像和文本?
【发布时间】:2022-08-14 07:04:53
【问题描述】:

我有一个 TextField,我需要为所有玩家显示它,还有一个包含非静态图像的字段也应该同步。我读到这可以通过 RPS 完成,但我没有找到专门针对我的问题的明确指南。

  • RPC 是完成此任务的最简单方法。对于文本,只需创建一个接受字符串的 RPC 函数。对于图像,创建一个接受某种标识符的 RPC 函数,您可以使用该标识符来查找图像。在 RPC 函数中,您希望分别使用对 Image 组件和 TextField 组件的引用在本地显示项目。
  • @hijinxbassist <code>使用 System.Collections;使用 System.Collections.Generic;使用 UnityEngine;使用 UnityEngine.UI;使用 Photon.Pun;使用 Photon.Realtime;公共类同步:MonoBehaviourPunCallbacks { 公共 PhotonView 视图;公共文本文本游戏; void Start() { view = GetComponent<PhotonView>(); } [PunRPC] public void ViewAll() { textGame.gameObject.SetActive(true); } void Update() { view.RPC(\"ViewAll\", RpcTarget.All); } } <code> 像这样?
  • 请使用您的问题的具体细节编辑您的问题。上面的代码没有做任何事情,所以我怀疑这就是你想要的。不要像那样在 Update 中运行 RPC,这样做没有意义,并且会导致大量不必要的网络流量。
  • 公共 PhotonView 视图;公共文本文本游戏;公共文本已复制; void Awake() { view = GetComponent<PhotonView>(); } public void sync() { if (view.IsMine) { view.RPC(\"ViewAll\", RpcTarget.All, textGame.text); } } [PunRPC] public void ViewAll(Text tG) { tG.text =copyed.text;我做了,但它不起作用。我需要将文本字段从线索同步到玩家
  • 您不能发送文本组件,但是可以发送字符串。 ViewAll(string text) { localTextComponent.text = text; }

标签: unity3d synchronization multiplayer photon


【解决方案1】:

我解决了这个问题,文本可以传输光子,但图像不能,您只需创建一个函数并在其中抛出一个字符串或 TEXT 文本,您还应该对对象有一个光子视图。

public PhotonView view;
public Text textGame;
public Text copied;

void Awake()
{
    view = GetComponent<PhotonView>();
    
}

public void sync()
{
  view.RPC("ViewAll", RpcTarget.All, textGame.text);   
}

[PunRPC]
public void ViewAll(string tg)
{
   copied.text = tg;

}[enter image description here][1]

https://i.stack.imgur.com/8skzD.png 图像通过 Photon Transform View 传递其坐标

【讨论】:

    猜你喜欢
    • 2014-11-25
    • 1970-01-01
    • 2012-02-10
    • 2012-05-15
    • 2015-06-10
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多