HealthBar
class SoftKitty.MasterHealthBarSystem.HealthBar : MonoBehaviour
Description
HealthBar is the runtime component for world-space overhead health bars.
Add it to the root of a character prefab and the system will create the overhead UI based on the assigned OverheadUID.
If Use SoftKitty EntityManager and Attributes is enabled, place EntityComponent on the same GameObject so the bar can auto-sync from entity attributes.
Public Fields and Properties
string OverheadUID- The UID of the overhead preset used by this character.
float CharacterHeight = 1.8f- World-space height offset used for positioning the overhead UI.
bool ActiveOutline- Enables the main bar outline effect.
bool ActiveInnerLine- Enables the inner line effect.
bool ActiveCrack- Enables the crack effect.
string OverheadInfo- Runtime text shown by the overhead info text block.
bool Visible- Shows or hides the full overhead UI for this character.
BarUI MyBar- Accesses the main created bar UI. Sub bars are children of this bar.
OverheadSetting MyOverheadSetting- Resolves the assigned overhead preset.
string uid- Returns the
Entity UIDfromEntityComponentwhen EntityManager mode is enabled.
- Returns the
Core Methods
int GetValue(int _barIdx, BarValueType _type)
Returns the current value for a bar channel.
_barIdx: bar index.0is the main bar._type: which value channel to read.
In EntityManager mode, values are read from the mapped attributes. In standalone mode, values are read from the internal runtime cache.
void SetValue(int _barIdx, BarValueType _type, int _value)
Sets one value channel for a specific bar.
_barIdx: bar index.0is the main bar._type: which channel to modify._value: integer value to assign.
In EntityManager mode, this writes back to the mapped entity attribute. In standalone mode, this updates the internal runtime cache.
void PopNumberText(string _uid, int _num)
Creates floating combat text on the main overhead bar.
_uid: floating combat text preset UID._num: number to display.
void SetOverheadInfo(string _text)
Overrides the overhead text shown by the info text block.
Use <br> inside the input string to create line breaks.
BarUI GetBar(int _barIndex)
Returns the created BarUI instance for a specific index.
0: main bar1+: sub bars in the overhead preset
void SetAvatar(Texture _texture)
Sets the avatar texture when Show Avatar is enabled in OverheadSettings.
BarValueType
public enum BarValueType
{
BarValue,
MaximumBarValue,
OverlayValue,
MaximumOverlayValue
}
BarValue: primary current valueMaximumBarValue: primary maximum valueOverlayValue: overlay current value, such as shieldMaximumOverlayValue: overlay maximum value
Standalone Usage Example
public HealthBar player;
public int healthValue = 100;
public int maxHealthValue = 100;
public int shieldValue = 0;
public int maxShieldValue = 100;
void Update()
{
player.SetValue(0, BarValueType.BarValue, healthValue);
player.SetValue(0, BarValueType.MaximumBarValue, maxHealthValue);
player.SetValue(0, BarValueType.OverlayValue, shieldValue);
player.SetValue(0, BarValueType.MaximumOverlayValue, maxShieldValue);
}
Common Usage Notes
- Add this component to the character prefab root.
- Assign a valid
OverheadUIDcreated in OverheadSettings. - In EntityManager mode, add
EntityComponenton the same GameObject. - Use
Visibleto show or hide the entire overhead UI. - Use
PopNumberText()for world-space overhead bars. For static bars, callBarUI.PopNumberText()instead.