A class in Root.Township, the global namespace.
Writes and reads an entity's position and rotation for the network, optionally relative to a moving context such as a cart or boat it stands on. PositionSerializer<T> adds a typed FixParent.
Constructors
Fields
| Member | What it is |
|---|
Vector3 position | Last world position written or received. |
Quaternion rotation | Last world rotation written or received. |
protected bool isContextChanged | Set on read when the context changed from the previous one. |
protected Transform lastContextParent | The transform FixParent last parented to. |
7 private and internal fields
| Member | What it is |
|---|
private IMovementContext context | Backing field for Context. |
private NetworkEntity entity | The entity whose position this serializes. |
private MemoizeOne<uint, IMovementContext> getContext | Caches the last id to context lookup. |
private static readonly Vector3 LocalMaximum | Upper bound (100 on each axis) for the position sent relative to a movement context. |
private static readonly Vector3 LocalMinimum | Lower bound (-100 on each axis) for the position sent relative to a movement context. |
private Vector3 localPosition | Position relative to the movement context. |
private Quaternion localRotation | Rotation relative to the movement context. |
Properties
| Member | What it is |
|---|
IMovementContext Context { get; set; } | The moving object the entity is positioned relative to, or null. Cleared if that object is destroyed. |
Vector3 LivePosition { get; } | World position, worked out from the context's current transform when there is one. |
Quaternion LiveRotation { get; } | World rotation, worked out from the context's current transform when there is one. |
Methods
| Member | What it is |
|---|
void FixParent(Transform targetTransform) | Parents the transform to the context's transform, or unparents it when the context goes away. |
void ForceRemotePosition(Vector3 position) | Sets the stored world position and updates the context-local copy to match. |
void ForceRemoteRotation(Quaternion rotation) | Sets the stored world rotation and updates the context-local copy to match. |
void Serialize(Stream stream) | Writes or reads position, rotation and the context id plus local offset. Readers that aren't authoritative pick up the new context. |
2 private and internal methods
| Member | What it is |
|---|
private IMovementContext GetContext(uint id) | Finds the movement context of the entity with an id. Returns null for 0 or a missing entity. |
private void RemoveContext(NetworkEntity entity, bool isUnload) | Clears the context when its entity is destroyed. |
Used in
Members of other types that take, return or hold a PositionSerializer: