経緯
https://www.youtube.com/watch?v=GRUtGLL8iMQ&t=52s&ab_channel=UnityJapan
UnityJapanの解説動画(39:00~)で使われているClientNetworkTransformが見つからない
動画内ではNetcode for GameObjectsのパッケージにサンプルとしてインポート出来ていた
解決
com.unity.multiplayer.samples.coop
上記のパッケージに入っていた
どうやらサンプル周りは全部ここに移動したらしい
[github] https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop
ClientNetworkTransformって何をやってるの?
中身のコードはこれだけ
using Unity.Netcode.Components;
using UnityEngine;
namespace Unity.Multiplayer.Samples.Utilities.ClientAuthority
{
/// <summary>
/// Used for syncing a transform with client side changes. This includes host. Pure server as owner isn't supported by this. Please use NetworkTransform
/// for transforms that'll always be owned by the server.
/// </summary>
[DisallowMultipleComponent]
public class ClientNetworkTransform : NetworkTransform
{
/// <summary>
/// Used to determine who can write to this transform. Owner client only.
/// This imposes state to the server. This is putting trust on your clients. Make sure no security-sensitive features use this transform.
/// </summary>
protected override bool OnIsServerAuthoritative()
{
return false;
}
}
}
NetworkTransformのOnIsServerAuthoritative()
をoverrideするだけでいいらしい
コメントでもある通り、クライアントを信用して同期するためセキュリティを重視する部分では使わないほうがいい
https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/develop/com.unity.netcode.gameobjects/Components/NetworkTransform.cs
上記のURLがNetworkTransformのコード
2680行目から該当のメソッドがある
その他
com.unity.multiplayer.samples.coop
にはClientNetworkAnimatorも入っている
そちらもやっていることは同じ
また、UnityRelayUtilities.csはRelayを使う際にすごく参考になった
これからRelayを使おうと思っている人はちょっとだけ目を通すと幸せになれるかも