Photon Quantum 3.0.0

Classes | Public Member Functions | Public Attributes | Protected Member Functions | Properties | List of all members
Quantum.QuantumEntityView Class Reference

The Quantum entity view component is the representation of the entity inside Unity. Instances will be created by the EntityViewUpdater. Quantum entity with the View component will references a Quantum EntityView asset which will in turn be instantiated as EntityView.Prefab and the resulting game object includes this script. More...

Inheritance diagram for Quantum.QuantumEntityView:
Quantum.QuantumMonoBehaviour

Classes

class  EntityUnityEvent
 Wrapping UnityEvent(QuantumGame) into a class. Is used by the QuantumEntityView to make create and destroy publish Unity events. More...
 
struct  UpdatePositionParameter
 The struct is used to gather all transform and interpolation data to apply new transform data to the entity view. ApplyTransform(ref UpdatePositionParameter). More...
 

Public Member Functions

bool HasViewFlag (QuantumEntityViewFlags flag)
 Test if a view flag is set. More...
 
virtual void OnActivate (Frame frame)
 A callback to override to add custom logic the activation of this entity view. More...
 
virtual void OnDeactivate ()
 A callback to override to add custom logic to the deactivation of this entity view. More...
 
virtual void OnGameChanged ()
 A callback to override to add custom logic when the associate game has changed on the connected QuantumEntityViewUpdater. More...
 
virtual void OnInitialize ()
 A callback to override to add custom logic to the initialization of this entity view. More...
 
virtual void OnLateUpdateView ()
 A callback to override to add custom logic to the late update method. More...
 
virtual void OnUpdateView ()
 A callback to override to add custom logic to the update method. More...
 
void SetViewFlag (QuantumEntityViewFlags flag, bool isEnabled)
 Set the QuantumEntityViewFlags to further configure the entity view. More...
 
bool TryGetTransform2DData (QuantumEntityViewTimeReference timeRef, ref UpdatePositionParameter param, out int frameNumber, out Transform2D transform, out Transform2DVertical transformVertical, out bool hasVertical, bool isSpawning)
 There are two sources how to get the transform 3D data from an entity. Using the Quantum predicted frames or a snapshot interpolation. Toggle the setting on InterpolationMode. More...
 
bool TryGetTransform3DData (QuantumEntityViewTimeReference timeRef, ref UpdatePositionParameter param, out int frameNumber, out Transform3D transform, bool isSpawning)
 There are two sources how to get the transform 3D data from an entity. Using the Quantum predicted frames or a snapshot interpolation. Toggle the setting on InterpolationMode. More...
 
void UpdateFromTransform2D (QuantumGame game, Boolean useClockAliasingInterpolation, Boolean useErrorCorrectionInterpolation, bool isSpawning)
 Apply new transform 2D data and interpolation. More...
 
void UpdateFromTransform3D (QuantumGame game, Boolean useClockAliasingInterpolation, Boolean useErrorCorrectionInterpolation, bool isSpawning)
 Apply new transform 3D data and interpolation. More...
 

Public Attributes

AssetGuid AssetGuid
 Will set to the AssetObject.Guid that the underlying EntityView asset has. Or receives a new Guid when binding this view script to a scene entity. More...
 
QuantumEntityViewBindBehaviour BindBehaviour
 Set the entity view bind behaviour. If set to QuantumEntityViewBindBehaviour.NonVerified then the view is created during a predicted frame. Entity views created at that time can be subject to changes and even be destroyed because of misprediction. Entity views created during QuantumEntityViewBindBehaviour.Verified will be more stable but are always created at a later time, when the input has been confirmed by the server. More...
 
EntityRef EntityRef
 References the Quantum entity that this view script is liked to. More...
 
Single ErrorCorrectionRateMax = 10f
 
Single ErrorCorrectionRateMin = 3.3f
 
Single ErrorPositionBlendEnd = 1f
 
Single ErrorPositionBlendStart = 0.25f
 
Single ErrorPositionMinCorrection = 0.025f
 
Single ErrorPositionTeleportDistance = 2f
 
Single ErrorRotationBlendEnd = 0.5f
 
Single ErrorRotationBlendStart = 0.1f
 
Single ErrorRotationTeleportDistance = 0.5f
 
