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(