Photon Fusion 2.0.3

Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Properties | List of all members
HitboxRoot Class Reference

Root Hitbox group container. Manages registering/unregistering hitboxes with the group, and defines the broadphase geometry for the group. More...

Inherits NetworkBehaviour.

Public Types

enum class  ConfigFlags : int
 Set of configuration options for a Hitbox Root behaviour. More...
 

Public Member Functions

override void Despawned (NetworkRunner runner, bool hasState)
 Called before the network object is despawned
 
void InitHitboxes ()
 Finds child Hitbox components, and adds them to the Hitboxes collection. More...
 
bool IsHitboxActive (Hitbox hitbox)
 Checks the state of a Hitbox instance under this root. Both the hitbox and its root must be active in order for it to be hit by lag-compensated queries. More...
 
void OnDrawGizmos ()
 HitboxRoot on draw gizmos. More...
 
void SetHitboxActive (Hitbox hitbox, bool setActive)
 Sets the state of a Hitbox instance under this root. Both the hitbox and its root must be active in order for it to be hit by lag-compensated queries. More...
 
void SetMinBoundingRadius ()
 Sets BroadRadius to a rough value which encompasses all Hitboxes in their current positions. More...
 
- Public Member Functions inherited from NetworkBehaviour
virtual void CopyBackingFieldsToState (bool firstTime)
 Copies the backing fields to the state. This method is meant to be overridden in derived classes. More...
 
void CopyStateFrom (NetworkBehaviour source)
 Copies entire state of passed in source NetworkBehaviour More...
 
virtual void CopyStateToBackingFields ()
 Copies the state to the backing fields. This method is meant to be overridden in derived classes. More...
 
override void FixedUpdateNetwork ()
 Fixed update callback for networked behaviours. More...
 
ArrayReader< T > GetArrayReader< T > (string property)
 Gets an ArrayReader for a network array of type T. More...
 
BehaviourReader< T > GetBehaviourReader< T > (string property)
 Gets a BehaviourReader for a network behaviour of type T. More...
 
ChangeDetector GetChangeDetector (ChangeDetector.Source source, bool copyInitial=true)
 Creates a ChangeDetector for this network behaviour. More...
 
DictionaryReader< K, V > GetDictionaryReader< K, V > (string property)
 Gets a DictionaryReader for a network dictionary with keys of type K and values of type V. More...
 
T? GetInput< T > ()
 
bool GetInput< T > (out T input)
 Returns true if it a valid INetworkInput can be found for the current simulation tick (Typically this is used in FixedUpdateNetwork). More...
 
LinkListReader< T > GetLinkListReader< T > (string property)
 Gets a LinkListReader for a network linked list of type T. More...
 
int GetLocalAuthorityMask ()
 Gets a bitmask of AuthorityMasks flags, representing the current local authority over this NetworkObject. More...
 
PropertyReader< T > GetPropertyReader< T > (string property)
 Gets a PropertyReader for a property of type T in this network behaviour. More...
 
ref T ReinterpretState< T > (int offset=0)
 Allows read and write access to the internal state buffer More...
 
void ReplicateTo (PlayerRef player, bool replicate)
 Controls if this network behaviours state is replicated to a player or not More...
 
void ReplicateToAll (bool replicate)
 Sets the default replicated state for this behaviour, this by default is true so calling ReplicateToAll(true) does nothing if ReplicateToAll(false) hasn't been called before
More...
 
void ResetState ()
 Resets the state of the object to the original state More...
 
virtual void Spawned ()
 Post spawn callback. More...
 
bool TryGetSnapshotsBuffers (out NetworkBehaviourBuffer from, out NetworkBehaviourBuffer to, out float alpha)
 Tries to get the snapshot buffers for this network behaviour. More...
 
- Public Member Functions inherited from SimulationBehaviour
virtual void Render ()
 Post simulation frame rendering callback. Runs after all simulations have finished. Use in place of Unity's Update when Fusion is handling Physics. More...
 
- Public Member Functions inherited from Behaviour
AddBehaviour< T > ()
 Wrapper for Unity's GameObject.AddComponent() More...
 
GetBehaviour< T > ()
 Wrapper for Unity's GameObject.GetComponentInChildren() More...
 
bool TryGetBehaviour< T > (out T behaviour)
 Wrapper for Unity's GameObject.TryGetComponent() More...
 
- Public Member Functions inherited from IElementReaderWriter< NetworkObject >
int GetElementHashCode (T element)
 Calculate the hash code of an element. More...
 
int GetElementWordCount ()
 Gets the word count of an element. More...
 
Read (byte *data, int index)
 Reads an element from the specified index in the byte array. More...
 
ref T ReadRef (byte *data, int index)
 Reads a reference to an element from the specified index in the byte array. More...
 
void Write (byte *data, int index, T element)
 Writes an element to the specified index in the byte array. More...
 
- Public Member Functions inherited from IElementReaderWriter< NetworkBehaviour >
int GetElementHashCode (T element)
 Calculate the hash code of an element. More...
 
int GetElementWordCount ()
 Gets the word count of an element. More...
 
Read (byte *data, int index)
 Reads an element from the specified index in the byte array. More...
 
ref T ReadRef (byte *data, int index)
 Reads a reference to an element from the specified index in the byte array. More...
 
void Write (byte *data, int index, T element)
 Writes an element to the specified index in the byte array. More...
 

Public Attributes

float BroadRadius
 The radius of the broadphase bounding sphere for this Hitbox group. Used by HitboxManager to insert/update lag compensated NetworkObjects into its BVH (bounding volume hierarchy) data structure. Be sure this radius encompasses all children Hitbox components (including their full ranges of animation motion). We plan to offer an option to dynamically compute the bounding volume, but the performance trade of will still favor a hand-crafted radius. More...
 
ConfigFlags Config = ConfigFlags.Default
 Set of configuration options for this Hitbox Root behaviour. Check the API documentation for more details on what each flag represents. More...
 
Color GizmosColor = Color.gray
 Color used when drawing gizmos for this hitbox. More...
 
Hitbox[] Hitboxes
 All Hitbox instances in hierarchy. Auto-filled at Spawned. More...
 
Vector3 Offset
 Local-space offset of the broadphase bounding sphere from its transform position. More...
 
- Public Attributes inherited from NetworkBehaviour
int offset
 Gives access to the offset (in 32 bit words) and count (in 32 bit words) of this behaviour backing data More...
 

Static Public Attributes

const Int32 MAX_HITBOXES = (sizeof(UInt32) * 8) - 1
 The max number of hitboxes allowed under the same root. More...
 

Protected Member Functions

virtual void DrawGizmos (Color color, ref Matrix4x4 localToWorldMatrix)
 Draws the gizmos for the HitboxRoot More...
 
- Protected Member Functions inherited from NetworkBehaviour
virtual bool ReplicateTo (PlayerRef player)
 Determines whether to replicate the network behaviour to the specified player. This method can be overridden in derived classes to implement custom replication logic. More...
 

Properties

bool HitboxRootActive [get, set]
 Get or set the state of this HitboxRoot. For a hitbox to be hit by lag-compensated queries, both it and its HitboxRoot must be active. More...
 
bool InInterest [get]
 If this HitboxRoot is in interest for the local player. More...
 
HitboxManager Manager [get]
 Reference to associated hitbox manager (from which lag compensated queries can be performed). More...
 
- Properties inherited from NetworkBehaviour
Tick ChangedTick [get]
 The tick the data on this networked behaviour changed More...
 
virtual ? int DynamicWordCount [get]
 Override this value for custom memory allocations. This is for advanced use cases only, and cannot be used if NetworkedAttribute is used in the derived class.
More...
 
bool? HasInputAuthority [get]
 Returns true if the Simulation.LocalPlayer of the associated NetworkRunner is the designated as Input Source for this network entity. More...
 
bool? HasStateAuthority [get]
 Returns true if the associated NetworkRunner is the State Source for this network entity. More...
 
NetworkBehaviourIdId [get]
 The unique identifier for this network behaviour. More...
 
bool? IsProxy [get]
 Returns true if the associated NetworkRunner is neither the Input nor State Authority for this network entity. It is recommended to use !HasStateAuthority or !HasInputAuthority when possible instead, as this check requires evaluating both authorities - and is therefore less performant than the individual checks. More...
 
NetworkBehaviourBuffer StateBuffer [get]
 Gets the state buffer associated with the network behaviour. More...
 
bool StateBufferIsValid [get]
 Gets a value indicating whether the state buffer is valid. More...
 
- Properties inherited from SimulationBehaviour
bool CanReceiveRenderCallback [get]
 Gets a value indicating whether this instance can receive render callbacks. More...
 
bool CanReceiveSimulationCallback [get]
 Gets a value indicating whether this instance can receive simulation callbacks. More...
 
NetworkObject Object [get]
 The NetworkObject this component is associated with. More...
 
NetworkRunner Runner [get]
 The NetworkRunner this component is associated with. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from NetworkBehaviour
static ArrayReader< T > GetArrayReader< T > (Type behaviourType, string property, IElementReaderWriter< T > readerWriter=null)
 Gets an ArrayReader for a network array of type T in a network behaviour of a specific type. More...
 
static BehaviourReader< T > GetBehaviourReader< T > (NetworkRunner runner, Type behaviourType, string property)
 Gets a BehaviourReader for a network behaviour of type T. More...
 
static BehaviourReader< TProperty > GetBehaviourReader< TBehaviour, TProperty > (NetworkRunner runner, string property)
 Gets a BehaviourReader for a network behaviour with a specific property of type TProperty. More...
 
static DictionaryReader< K, V > GetDictionaryReader< K, V > (Type behaviourType, string property, IElementReaderWriter< K > keyReaderWriter=null, IElementReaderWriter< V > valueReaderWriter=null)
 Gets a DictionaryReader for a network dictionary with keys of type K and values of type V in a network behaviour of a specific type. More...
 
static LinkListReader< T > GetLinkListReader< T > (Type behaviourType, string property, IElementReaderWriter< T > readerWriter=null)
 Gets a LinkListReader for a network linked list of type T in a network behaviour of a specific type. More...
 
static PropertyReader< T > GetPropertyReader< T > (Type behaviourType, string property)
 Gets a PropertyReader for a property of type T in a network behaviour of a specific type. More...
 
static PropertyReader< TProperty > GetPropertyReader< TBehaviour, TProperty > (string property)
 Gets a PropertyReader for a property of type TProperty in a network behaviour of type TBehaviour. More...
 
static NetworkBehaviourUtils.DictionaryInitializer< K, V > MakeInitializer< K, V > (Dictionary< K, V > dictionary)
 This is a special method that is meant to be used only for [Networked] properties inline initialization. More...
 
static NetworkBehaviourUtils.ArrayInitializer< T > MakeInitializer< T > (T[] array)
 This is a special method that is meant to be used only for [Networked] properties inline initialization. More...
 
static T * MakePtr< T > ()
 Creates a pointer to a value of type T. This method is meant to be used only for [Networked] properties inline initialization. More...
 
static T * MakePtr< T > (T defaultValue)
 Creates a pointer to a value of type T, initializing it with the provided default value. This method is meant to be used only for [Networked] properties inline initialization. More...
 
static ref T MakeRef< T > ()
 Creates a reference to a value of type T. This method is meant to be used only for [Networked] properties inline initialization. More...
 
static ref T MakeRef< T > (T defaultValue)
 Creates a reference to a value of type T, initializing it with the provided default value. This method is meant to be used only for [Networked] properties inline initialization. More...
 
static int NetworkDeserialize (NetworkRunner runner, byte *data, ref NetworkBehaviour result)
 Deserializes a NetworkBehaviour from a byte array. More...
 
static int NetworkSerialize (NetworkRunner runner, NetworkBehaviour obj, byte *data)
 Serializes a NetworkBehaviour into a byte array. More...
 
static NetworkBehaviour NetworkUnwrap (NetworkRunner runner, NetworkBehaviourId wrapper)
 Converts a NetworkBehaviourId to a NetworkBehaviour. More...
 
static NetworkBehaviourId NetworkWrap (NetworkBehaviour obj)
 Converts a NetworkBehaviour to a NetworkBehaviourId. More...
 
static NetworkBehaviourId NetworkWrap (NetworkRunner runner, NetworkBehaviour obj)
 Converts a NetworkBehaviour to a NetworkBehaviourId. More...
 
static implicit operator NetworkBehaviourId (NetworkBehaviour behaviour)
 Converts NetworkBehaviour to NetworkBehaviourId More...
 
- Static Public Member Functions inherited from Behaviour
static void DestroyBehaviour (Behaviour behaviour)
 Wrapper for Unity's GameObject.Destroy() More...
 

Detailed Description

Root Hitbox group container. Manages registering/unregistering hitboxes with the group, and defines the broadphase geometry for the group.

Broadphase is the initial rough query used by raycasts/overlaps/etc to find potential hit candidates, which are then used in the final narrowphase query.

