news 2026/4/18 10:12:50

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/18 3:12:17

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

com.unity.multiplayer.samples.coop-2.5.0\Assets\Scripts\Gameplay\GameplayObjects\Character\AI 1. 系统概述 AI系统是一个基于状态机的智能体控制系统,主要用于处理游戏中NPC角色的行为逻辑,包括空闲状态、攻击状态等。系统采用了组件化架构,与服务器端角色逻辑紧密集…

作者头像 李华
网站建设 2026/4/18 8:00:26

Azure智能搜索双引擎:从检索规划到深度推理的企业级实践

Azure智能搜索双引擎&#xff1a;从检索规划到深度推理的企业级实践 【免费下载链接】azure-search-openai-demo A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure AI Search for retrieval and Azure OpenAI large language model…

作者头像 李华
网站建设 2026/4/18 8:30:47

面试数据库八股文十问十答第五期

面试数据库八股文十问十答第五期 作者&#xff1a;程序员小白条&#xff0c;个人博客 1&#xff09;介绍一下 MySQL8 的新特性 Window Functions&#xff1a; 提供了对查询结果进行窗口化处理的功能&#xff0c;例如使用 ROW_NUMBER() 进行分页。Common Table Expressions (CT…

作者头像 李华
网站建设 2026/4/18 5:42:08

Avue.js实战指南:数据驱动型企业级应用开发新范式

Avue.js实战指南&#xff1a;数据驱动型企业级应用开发新范式 【免费下载链接】avue &#x1f525;Avue.js是基于现有的element-plus库进行的二次封装&#xff0c;简化一些繁琐的操作&#xff0c;核心理念为数据驱动视图,主要的组件库针对table表格和form表单场景&#xff0c;同…

作者头像 李华
网站建设 2026/4/18 3:18:33

openEuler系统下安装MongoDB的技术教程

你需要一份在openEuler系统下安装MongoDB的技术教程&#xff0c;我会按照环境准备→安装部署→配置启动→功能验证的流程&#xff0c;提供详细且可直接操作的步骤&#xff0c;同时覆盖开源版MongoDB&#xff08;社区版&#xff09;的核心配置要点。 一、环境说明 系统版本&…

作者头像 李华
网站建设 2026/4/18 5:09:24

Venture:构建复杂异步工作流的Laravel神器

Venture&#xff1a;构建复杂异步工作流的Laravel神器 【免费下载链接】venture Venture allows you to create and manage complex, async workflows in your Laravel apps. 项目地址: https://gitcode.com/gh_mirrors/ve/venture 在当今的Web开发中&#xff0c;处理复…

作者头像 李华