NetworkedUnit - alexneargarder/Broforce-Docs GitHub Wiki
NetworkedUnit
Table of Contents
- Unity Lifecycle & Setup
- Position & Physics
- Character State & Effects
- Unit Management
- AI Awareness
- Networking & RPC
Unity Lifecycle & Setup
Methods
protected virtual void Awake()
Initializes the unit by setting maxHealth to the current health value. Called once when the unit is first instantiated.
Position & Physics
Properties
public int Direction { get; set; }
Gets the facing direction of the unit as an integer. Returns -1 if facing left (negative X scale), 1 if facing right (positive X scale).
public virtual byte DirectionSynced { get; set; }
Gets or sets the synchronized direction as a byte value for network transmission. Uses byte value 2 for left direction (-1), 1 for right direction (1). When set, updates the unit's transform scale and internal syncedDirection field. This property does not use interpolation during synchronization.
public virtual Vector3 DirectionVec { get; set; }
Gets the full local scale vector of the unit's transform. Can be used to get both direction and scale information.
public virtual Vector2 XY { get; set; }
Gets or sets the 2D position of the unit as a Vector2. This property is synchronized across the network. Getting returns the current X and Y position from BroforceObject base class. Setting updates the position via SetXY method.
Character State & Effects
Properties
public bool IsEnemy { get; set; }
Gets whether this unit is an enemy. Calculated based on whether the unit is a hero or RescueBro. If not a hero and not a RescueBro, the unit is considered an enemy. This value is cached after first access for performance.
public bool IsHero { get; set; }
Gets whether this unit is a hero (player character). Based on the internal isHero field set by derived classes.
public bool IsMook { get; set; }
Gets whether this unit is specifically a Mook enemy type. Returns true if the unit's type inherits from Mook class.
Fields
protected bool isHero
Protected field that determines if this unit is a hero (player character). Set to true by hero classes during initialization.
Unit Management
Properties
public int playerNum { get; set; }
Gets or sets the player number that owns this unit. Default value is -1, indicating no player ownership. Used to associate units with specific players in multiplayer.
Fields
public int _playerNum = -1
Backing field for the playerNum property. Stores the player number that owns this unit. Default value is -1, indicating no player ownership.
AI Awareness
Properties
public virtual bool IsLocalMook { get; set; }
Gets whether this unit is a mook (enemy) that should be controlled locally. Returns true if the unit has an enemyAI or enemyAIOnChildOrParent component and is owned by the local player. Used to determine which client should control the AI behavior in multiplayer.
Fields
public PolymorphicAI enemyAI
Reference to the PolymorphicAI component that controls this unit's AI behavior. Used for enemy units that have their AI component on the same GameObject.
public PolymorphicAI enemyAIOnChildOrParent
Reference to a PolymorphicAI component that might be on a child or parent GameObject. Used for units where the AI component is not directly on this GameObject.
Networking & RPC
Methods
public override bool ReadyTobeSynced()
Determines if the unit is ready to be synchronized across the network. Returns true only if both X and Y position values are non-negative. This prevents synchronization of units that haven't been properly positioned yet.
Returns:
bool
: True if the unit's position is valid (both X and Y >= 0), false otherwise
Fields
protected int syncedDirection
Stores the synchronized direction value (-1 for left, 1 for right). Updated when DirectionSynced property is set from network synchronization.