Size: 84
Comment:
|
Size: 1642
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
在这里详述 UE4-Networking-And-Multiplayer/MultiplayerProgrammingQuickStart。 | [[https://docs.unrealengine.com/en-US/InteractiveExperiences/Networking/QuickStart/index.html | 原文]] * How to add replication to a base Actor [[#1]] * How to take advantage of '''Movement Components''' in a network game [[#2]] * How to add replication to '''variables''' [[#1]] * How to use '''!RepNotifies''' when a variable changes [[#4]] * How to use '''Remote Procedure Calls (RPCs)''' in C++ [[#5]] * How to check an Actor's '''Network Role''' in order to filter calls that are performed within a function [[#6]] = How to add replication to a base Actor = <<Anchor(#1)>> {{{#!highlight C++ //////////////////////////// // ThirdPersonMPCharacter.h //////////////////////////// /** The player's current health. When reduced to 0, they are considered dead.*/ UPROPERTY(ReplicatedUsing=OnRep_CurrentHealth) float CurrentHealth; /** RepNotify for changes made to current health.*/ UFUNCTION() void OnRep_CurrentHealth(); /** Property replication */ void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override; }}} {{{#!highlight C++ //////////////////////////// // ThirdPersonMPCharacter.cpp //////////////////////////// ////////////////////////////////////////////////////////////////////////// // Replicated Properties void AThirdPersonMPCharacter::GetLifetimeReplicatedProps(TArray <FLifetimeProperty> & OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); //Replicate current health. DOREPLIFETIME(AThirdPersonMPCharacter, CurrentHealth); } }}} = How to use '''!RepNotifies''' when a variable changes = |
How to add replication to a base Actor #1
How to take advantage of Movement Components in a network game #2
How to add replication to variables #1
How to use RepNotifies when a variable changes #4
How to use Remote Procedure Calls (RPCs) in C++ #5
How to check an Actor's Network Role in order to filter calls that are performed within a function #6
How to add replication to a base Actor
1 ////////////////////////////
2 // ThirdPersonMPCharacter.h
3 ////////////////////////////
4 /** The player's current health. When reduced to 0, they are considered dead.*/
5 UPROPERTY(ReplicatedUsing=OnRep_CurrentHealth)
6 float CurrentHealth;
7
8 /** RepNotify for changes made to current health.*/
9 UFUNCTION()
10 void OnRep_CurrentHealth();
11
12 /** Property replication */
13 void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
1 ////////////////////////////
2 // ThirdPersonMPCharacter.cpp
3 ////////////////////////////
4
5 //////////////////////////////////////////////////////////////////////////
6 // Replicated Properties
7
8 void AThirdPersonMPCharacter::GetLifetimeReplicatedProps(TArray <FLifetimeProperty> & OutLifetimeProps) const
9 {
10 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
11
12 //Replicate current health.
13 DOREPLIFETIME(AThirdPersonMPCharacter, CurrentHealth);
14 }