Class BannerVisualElement
Unity UIToolkit compatible IBannerAd.
Implements
Inherited Members
Namespace: Chartboost.Mediation.Ad.Banner.UIToolkit
Assembly: Chartboost.Mediation.dll
Syntax
public class BannerVisualElement : VisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IAd
Constructors
BannerVisualElement()
Declaration
public BannerVisualElement()
Properties
BannerSize
Gets the size of the banner ad loaded inside this container. Note that this will change with auto-refresh and will be notified in WillAppear
Declaration
public BannerSize? BannerSize { get; }
Property Value
| Type | Description |
|---|---|
| BannerSize? |
Draggable
Gets or sets a value indicating whether this container can be dragged on the screen.
Declaration
public bool Draggable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HorizontalAlignment
The horizontal alignment of the ad within its container.
Declaration
public BannerHorizontalAlignment HorizontalAlignment { get; set; }
Property Value
| Type | Description |
|---|---|
| BannerHorizontalAlignment |
Keywords
The keywords targeted for the ad.
Declaration
public IReadOnlyDictionary<string, string> Keywords { get; set; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, string> |
LoadId
The identifier for this load call. Note that this will change with auto-refresh and will be notified in WillAppear
Declaration
public string LoadId { get; }
Property Value
| Type | Description |
|---|---|
| string |
LoadMetrics
The load metrics for the most recent successful load operation, or Null if a banner is not loaded. If auto-refresh is enabled, this value will change over time. The WillAppear event will be called after this value changes.
Declaration
public Metrics? LoadMetrics { get; }
Property Value
| Type | Description |
|---|---|
| Metrics? |
PartnerSettings
Optional partner-specific settings that can be associated with the advertisement placement.
Declaration
public IReadOnlyDictionary<string, string> PartnerSettings { get; set; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, string> |
PlacementName
The placement name for the ad.
Declaration
public string PlacementName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Request
The publisher supplied request that was used to load the ad.
Declaration
public BannerAdLoadRequest Request { get; }
Property Value
| Type | Description |
|---|---|
| BannerAdLoadRequest |
VerticalAlignment
The vertical alignment of the ad within its container.
Declaration
public BannerVerticalAlignment VerticalAlignment { get; set; }
Property Value
| Type | Description |
|---|---|
| BannerVerticalAlignment |
WinningBidInfo
The winning bid info for the ad. Note that this will change with auto-refresh and will be notified in WillAppear
Declaration
public BidInfo? WinningBidInfo { get; }
Property Value
| Type | Description |
|---|---|
| BidInfo? |
Methods
Dispose()
Disposes the ad along with its container. This should be called when the ad is no longer needed.
Declaration
public void Dispose()
Load()
Loads an ad inside this VisualElement. Uses the size of this VisualElement (width and height in pixels) to construct the BannerSize in load request
Declaration
public Task<BannerAdLoadResult> Load()
Returns
| Type | Description |
|---|---|
| Task<BannerAdLoadResult> |
Load(BannerAdLoadRequest)
Loads an ad.
Declaration
public Task<BannerAdLoadResult> Load(BannerAdLoadRequest loadRequest)
Parameters
| Type | Name | Description |
|---|---|---|
| BannerAdLoadRequest | loadRequest |
Returns
| Type | Description |
|---|---|
| Task<BannerAdLoadResult> |
Reset()
Clears the loaded ad
Declaration
public void Reset()
SetAbsolutePositionByAlignment(float, float)
Positions the banner using absolute positioning based on alignment values relative to the screen.
Declaration
public void SetAbsolutePositionByAlignment(float horizontalAlignment, float verticalAlignment)
Parameters
| Type | Name | Description |
|---|---|---|
| float | horizontalAlignment | Horizontal alignment (0=left, 0.5=center, 1=right) |
| float | verticalAlignment | Vertical alignment (0=top, 0.5=center, 1=bottom) |
Remarks
Why use this method:
This method is designed for scenarios where you need precise, screen-relative positioning of banner ads using absolute coordinates. It's particularly useful when:
- You want to position banners at specific screen locations (corners, edges, center)
- You're not using UIToolkit's layout system (flexbox, absolute/relative parent positioning)
- You need consistent positioning across different screen sizes and densities
- You want to dynamically reposition banners after they've loaded (e.g., for A/B testing positions)
How it works:
This method sets style.position = Position.Absolute and calculates pixel-perfect coordinates
based on the actual banner size and screen dimensions. The alignment values (0-1 range) determine
where the banner appears on screen, with fractional pixels rounded to prevent rendering issues.
When NOT to use this method:
If you're using UIToolkit's layout system (e.g., banner inside a flex container, using relative positioning, or styled via USS), you should control positioning through standard UIToolkit styling instead. This method overrides position-related styles with absolute positioning.
Important:
Must be called AFTER the banner loads (when BannerSize is available). If called before loading, a warning is logged and the method returns without effect. The container is automatically resized to match the actual banner dimensions.
ToString()
Returns JSON representation of the current object
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Events
DidBeginDrag
Called when the ad container has begun dragging on screen.
Declaration
public event BannerVisualElementAdDragEvent DidBeginDrag
Event Type
| Type | Description |
|---|---|
| BannerVisualElementAdDragEvent |
Remarks
Event type is BannerVisualElementAdDragEvent for UI Toolkit compatibility.
DidClick
Called when the ad executes its click-through. This may happen multiple times for the same ad.
Declaration
public event BannerVisualElementAdEvent DidClick
Event Type
| Type | Description |
|---|---|
| BannerVisualElementAdEvent |
Remarks
Event type is BannerVisualElementAdEvent for UI Toolkit compatibility.
DidDrag
Called when the ad container is dragged on screen.
Declaration
public event BannerVisualElementAdDragEvent DidDrag
Event Type
| Type | Description |
|---|---|
| BannerVisualElementAdDragEvent |
Remarks
Event type is BannerVisualElementAdDragEvent for UI Toolkit compatibility.
DidEndDrag
Called when the ad container has finished dragging on screen.
Declaration
public event BannerVisualElementAdDragEvent DidEndDrag
Event Type
| Type | Description |
|---|---|
| BannerVisualElementAdDragEvent |
Remarks
Event type is BannerVisualElementAdDragEvent for UI Toolkit compatibility.
DidRecordImpression
Called when the ad impression occurs.
Declaration
public event BannerVisualElementAdEvent DidRecordImpression
Event Type
| Type | Description |
|---|---|
| BannerVisualElementAdEvent |
Remarks
Event type is BannerVisualElementAdEvent for UI Toolkit compatibility.
WillAppear
Called when ad is loaded within its container. This will be called for each refresh when auto-refresh is enabled.
Declaration
public event BannerVisualElementAdEvent WillAppear
Event Type
| Type | Description |
|---|---|
| BannerVisualElementAdEvent |
Remarks
Event type is BannerVisualElementAdEvent for UI Toolkit compatibility.