HTML Content Display

Goal

Display local HTML content (terms & conditions, privacy policies, help documentation, offline content).

Actions Required

Action
Purpose

WebViewCreateInstance

Creates WebView instance

WebViewLoadHtmlString

Loads HTML string

WebViewShow

Displays WebView

Variables Needed

  • webViewInstance (Object): Stores the WebView instance

  • htmlContent (String): HTML content to display

  • baseURL (String): Base URL for relative resources (optional)

Implementation Steps

1. State: PrepareHTML

Load HTML content from file or construct programmatically.

Option A: From Resources

Option B: Constructed HTML

2. State: CreateWebView

Action: WebViewCreateInstance

  • Outputs:

    • webViewInstance β†’ Store in FsmObject variable

  • Next: LoadHTML

3. State: LoadHTML

Action: WebViewLoadHtmlString

  • Inputs:

    • webViewInstance β†’ From variable

    • htmlString β†’ htmlContent variable

    • baseURL β†’ Optional (e.g., "file:///android_asset/" for local resources)

  • Next: ShowWebView

Note: baseURL is used to resolve relative paths in HTML (images, CSS, etc.)

4. State: ShowWebView

Action: WebViewShow

  • Inputs:

    • webViewInstance β†’ From variable

  • Events:

    • successEvent β†’ End

    • failureEvent β†’ ShowError

Common Issues

  • Images don't load: Provide correct baseURL for relative image paths

  • Styles not applied: Use inline CSS or embedded <style> tags

  • Encoding issues: Ensure HTML string uses UTF-8 encoding

  • Links don't work: Relative links require baseURL, external links work normally

Flow Diagram

Best Practices

  • Keep HTML self-contained (inline CSS, embedded images as base64)

  • Use responsive design (viewport meta tag for mobile)

  • Test HTML rendering separately before integration

  • Provide baseURL when using relative resource paths

  • Consider localization (load different HTML per language)

Example HTML Templates

Simple Terms & Conditions

Privacy Policy

Help Documentation

Advanced: Dynamic Content

Construct HTML dynamically with player data:

Localization Support

Load different HTML based on language:

Images in HTML

Option 1: Base64 Embedded Images

Option 2: Resources with BaseURL

Option 3: External URLs

Styling for Mobile

Always include viewport meta tag:

Use relative units:

Interactive HTML

Combine with JavaScript (Use Case 2) for interactive content:

Then use Custom URL Schemes (Use Case 3) to handle button clicks in Unity.

File Organization

Recommended structure:

Last updated

Was this helpful?