Class BasePanel
ENGINE - Base class for UI Toolkit panels. Provides common infrastructure: UIDocument access, root element, show/hide.
Usage:
- Inherit from BasePanel
- Override CreateUI() to build your panel
- Call Initialize() to set up the panel
[RequireComponent(typeof(UIDocument))]
public abstract class BasePanel : MonoBehaviour
- Inheritance
-
objectBasePanel
- Derived
Fields
isInitialized
protected bool isInitialized
Field Value
- bool
isVisible
protected bool isVisible
Field Value
- bool
panelContainer
protected VisualElement panelContainer
Field Value
rootElement
protected VisualElement rootElement
Field Value
uiDocument
protected UIDocument uiDocument
Field Value
Properties
IsInitialized
True if panel has been initialized.
public bool IsInitialized { get; }
Property Value
- bool
IsVisible
True if panel is currently visible.
public bool IsVisible { get; }
Property Value
- bool
Methods
CenterPanel()
Center the panel on screen.
protected void CenterPanel()
CreatePanelContainer(string, Color, float, float)
Create the main panel container with common styling.
protected VisualElement CreatePanelContainer(string name, Color backgroundColor, float padding = 10, float borderRadius = 6)
Parameters
namestringbackgroundColorColorpaddingfloatborderRadiusfloat
Returns
CreateUI()
Override to create your panel's UI elements. Set panelContainer to your main container element.
protected abstract void CreateUI()
Hide()
Hide the panel.
public virtual void Hide()
InitializeBase()
Initialize the panel. Call from subclass Initialize() method.
protected bool InitializeBase()
Returns
- bool
OnHide()
Called when panel is hidden. Override for cleanup.
protected virtual void OnHide()
OnShow()
Called when panel is shown. Override for refresh logic.
protected virtual void OnShow()
PositionPanel(float?, float?, float?, float?)
Position the panel absolutely.
protected void PositionPanel(float? top = null, float? right = null, float? bottom = null, float? left = null)
Parameters
topfloat?rightfloat?bottomfloat?leftfloat?
Show()
Show the panel.
public virtual void Show()
Toggle()
Toggle panel visibility.
public virtual void Toggle()