news 2026/4/23 23:00:31

Netcode for GameObjects Boss Room 多人RPG战斗(12)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Netcode for GameObjects Boss Room 多人RPG战斗(12)

ClientCharacter.cs

1. 完整代码

usingSystem;usingUnity.BossRoom.CameraUtils;usingUnity.BossRoom.Gameplay.UserInput;usingUnity.BossRoom.Gameplay.Configuration;usingUnity.BossRoom.Gameplay.Actions;usingUnity.BossRoom.Utils;usingUnity.Netcode;usingUnityEngine;namespaceUnity.BossRoom.Gameplay.GameplayObjects.Character{/// <summary>/// <see cref="ClientCharacter"/> is responsible for displaying a character on the client's screen based on state information sent by the server./// </summary>publicclassClientCharacter:NetworkBehaviour{[SerializeField]Animatorm_ClientVisualsAnimator;[SerializeField]VisualizationConfigurationm_VisualizationConfiguration;/// <summary>/// Returns a reference to the active Animator for this visualization/// </summary>publicAnimatorOurAnimator=>m_ClientVisualsAnimator;/// <summary>/// Returns the targeting-reticule prefab for this character visualization/// </summary>publicGameObjectTargetReticulePrefab=>m_VisualizationConfiguration.TargetReticule;/// <summary>/// Returns the Material to plug into the reticule when the selected entity is hostile/// </summary>publicMaterialReticuleHostileMat=>m_VisualizationConfiguration.ReticuleHostileMat;/// <summary>/// Returns the Material to plug into the reticule when the selected entity is friendly/// </summary>publicMaterialReticuleFriendlyMat=>m_VisualizationConfiguration.ReticuleFriendlyMat;CharacterSwapm_CharacterSwapper;publicCharacterSwapCharacterSwap=>m_CharacterSwapper;publicboolCanPerformActions=>m_ServerCharacter.CanPerformActions;ServerCharacterm_ServerCharacter;publicServerCharacterserverCharacter=>m_ServerCharacter;ClientActionPlayerm_ClientActionViz;PositionLerperm_PositionLerper;RotationLerperm_RotationLerper;// this value suffices for both positional and rotational interpolations; one may have a constant value for eachconstfloatk_LerpTime=0.08f;Vector3m_LerpedPosition;Quaternionm_LerpedRotation;floatm_CurrentSpeed;/// <summary>/// /// Server to Client RPC that broadcasts this action play to all clients./// </summary>/// <param> Data about which action to play and its associated details. </param>[Rpc(SendTo.ClientsAndHost)]publicvoidClientPlayActionRpc(ActionRequestDatadata){ActionRequestDatadata1=data;m_ClientActionViz.PlayAction(refdata1);}/// <summary>/// This RPC is invoked on the client when the active action FXs need to be cancelled (e.g. when the character has been stunned)/// </summary>[Rpc(SendTo.ClientsAndHost)]publicvoidClientCancelAllActionsRpc(){m_ClientActionViz.CancelAllActions();}/// <summary>/// This RPC is invoked on the client when active action FXs of a certain type need to be cancelled (e.g. when the Stealth action ends)/// </summary>[Rpc(SendTo.ClientsAndHost)]publicvoidClientCancelActionsByPrototypeIDRpc(ActionIDactionPrototypeID){m_ClientActionViz.CancelAllActionsWithSamePrototypeID(actionPrototypeID);}/// <summary>/// Called on all clients when this character has stopped "charging up" an attack./// Provides a value between 0 and 1 inclusive which indicates how "charged up" the attack ended up being./// </summary>[Rpc(SendTo.ClientsAndHost)]publicvoidClientStopChargingUpRpc(floatpercentCharged){m_ClientActionViz.OnStoppedChargingUp(percentCharged);}voidAwake(
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/23 18:47:36

21、邮件配置中的重写规则与特殊 m4 配置详解

邮件配置中的重写规则与特殊 m4 配置详解 1. 重写规则理解 重写规则在邮件处理中起着核心作用,它主要用于匹配输入地址并根据特定模式进行重写。下面通过几个测试来详细说明其工作原理。 1.1 模板键值测试 模板使用 @ 加上 $2 的值作为键。例如,当键为 @imaginary.c…

作者头像 李华
网站建设 2026/4/23 13:56:33

多线程相关面试题-线程安全相关问题-锁相关问题

问题 1&#xff1a;什么是进程&#xff1f;什么是线程&#xff1f;二者的核心区别是什么&#xff1f; 问题 2&#xff1a;Java 中创建线程的三种方式是什么&#xff1f;分别举例说明。问题 3&#xff1a;start () 方法和 run () 方法的区别是什么&#xff1f;问题 4&#xff1a…

作者头像 李华
网站建设 2026/4/19 14:56:48

在亚马逊云上解决RDS、MariaDB 与 Aurora MySQL复制延迟实战指南

在高吞吐量的数据库系统中&#xff0c;复制延迟&#xff08;Replica Lag&#xff09;一直是个棘手的难题。在 MySQL 生态圈内&#xff0c;传统的异步复制架构由于其单线程应用事务的性能瓶颈&#xff0c;严重限制了从库&#xff08;Replica&#xff09;的处理能力 (1)。特别是在…

作者头像 李华
网站建设 2026/4/22 7:46:50

Java八股文合集来了,彻底解决一线大厂面试难题

纵观今年的技术招聘市场&#xff0c; Java 依旧是当仁不让的霸主 &#xff01;即便遭受 Go 等新兴语言不断冲击&#xff0c;依旧岿然不动。究其原因&#xff1a; Java 有着极其成熟的生态&#xff0c;这个不用我多说&#xff1b;Java 在 运维、可观测性、可监 控性方面都有着非…

作者头像 李华
网站建设 2026/4/22 19:13:05

5个实用技巧:轻松在Vim中查看文件属性

5个实用技巧&#xff1a;轻松在Vim中查看文件属性 【免费下载链接】vim-galore :mortar_board: All things Vim! 项目地址: https://gitcode.com/gh_mirrors/vi/vim-galore 作为一名Vim用户&#xff0c;你是否曾经需要快速了解文件的修改时间、大小或权限信息&#xff1f…

作者头像 李华
网站建设 2026/4/17 21:59:16

Unity网络请求终极指南:RestClient快速上手与实战技巧

在Unity开发中&#xff0c;处理网络请求是每个开发者都会遇到的挑战。传统的UnityWebRequest虽然功能强大&#xff0c;但代码结构往往复杂冗长。RestClient for Unity应运而生&#xff0c;这款基于Promise的REST和HTTP客户端彻底改变了Unity异步编程的游戏规则&#xff0c;让HT…

作者头像 李华