news 2026/7/1 21:06:19

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/24 19:56:30

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

ActionPlayers ActionPlayers是Boss Room项目中负责管理和执行动作(Action)的核心组件,分为客户端和服务器端两个版本,分别处理动作的视觉表现和逻辑执行。 1. 系统架构 1.1 核心组件 组件 职责 位置 ClientActionPlayer 客户端动作可视化与生命周期管理 Assets/Scripts/G…

作者头像 李华
网站建设 2026/6/26 22:09:10

深度学习优化器算法巧思速览

1. 为什么要研究优化器算法&#xff1f;它的关联问题&#xff1a;训练为什么要调参&#xff0c;调的是什么参&#xff1f;如果就这个问题去问各种大语言模型&#xff0c;它们能给出一堆的理由。但就博主而言&#xff0c;答案只有一个&#xff1a;干掉调参&#xff0c;解放生产力…

作者头像 李华
网站建设 2026/7/1 17:29:30

macOS上优雅运行Docker容器

什么是colimacolima主页Colima&#xff08;Container on Lima&#xff09;是一个轻量级的容器运行时管理工具&#xff0c;专为macOS&#xff08;同时也支持Linux&#xff09;设计&#xff0c;提供了一种简单优雅的方式来运行容器。它基于Lima项目&#xff0c;后者为macOS提供了…

作者头像 李华
网站建设 2026/7/1 11:15:03

XXL-JOB分布式任务调度

1.什么是任务调度 简单说&#xff1a;按照指定的规则&#xff08;时间、频率、条件&#xff09;自动执行某个任务&#xff0c;不需要人工手动触发。比如&#xff1a; 每天凌晨 2 点执行数据备份&#xff1b;每 5 分钟检查一次接口可用性&#xff1b;订单支付超时&#xff08;30…

作者头像 李华
网站建设 2026/7/1 18:11:26

MYSQL与B+树与索引相关面试题

第一题&#xff08;基础&#xff09;&#xff1a;请简述 MySQL 中索引底层为什么选择 B 树&#xff0c;而不是 B 树、红黑树等其他数据结构&#xff1f;第二题&#xff08;基础进阶&#xff09;&#xff1a;MySQL 中聚簇索引和非聚簇索引的区别是什么&#xff1f;它们的叶子节…

作者头像 李华
网站建设 2026/6/26 16:21:43

PostgreSQL pgvector扩展Windows环境完整安装指南

PostgreSQL pgvector扩展Windows环境完整安装指南 【免费下载链接】pgvector Open-source vector similarity search for Postgres 项目地址: https://gitcode.com/GitHub_Trending/pg/pgvector 在人工智能应用日益普及的今天&#xff0c;向量相似性搜索已成为现代数据库…

作者头像 李华