Member Enumeration Documentation

◆ ConfigFlags

enum ConfigFlags : int
strong

Set of configuration options for a Hitbox Root behaviour.

Enumerator
ReinitializeHitboxesBeforeRegistration 

If the collection of hitboxes under a given root should be re-initialized before the Root is registered in a hitbox snapshot. If disabled, the hitboxes will be used as configured in edit-time.

IncludeInactiveHitboxes 

If Hitboxes on inactive Game Objects should be registered under this root upon initialization.

Legacy 

Set of configuration flags that replicate the behaviour as it was before the flag options were added.

Default 

Ser of configuration flags with the default behaviour, suitable for most use-cases.

Member Function Documentation

◆ DrawGizmos()

virtual void DrawGizmos ( Color  color,
ref Matrix4x4  localToWorldMatrix 
)
protectedvirtual

Draws the gizmos for the HitboxRoot

◆ InitHitboxes()

void InitHitboxes ( )

Finds child Hitbox components, and adds them to the Hitboxes collection.

◆ IsHitboxActive()

bool IsHitboxActive ( Hitbox  hitbox)

Checks the state of a Hitbox instance under this root. Both the hitbox and its root must be active in order for it to be hit by lag-compensated queries.

Parameters
hitboxA hitbox instance under the hierarchy of this root.
Returns
True if the hitbox is part of this root and is active.
Exceptions
ArgumentOutOfRangeExceptionIf the Hitbox.HitboxIndex of the hitbox is outside the valid range.
AssertExceptionIn Debug configuration, if the hitbox is not part of this root.

◆ OnDrawGizmos()

void OnDrawGizmos ( )

HitboxRoot on draw gizmos.

◆ SetHitboxActive()

void SetHitboxActive ( Hitbox  hitbox,
bool  setActive 
)

Sets the state of a Hitbox instance under this root. Both the hitbox and its root must be active in order for it to be hit by lag-compensated queries.

Parameters
hitboxA hitbox instance under the hierarchy of this root.
setActiveIf the hitbox should be activated or deactivated.
Exceptions
ArgumentOutOfRangeExceptionIf the Hitbox.HitboxIndex of the hitbox is outside the valid range.
AssertExceptionIn Debug configuration, if the hitbox is not part of this root.

◆ SetMinBoundingRadius()

void SetMinBoundingRadius ( )

Sets BroadRadius to a rough value which encompasses all Hitboxes in their current positions.

Member Data Documentation

◆ BroadRadius

float BroadRadius

The radius of the broadphase bounding sphere for this Hitbox group. Used by HitboxManager to insert/update lag compensated NetworkObjects into its BVH (bounding volume hierarchy) data structure. Be sure this radius encompasses all children Hitbox components (including their full ranges of animation motion). We plan to offer an option to dynamically compute the bounding volume, but the performance trade of will still favor a hand-crafted radius.

Broadphase is the initial rough query used by raycasts/overlaps/etc to find potential hit candidates, which are then used in the final narrowphase query.

◆ Config

Set of configuration options for this Hitbox Root behaviour. Check the API documentation for more details on what each flag represents.

◆ GizmosColor

Color GizmosColor = Color.gray

Color used when drawing gizmos for this hitbox.

◆ Hitboxes

Hitbox [] Hitboxes

All Hitbox instances in hierarchy. Auto-filled at Spawned.

◆ MAX_HITBOXES

const Int32 MAX_HITBOXES = (sizeof(UInt32) * 8) - 1
static

The max number of hitboxes allowed under the same root.

◆ Offset

Vector3 Offset

Local-space offset of the broadphase bounding sphere from its transform position.

Adjust the BroadRadius and Offset until the sphere gizmo (shown in the Unity Scene window) encompasses all children Hitbox components (including their full ranges of animation motion).

Broadphase is the initial rough query used by raycasts/overlaps/etc to find potential hit candidates, which are then used in the final narrowphase query.

Property Documentation

◆ HitboxRootActive

bool HitboxRootActive
getset

Get or set the state of this HitboxRoot. For a hitbox to be hit by lag-compensated queries, both it and its HitboxRoot must be active.

◆ InInterest

bool InInterest
get

If this HitboxRoot is in interest for the local player.

◆ Manager

HitboxManager Manager
get

Reference to associated hitbox manager (from which lag compensated queries can be performed).