Skip to main content

HealthBarManager

class SoftKitty.MasterHealthBarSystem.HealthBarManager : MonoBehaviour

Description​

HealthBarManager is the central runtime manager for health bar resources, shared settings, pooled UI objects, and materials. It is initialized automatically by HealthBarCanvas when the scene loads.


Runtime Responsibilities​

  • load bar prefabs from Resources
  • build bar-setting and floating-text lookup dictionaries
  • create and cache shared materials for each bar UID
  • initialize the overhead setting dictionary
  • manage pooled BarUI, damage text, and OTE UI objects
  • expose shared roots through HealthBarCanvas

Core Methods​

static BarSetting GetBarSetting(string _uid)​

Returns the BarSetting that matches a bar UID.

static NumberSetting GetNumberSetting(string _uid)​

Returns the floating combat text setting that matches a number-text UID.

static Material GetBarMaterial(BarStyle _style, string _barUid)​

Returns the cached shared material for a specific style and bar UID. All bars using the same setting share this material.

static BarUI CreateBar(HealthBar _bar, string _barUid, int _index, Vector2 _size)​

Gets a BarUI from the pool or instantiates one if needed. This is the main entry point used by HealthBar to create overhead bars.

static void ReturnBarToPool(BarUI _bar)​

Returns a floating BarUI to the pool. The bar is deactivated and moved under PoolRoot.

static void CreateDamage(int _damage, BarUI _bar, string _textUid = "")​

Creates floating combat text using a configured number-text UID. This is called internally by HealthBar.PopNumberText() and BarUI.PopNumberText().


Important Dictionaries​

These are public static runtime caches used by the system:

  • BarSettingDic
  • NumberSettingDic
  • OverHeadSettingDic
  • BarInPool
  • MaterialDic
  • DamageObj
  • DamageInPool
  • BarPrefabs
  • OteInPool

In normal gameplay code, you usually do not need to modify them directly.


Usage Notes​

  • Most gameplay scripts should call HealthBar or BarUI, not HealthBarManager directly.
  • GetBarSetting() and GetNumberSetting() are useful when building custom integrations or debug tools.
  • Material sharing is a key part of the system's performance model.