QuantumEntityViewInterpolationMode InterpolationMode
 Set the QuantumEntityViewInterpolationMode allowing the view timing to be switched between prediction and snapshot-interpolation. Requires the QuantumEntityViewFlags.SnapshotInterpolationEnabled flag to be set to have an effect. AUTO selects the mode dynamically based on the prediction-culled state of the entity. More...
 
bool ManualDiposal => ManualDisposal
 Obsolete property, use ManualDisposal More...
 
bool ManualDisposal
 If enabled the QuantumEntityViewUpdater will not destroy (or disable, in case of map entities) this instance, and you are responsible for removing it from the game world yourself.
\nYou will still receive the OnEntityDestroyed callback. More...
 
EntityUnityEvent OnEntityDestroyed
 Is called before the entity view is destroyed. More...
 
EntityUnityEvent OnEntityInstantiated
 Is called after the entity view has been instantiated. More...
 
IQuantumViewComponent[] ViewComponents => _viewComponents
 Access the entity view components registered to this entity view. All view components found on this game object during creation are used. More...
 
QuantumEntityViewFlags ViewFlags
 Set the QuantumEntityViewFlags to further configure the entity view. More...
 

Protected Member Functions

virtual void ApplyTransform (ref UpdatePositionParameter param)
 The method to override to apply the final position and rotation interpolation to the view transform. More...
 

Properties

QuantumEntityViewUpdater EntityViewUpdater [get]
 A reference to the entity view updater that controls this entity view. More...
 
QuantumGame Game [get]
 A reference to the current game that this entity view belongs to QuantumEntityViewUpdater.ObservedGame. More...
 
bool GameObjectNameIsEntityRef [get, set]
 If set to true, the game object will be renamed to the EntityRef number. More...
 
Transform Transform [get]
 Access the transform of the entity view. In play mode the transform object will be cached to improve the performance. More...
 
Dictionary< Type, IQuantumViewContextViewContexts [get]
 All contexts found on the EntityViewUpdater game object accessible by their type. More...
 

Detailed Description

The Quantum entity view component is the representation of the entity inside Unity. Instances will be created by the EntityViewUpdater. Quantum entity with the View component will references a Quantum EntityView asset which will in turn be instantiated as EntityView.Prefab and the resulting game object includes this script.

Member Function Documentation

◆ SetViewFlag()

void Quantum.QuantumEntityView.SetViewFlag ( QuantumEntityViewFlags  flag,
bool  isEnabled 
)
inline

Set the QuantumEntityViewFlags to further configure the entity view.

Parameters
flagThe flag enum value
isEnabledSet or unset the flag.

◆ HasViewFlag()

bool Quantum.QuantumEntityView.HasViewFlag ( QuantumEntityViewFlags  flag)

Test if a view flag is set.

Parameters
flag
Returns

◆ OnInitialize()

virtual void Quantum.QuantumEntityView.OnInitialize ( )
inlinevirtual

A callback to override to add custom logic to the initialization of this entity view.

◆ OnActivate()

virtual void Quantum.QuantumEntityView.OnActivate ( Frame  frame)
inlinevirtual

A callback to override to add custom logic the activation of this entity view.

Parameters
frameFrame

◆ OnDeactivate()

virtual void Quantum.QuantumEntityView.OnDeactivate ( )
inlinevirtual

A callback to override to add custom logic to the deactivation of this entity view.

◆ OnUpdateView()

virtual void Quantum.QuantumEntityView.OnUpdateView ( )
inlinevirtual

A callback to override to add custom logic to the update method.

◆ OnLateUpdateView()

virtual void Quantum.QuantumEntityView.OnLateUpdateView ( )
inlinevirtual

A callback to override to add custom logic to the late update method.

◆ OnGameChanged()

virtual void Quantum.QuantumEntityView.OnGameChanged ( )
inlinevirtual

A callback to override to add custom logic when the associate game has changed on the connected QuantumEntityViewUpdater.

◆ TryGetTransform3DData()

bool Quantum.QuantumEntityView.TryGetTransform3DData ( QuantumEntityViewTimeReference  timeRef,
ref UpdatePositionParameter  param,
out int  frameNumber,
out Transform3D  transform,
bool  isSpawning 
)
inline

