4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

(2023/02/08)PhotonFusionにおける公式ドキュメントの間違いについて

Last updated at Posted at 2023-02-07
  • PhotonFusionのチュートリアルにおけるこちらの公式ドキュメント https://doc.photonengine.com/ja-jp/fusion/current/fusion-100/fusion-102 (現在2023/02/08)がそのまま書いても動作しないので備忘録
  • 1.INetworkRunnerCallbaksインターフェイスをクラスに追加する際、OnInputメソッドとOnHostMigrationメソッドも実装しなければならない。正しくは以下
public class BasicSpawner : MonoBehaviour, INetworkRunnerCallbacks
{
  public void OnPlayerJoined(NetworkRunner runner, PlayerRef player)    {    }
  public void OnPlayerLeft(NetworkRunner runner, PlayerRef player)    {    }
  public void OnInputMissing(NetworkRunner runner, PlayerRef player, NetworkInput input) { }
  public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason) { }
  public void OnConnectedToServer(NetworkRunner runner) { }
  public void OnDisconnectedFromServer(NetworkRunner runner) { }
  public void OnConnectRequest(NetworkRunner runner, NetworkRunnerCallbackArgs.ConnectRequest request, byte[] token) { }
  public void OnConnectFailed(NetworkRunner runner, NetAddress remoteAddress, NetConnectFailedReason reason) { }
  public void OnUserSimulationMessage(NetworkRunner runner, SimulationMessagePtr message) { }
  public void OnSessionListUpdated(NetworkRunner runner, List<SessionInfo> sessionList) { }
  public void OnCustomAuthenticationResponse(NetworkRunner runner, Dictionary<string, object> data) { }
  public void OnReliableDataReceived(NetworkRunner runner, PlayerRef player, ArraySegment<byte> data) { }
  public void OnSceneLoadDone(NetworkRunner runner) { }
  public void OnSceneLoadStart(NetworkRunner runner) { }

  //ここが必要!
  public void OnInput(NetworkRunner runner, NetworkInput input) { }
  public void OnHostMigration(NetworkRunner runner, HostMigrationToken token) { }
}
  • またStartGameArgsに定義されているメンバ変数はObjectSceneProviderではなくSceneManagerである
async void StartGame(GameMode mode)
    {
        // Create the Fusion runner and let it know that we will be providing user input
        _runner = gameObject.AddComponent<NetworkRunner>();
        _runner.ProvideInput = true;

        // Start or join (depends on gamemode) a session with a specific name
        await _runner.StartGame(new StartGameArgs()
        {
            GameMode = mode,
            SessionName = "TestRoom",
            Scene = SceneManager.GetActiveScene().buildIndex,

            //ここが変更!
            SceneManager = gameObject.AddComponent<NetworkSceneManagerBase>()
        });
    }
  • さらにPlayer関数を書く際、NetwowrkCharacterControllerで入力を受け渡しているが、これは非推奨であり、正しくはNetworkCharacterControllerPrototypeでなければならない。
public class Player : NetworkBehaviour
{
    //ここが変更!
    private NetworkCharacterControllerPrototype _cc;
    private void Awake()
    {
        //ここが変更!
        _cc = GetComponent<NetworkCharacterControllerPrototype>();
    }
    public override void FixedUpdateNetwork()
    {
        if (GetInput(out NetworkInputData data))
        {
            data.direction.Normalize();
            _cc.Move(5 * data.direction * Runner.DeltaTime);
        }
    }
}

このとき、アタッチするコンポーネントもNetworkCharacterControllerPrototypeにすることを忘れないこと。

  • なお1,2番目は日本語・英語ドキュメント両方で間違っており、3番目は日本語ドキュメントのみ間違っている。うまくいかないときは英語ドキュメントをまず調べることも重要そうだ
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?