UIBank - jimdroberts/FishMMO GitHub Wiki
A UI control for displaying and managing the player's bank in the FishMMO client. Handles the display of bank slots, updates slot contents in response to network and character events, and integrates with the bank controller to keep the UI in sync with the player's bank inventory.
-
public RectTransform content
The parent RectTransform for bank slot UI elements.
-
public UIBankButton buttonPrefab
The prefab used to instantiate bank slot buttons.
-
public List bankSlots
List of all bank slot buttons currently displayed.
-
public override void OnClientSet()
Registers the broadcast handler for banker updates.
-
public override void OnClientUnset()
Unregisters the broadcast handler for banker updates.
-
public override void OnDestroying()
Cleans up bank slot buttons.
-
private void DestroySlots()
Destroys all bank slot buttons in the UI and clears the list.
-
private void OnClientBankerBroadcastReceived(BankerBroadcast msg, Channel channel)
Handles the broadcast message for banker updates. Shows or hides the UI based on character and bank controller presence.
-
public override void OnPreSetCharacter()
Unsubscribes from bank slot update events before the character is set.
-
public override void OnPostSetCharacter()
Initializes bank slot buttons and subscribes to slot update events after the character is set.
-
public void OnBankSlotUpdated(IItemContainer container, Item item, int bankIndex)
Event handler for when a bank slot is updated. Updates the corresponding button display.
- Attach
UIBank
to a bank UI GameObject in the Unity Editor. - Assign the
content
andbuttonPrefab
fields in the Inspector. - Ensure the character and bank controller systems are available and properly set up.
// Example usage in a MonoBehaviour
public UIBank bankUI;
void Start() {
bankUI.OnClientSet();
}
// To update a bank slot
bankUI.OnBankSlotUpdated(container, item, bankIndex);
- Always assign all UI references in the Inspector to avoid null reference errors.
- Use event subscriptions in
OnClientSet
/OnClientUnset
to avoid memory leaks. - Keep the UI updated by calling
DestroySlots()
and updating slot lists as needed. - Integrate with the bank controller for dynamic updates.