There are two sources how to get the transform 3D data from an entity. Using the Quantum predicted frames or a snapshot interpolation. Toggle the setting on InterpolationMode.

Parameters
timeRefTime reference context
paramTransform parameter to be filled out
frameNumberResulting frame number
transformResulting transform
isSpawningIs the entity spawning
Returns
True if data could be retrieved

◆ UpdateFromTransform3D()

void Quantum.QuantumEntityView.UpdateFromTransform3D ( QuantumGame  game,
Boolean  useClockAliasingInterpolation,
Boolean  useErrorCorrectionInterpolation,
bool  isSpawning 
)
inline

Apply new transform 3D data and interpolation.

Parameters
gameGame
useClockAliasingInterpolationUse clock aliasing interpolation
useErrorCorrectionInterpolationUse error correction interpolation
isSpawningIs the entity just spawning

◆ TryGetTransform2DData()

bool Quantum.QuantumEntityView.TryGetTransform2DData ( QuantumEntityViewTimeReference  timeRef,
ref UpdatePositionParameter  param,
out int  frameNumber,
out Transform2D  transform,
out Transform2DVertical  transformVertical,
out bool  hasVertical,
bool  isSpawning 
)
inline

There are two sources how to get the transform 3D data from an entity. Using the Quantum predicted frames or a snapshot interpolation. Toggle the setting on InterpolationMode.

Parameters
timeRefTime reference context
paramTransform parameter to be filled out
frameNumberResulting frame number
transformResulting transform
transformVerticalTransform vertical component
hasVerticalHas a transform vertical 2D component
isSpawningIs the entity spawning
Returns

True if data could be retrieved

◆ UpdateFromTransform2D()

void Quantum.QuantumEntityView.UpdateFromTransform2D ( QuantumGame  game,
Boolean  useClockAliasingInterpolation,
Boolean  useErrorCorrectionInterpolation,
bool  isSpawning 
)
inline

Apply new transform 2D data and interpolation.

Parameters
gameGame
useClockAliasingInterpolationUse clock aliasing interpolation
useErrorCorrectionInterpolationUse error correction interpolation
isSpawningIs the entity just spawning

◆ ApplyTransform()

virtual void Quantum.QuantumEntityView.ApplyTransform ( ref UpdatePositionParameter  param)
inlineprotectedvirtual

The method to override to apply the final position and rotation interpolation to the view transform.

Parameters
param

Member Data Documentation

◆ AssetGuid

AssetGuid Quantum.QuantumEntityView.AssetGuid

Will set to the AssetObject.Guid that the underlying EntityView asset has. Or receives a new Guid when binding this view script to a scene entity.

◆ EntityRef

EntityRef Quantum.QuantumEntityView.EntityRef

References the Quantum entity that this view script is liked to.

◆ BindBehaviour

QuantumEntityViewBindBehaviour Quantum.QuantumEntityView.BindBehaviour

Set the entity view bind behaviour. If set to QuantumEntityViewBindBehaviour.NonVerified then the view is created during a predicted frame. Entity views created at that time can be subject to changes and even be destroyed because of misprediction. Entity views created during QuantumEntityViewBindBehaviour.Verified will be more stable but are always created at a later time, when the input has been confirmed by the server.

◆ ManualDisposal

bool Quantum.QuantumEntityView.ManualDisposal

If enabled the QuantumEntityViewUpdater will not destroy (or disable, in case of map entities) this instance, and you are responsible for removing it from the game world yourself.
\nYou will still receive the OnEntityDestroyed callback.

◆ ManualDiposal

bool Quantum.QuantumEntityView.ManualDiposal => ManualDisposal

Obsolete property, use ManualDisposal

◆ ViewFlags

QuantumEntityViewFlags Quantum.QuantumEntityView.ViewFlags

Set the QuantumEntityViewFlags to further configure the entity view.

◆ InterpolationMode

QuantumEntityViewInterpolationMode Quantum.QuantumEntityView.InterpolationMode

Set the QuantumEntityViewInterpolationMode allowing the view timing to be switched between prediction and snapshot-interpolation. Requires the QuantumEntityViewFlags.SnapshotInterpolationEnabled flag to be set to have an effect. AUTO selects the mode dynamically based on the prediction-culled state of the entity.

