Unity-Technologies / Unity-Technologies/com.unity.netcode.gameobjects

ClientRpc and ServerRpc decorators should give an error if attached to a non-NetworkBehaviour class method

未关闭
#1,911 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Tracking type:feature
主要语言
C#
星标
2.3k
派生
461
平均合并
3 天 16 小时
30 天内合并 PR
20

描述

Is your feature request related to a problem? Please describe.
I'm finding it easy to accidentally add [ClientRpc] or [ServerRpc] methods to MonoBehaviour-derived classes, where clearly they won't do anything. This leads to a bunch of confusion while I try to figure out what's wrong with the networking only to do the forehead-slap when I notice that the class hasn't been switched to NetworkBehaviour.

Describe the solution you'd like
At a minimum, a runtime error with a descriptive error message would be helpful. Something like "FooClientRpc was added to a class that doesn't derive from NetworkBehaviour - as a result, FooClientRpc will never be called."

Better would be a similar error logged when in the editor. Compile-time errors would be ideal if possible, of course.

Describe alternatives you've considered
Beyond "vigilance" (which can be assumed doesn't work), if it becomes a more serious issue then I'd have to rig some sort of linting rule to catch this.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

该 issue 没有指出文件、测试或入口点。首先定位 ClientRpc 和 ServerRpc 装饰器的处理方式,以及如何检查 NetworkBehaviour 继承关系;为不继承自 NetworkBehaviour 的类中的方法定义并测试一项诊断,同时包含所请求的运行时或编辑器行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp
领域
networking
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。