PlayerNetworkEntity
public abstract class PlayerNetworkEntity : DirectionalNetworkEntity
{
public int playerID = -1;
public string playerName = "";
//different skins/characters
public int currentSkin = 0;
public List<AnimationComponent> skins;//change which one the character points to out of these using currentSkin
public AnimationComponent animationComponent;
public HPComponent hpComponent;
public GameObject ghostPos;
public Text nameText;
public static System.Random r = new System.Random();
//...
Currently the engine is built around identifying a PlayerNetworkEntity to work out which entities to run inputs for on both client and server side. It is recommended to extend this class so you can add whatever features are relevant to your player characters. The example project fills in the rest of the logic in CyborgPlayer
A client will press buttons and those are actioned on their local controlled PlayerNetworkEntity via client side prediction, these inputs are then relayed to the server with their playerID and processed there to ensure inputs are legal.
NOTE: Client side prediction is a prediction and can be found to be false, which the server will correct the client on.
Methods
public bool IsMyPlayer()
Since this is an online game, the client is likely to see other PlayerNetworkEntities walking around representing other players. This function checks to see if this is the current one we are controlling.
public void MoveToRandomSpawnPoint()
Called when a PlayerNetworkEntity respawns. It looks through the spawn locations and picks one randomly.
public void WriteToPacket(NetDataWriter writer, bool fullWrite)
This WriteToPacket overloaded method is unique to PlayerNetworkEntity.The player you control on the client needs extra information to about itself from the server to accurately calculate client side prediction, whereas other players on the server we need fewer details as we're trying to lerp them for smooth movement instead. So fullWrite is for sending data about a PlayerNetworkEntity to its owning client, and an abridged writeToPacket to others. Override this method in child classes, see CyborgPlayer as reference
public void ChangeSkin(int skin)
Example has a couple of different sets of animations representing character skin alternatives, this method helps switch between them.
public void ChangeName(string name)
Updates the text above the characters head