◆ ErrorCorrectionRateMin

Single Quantum.QuantumEntityView.ErrorCorrectionRateMin = 3.3f

A factor with dimension of 1/s (Hz) that works as a lower limit for how much of the accumulated prediction error is corrected every frame. This factor affects both the position and the rotation correction. Suggested values are greater than zero and smaller than ErrorCorrectionRateMax.

E.g.: ErrorCorrectionRateMin = 3, rendering delta time = (1/60)s: at least 5% (3 * 1/60) of the accumulated error will be corrected on this rendered frame.

This threshold might not be respected if the resultant correction magnitude is below the ErrorPositionMinCorrection or above the ErrorPositionTeleportDistance, for the position error, or above the ErrorRotationTeleportDistance, for the rotation error.

◆ ErrorCorrectionRateMax

Single Quantum.QuantumEntityView.ErrorCorrectionRateMax = 10f

A factor with dimension of 1/s (Hz) that works as a upper limit for how much of the accumulated prediction error is corrected every frame. This factor affects both the position and the rotation correction. Suggested values are greater than ErrorCorrectionRateMin and smaller than half of a target rendering rate.

E.g.: ErrorCorrectionRateMax = 15, rendering delta time = (1/60)s: at maximum 25% (15 * 1/60) of the accumulated error will be corrected on this rendered frame.

This threshold might not be respected if the resultant correction magnitude is below the ErrorPositionMinCorrection or above the ErrorPositionTeleportDistance, for the position error, or above the ErrorRotationTeleportDistance, for the rotation error.

◆ ErrorPositionBlendStart

Single Quantum.QuantumEntityView.ErrorPositionBlendStart = 0.25f

The reference for the magnitude of the accumulated position error, in meters, at which the position error will be corrected at the ErrorCorrectionRateMin. Suggested values are greater than ErrorPositionMinCorrection and smaller than ErrorPositionBlendEnd.

In other words, if the magnitude of the accumulated error is equal to or smaller than this threshold, it will be corrected at the ErrorCorrectionRateMin. If, instead, the magnitude is between this threshold and ErrorPositionBlendEnd, the error is corrected at a rate between ErrorCorrectionRateMin and ErrorCorrectionRateMax, proportionally. If it is equal to or greater than ErrorPositionBlendEnd, it will be corrected at the ErrorCorrectionRateMax.

Note: as the factor is expressed in distance units (meters), it might need to be scaled proportionally to the overall scale of objects in the scene and speeds at which they move, which are factors that affect the expected magnitude of prediction errors.

◆ ErrorPositionBlendEnd

Single Quantum.QuantumEntityView.ErrorPositionBlendEnd = 1f

The reference for the magnitude of the accumulated position error, in meters, at which the position error will be corrected at the ErrorCorrectionRateMax. Suggested values are greater than ErrorPositionBlendStart and smaller than ErrorPositionTeleportDistance.

In other words, if the magnitude of the accumulated error is equal to or greater than this threshold, it will be corrected at the ErrorCorrectionRateMax. If, instead, the magnitude is between ErrorPositionBlendStart and this threshold, the error is corrected at a rate between ErrorCorrectionRateMin and ErrorCorrectionRateMax, proportionally. If it is equal to or smaller than ErrorPositionBlendStart, it will be corrected at the ErrorCorrectionRateMin.

Note: as the factor is expressed in distance units (meters), it might need to be scaled proportionally to the overall scale of objects in the scene and speeds at which they move, which are factors that affect the expected magnitude of prediction errors.

◆ ErrorRotationBlendStart

Single Quantum.QuantumEntityView.ErrorRotationBlendStart = 0.1f

The reference for the magnitude of the accumulated rotation error, in radians, at which the rotation error will be corrected at the ErrorCorrectionRateMin. Suggested values are smaller than ErrorRotationBlendEnd.

In other words, if the magnitude of the accumulated error is equal to or smaller than this threshold, it will be corrected at the ErrorCorrectionRateMin. If, instead, the magnitude is between this threshold and ErrorRotationBlendEnd, the error is corrected at a rate between ErrorCorrectionRateMin and ErrorCorrectionRateMax, proportionally. If it is equal to or greater than ErrorRotationBlendEnd, it will be corrected at the ErrorCorrectionRateMax.

