2
0

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.

ClientNetworkTransformが見つからない【Netcode for GameObjects】

Posted at

経緯

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を使おうと思っている人はちょっとだけ目を通すと幸せになれるかも

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?