news 2026/6/9 21:23:33

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/6/9 15:02:19

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

1. 系统概述 Boss Room项目采用了基于Unity Gaming Services (UGS) Lobby服务的房间管理系统,结合自定义的连接管理框架,实现了完整的房间创建、加入、管理和销毁功能。系统支持两种连接方式:直接IP连接和通过Relay服务的网络连接。 2. 核心组件架构 2.1 连接管理层 Con…

作者头像 李华
网站建设 2026/6/9 16:10:58

OpenUSD工具链:从入门到精通的实用指南

OpenUSD工具链&#xff1a;从入门到精通的实用指南 【免费下载链接】OpenUSD Universal Scene Description 项目地址: https://gitcode.com/GitHub_Trending/ope/OpenUSD OpenUSD工具链作为Universal Scene Description生态系统的重要组成部分&#xff0c;为开发者提供了…

作者头像 李华
网站建设 2026/6/8 19:40:44

2025终极Valetudo兼容指南:50+款扫地机器人完全解析

2025终极Valetudo兼容指南&#xff1a;50款扫地机器人完全解析 【免费下载链接】Valetudo Cloud replacement for vacuum robots enabling local-only operation 项目地址: https://gitcode.com/gh_mirrors/va/Valetudo 在智能家居蓬勃发展的今天&#xff0c;云端依赖已…

作者头像 李华
网站建设 2026/6/9 16:12:32

Orleans分布式追踪方案深度对比:Jaeger vs Zipkin实战指南

Orleans分布式追踪方案深度对比&#xff1a;Jaeger vs Zipkin实战指南 【免费下载链接】orleans dotnet/orleans: Orleans是由微软研究团队创建的面向云应用和服务的分布式计算框架&#xff0c;特别适合构建虚拟 actor模型的服务端应用。Orleans通过管理actors生命周期和透明地…

作者头像 李华
网站建设 2026/6/8 19:30:59

运维工程师技术教程之ELK日志监控

ELK&#xff08;现在通常称为 Elastic Stack&#xff0c;加入 Beats 后扩展为 ELKB&#xff09;在运维工作中使用非常广泛&#xff0c;是企业级日志管理、监控告警、故障排查的主流开源解决方案&#xff0c;尤其是在中大型互联网公司、云原生架构、分布式系统的运维场景中&…

作者头像 李华