◆ ErrorRotationBlendEnd

Single Quantum.QuantumEntityView.ErrorRotationBlendEnd = 0.5f

The reference for the magnitude of the accumulated rotation error, in radians, at which the rotation error will be corrected at the ErrorCorrectionRateMax. Suggested values are greater than ErrorRotationBlendStart and smaller than ErrorRotationTeleportDistance.

In other words, if the magnitude of the accumulated error is equal to or greater than this threshold, it will be corrected at the ErrorCorrectionRateMax. If, instead, the magnitude is between ErrorRotationBlendStart and this threshold, the error is corrected at a rate between ErrorCorrectionRateMin and ErrorCorrectionRateMax, proportionally. If it is equal to or smaller than ErrorRotationBlendStart, it will be corrected at the ErrorCorrectionRateMin.

◆ ErrorPositionMinCorrection

Single Quantum.QuantumEntityView.ErrorPositionMinCorrection = 0.025f

The value, in meters, that represents the minimum magnitude of the accumulated position error that will be corrected in a single frame, until it is fully corrected.

This setting has priority over the resultant correction rate, i.e. the restriction will be respected even if it makes the effective correction rate be different than the one computed according to the min/max rates and start/end blend values. Suggested values are greater than zero and smaller than ErrorPositionBlendStart.

Note: as the factor is expressed in distance units (meters), it might need to be scaled proportionally to the overall scale of objects in the scene and speeds at which they move, which are factors that affect the expected magnitude of prediction errors.

◆ ErrorPositionTeleportDistance

Single Quantum.QuantumEntityView.ErrorPositionTeleportDistance = 2f

The value, in meters, that represents the magnitude of the accumulated position error above which the error will be instantaneously corrected, effectively teleporting the rendered object to its correct position. Suggested values are greater than ErrorPositionBlendEnd.

This setting has priority over the resultant correction rate, i.e. the restriction will be respected even if it makes the effective correction rate be different than the one computed according to the min/max rates and start/end blend values.

Note: as the factor is expressed in distance units (meters), it might need to be scaled proportionally to the overall scale of objects in the scene and speeds at which they move, which are factors that affect the expected magnitude of prediction errors.

◆ ErrorRotationTeleportDistance

Single Quantum.QuantumEntityView.ErrorRotationTeleportDistance = 0.5f

The value, in radians, that represents the magnitude of the accumulated rotation error above which the error will be instantaneously corrected, effectively teleporting the rendered object to its correct orientation. Suggested values are greater than ErrorRotationBlendEnd.

This setting has priority over the resultant correction rate, i.e. the restriction will be respected even if it makes the effective correction rate be different than the one computed according to the min/max rates and start/end blend values.

◆ OnEntityInstantiated

EntityUnityEvent Quantum.QuantumEntityView.OnEntityInstantiated

Is called after the entity view has been instantiated.

◆ OnEntityDestroyed

EntityUnityEvent Quantum.QuantumEntityView.OnEntityDestroyed

Is called before the entity view is destroyed.

◆ ViewComponents

IQuantumViewComponent [] Quantum.QuantumEntityView.ViewComponents => _viewComponents

Access the entity view components registered to this entity view. All view components found on this game object during creation are used.

Property Documentation

◆ GameObjectNameIsEntityRef

bool Quantum.QuantumEntityView.GameObjectNameIsEntityRef
getset

If set to true, the game object will be renamed to the EntityRef number.

◆ EntityViewUpdater

QuantumEntityViewUpdater Quantum.QuantumEntityView.EntityViewUpdater
get

A reference to the entity view updater that controls this entity view.

◆ Game

QuantumGame Quantum.QuantumEntityView.Game
get

A reference to the current game that this entity view belongs to QuantumEntityViewUpdater.ObservedGame.

◆ ViewContexts

Dictionary<Type, IQuantumViewContext> Quantum.QuantumEntityView.ViewContexts
get

All contexts found on the EntityViewUpdater game object accessible by their type.

◆ Transform

Transform Quantum.QuantumEntityView.Transform
get

Access the transform of the entity view. In play mode the transform object will be cached to improve the performance.