This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Sandworm (Experimental)
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine.LoadingScreen Class

A singleton that controls the settings of the loading screen. Demonstration of it gives Unigine the time to load all world nodes and resources. You can also show your own loading screen when needed.

A loading screen displays a texture that is usually divided into two parts stacked vertically — the initial and final pictures — which are gradually blended from the beginning up to the end of loading to show the progress. Blending is performed based on the alpha channel of the outro (lower) part of the texture so pseudo-animation can be created using the alpha channel: regions of the lower half with small alpha values will be shown first, regions with larger alpha values will be shown last.

See Also#

  • A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/widgets/ folder:
    • loading_screen_00
    • loading_screen_01
    • loading_screen_04
  • Quick Video Guide: How To Customize Loading Screens.

Example

Here's a code example on how to add your own loading screens for application and world loading.

To show your loading screen on system logic initialization before a world is loaded, define it inside the init() method of the System Logic:

Source code (C#)
// AppSystemLogic.cs
/* ... */ 
public override bool Init()
{
	// define new transform for loading screen texture
	vec4 transform = new vec4(1.0f, 1.0f, 0.0f, 0.0f);
	
	// enable the loading screen
	LoadingScreen.Enabled = true;
	
	// set transform to the loading screen texture
	LoadingScreen.Transform = transform;

	// compute the aspect ratio to show corresponding texture
	float aspect_ratio = (float)App.GetWidth() / (float)App.GetHeight();

	// if the aspect ratio is 4:3 show the following loading screen
	// during world loading
	if (aspect_ratio < 1.5f)
	{
		LoadingScreen.TexturePath = "textures/splash_4x3.png";
	}
	else
	{
		// if the aspect ratio is 16:9 show this loading screen
		// during world loading
		LoadingScreen.TexturePath = "textures/splash_16x9.png";
	}
	
	// set the text to be displayed on the loading screen
	// with a certain displacement along the X and Y axes
	LoadingScreen.Text = "<xy x=\"%50\" dx=\"0\" y=\"%50\" dy=\"0\"/>LOADING_PROGRESS";
	
	// set duration (in milliseconds) and display the loading screen on world loading
	int duration = 5;
	DateTime begin = DateTime.Now;

	while (DateTime.Now.Subtract(begin).TotalSeconds < duration)
		LoadingScreen.Render((int)(DateTime.Now.Subtract(begin).TotalSeconds / duration * 100.0f));

	// disable the loading screen
	LoadingScreen.Enabled = false;
	
	return true;
}
/* ... */

A loading screen defined in the init() method of the World Logic will be shown right after a world is loaded:

Source code (C#)
// AppWorldLogic.cs

/* ... */
public override bool Init() {

	// enable the loading screen
	LoadingScreen.Enabled = true;
	
	// set the text to be displayed on the loading screen,
	// specifying a color, a font, and a certain displacement along the X and Y axes
	LoadingScreen.Text = "<p align=\"center\"><font size=\"20\" color=\"#FF0000FF\">CUSTOM LOADING TEXT</font></p>";
	
	// set duration (in seconds) and display the loading screen on world loading
	int duration = 5;
	DateTime begin = DateTime.Now;

	while (DateTime.Now.Subtract(begin).TotalSeconds < duration)
		LoadingScreen.Render((int)(DateTime.Now.Subtract(begin).TotalSeconds / duration * 100.0f));

	// disable the loading screen
	LoadingScreen.Enabled = false;
	
	return true;
}

/* ... */

LoadingScreen Class

Properties

string Message#

The text message representing the current loading stage.

int Progress#

The current progress state.

string MessageShadersCompilation#

The current message displayed on shaders compilation.
set
Sets a message to be displayed on shaders compilation.
set value - Message on shaders compilation. The text aliases are also supported.

string MessageLoadingWorld#

The current message displayed on world loading.
set
Sets a message to be displayed on world loading.
set value - Message on world loading. The text aliases are also supported.

string FontPath#

The path to the font used to render the text.
set
Sets the path to the font used to render the text.
set value - Path to the font (True Type Font).

string Text#

The text of the loading screen.
set
Sets the text of the loading screen.
set value - Text of the loading screen. Can be either a plain or rich text. A number of aliases is available:
  • UNIGINE_COPYRIGHT — the UNIGINE copyright text.
  • UNIGINE_VERSION — the current UNIGINE version.
  • LOADING_PROGRESS — the loading progress going from 0 to 100.
  • LOADING_WORLD — the world being loaded (if any).

vec4 BackgroundColor#

The background color of loading screens.
set
Sets the background color of the loading screen.
set value - Background color.

vec4 Transform#

Transformation of the loading screen texture.
set
Sets transformation of the loading screen texture.
set value - Transformation of the loading screen texture:
  1. Texture size multiplier.
  2. Window size multiplier.
  3. Horizontal position in the [0.0f, 1.0f] range.
  4. Vertical position in the [0.0f, 1.0f] range.

string TexturePath#

The path to the texture for loading screens.
set
Sets the path to a texture for custom loading screens.
set value - Path to a file with the custom loading screen texture. If NULL (0) is passed, no texture will be used.

int Threshold#

The amount of blur in the alpha channel when interpolating between states of the loading screen.
set
Sets the amount of blur in the alpha channel when interpolating between states of the loading screen.
Notice
By default, the Threshold value is set to 16.
set value - amount of blur in the [0, 255] range.

bool Enabled#

A value indicating if manual rendering of a loading screen is allowed.
set
Specifies if manual rendering of the loading screen can be started or should be stopped.
Notice
setEnabled() is used only together with the corresponding render functions (render()). It cannot be used to enable or disable rendering of the loading screen during the initialization stage of the engine.
set value - true to enable manual rendering of a custom loading screen; false to disable.

Members


void SetImage ( Image image ) #

Sets an image for a custom loading screen.

Arguments

  • Image image - Image to be used as a custom loading screen.

void RenderInterface ( ) #

Renders a static loading screen. Such a screen does not display any progress.

void Render ( ) #

Renders the loading screen in the current progress state and with the current stage message.

void Render ( int progress ) #

Renders a custom loading screen in a given progress state. Use this function in a loop to create a gradual change between the initial (upper opaque part) and the final states (bottom transparent part) of the loading screen texture.

Arguments

  • int progress - Progress of alpha blending between 2 screens stored in the texture. The value in range [0;100] sets an alpha channel threshold, according to which pixels from the initial (opaque) or final (transparent) screen in the texture are rendered. By the value of 0, the initial screen is loaded. By the value of 100, the final screen is loaded.

void Render ( int progress, string message ) #

Renders a custom loading screen in a given progress state and prints a given message. Use this function in a loop to create a gradual change between the initial (upper opaque part) and the final states (bottom transparent part) of the loading screen texture, while printing a custom loading stage.

Arguments

  • int progress - Progress of alpha blending between 2 loading screens stored in the texture. The value in range [0;100] sets an alpha channel threshold, according to which pixels from the initial (opaque) or final (transparent) loading screen in the texture are rendered. By the value of 0, the initial screen is loaded. By the value of 100, the final screen is loaded.
  • string message - message to print representing the loading stage.

void RenderForce ( ) #

Renders the loading screen regardless of whether the manual rendering is allowed or not.

void RenderForce ( string message ) #

Renders the loading screen regardless of whether the manual rendering is allowed or not and prints a given message.

Arguments

  • string message - message to print that represents the loading stage.

IntPtr AddRenderBeginCallback ( RenderBeginDelegate func ) #

Adds a callback function that will be executed when a text is output to the console. The function is useful when you implement a custom loading screen rendering function, for example. The callback function must not take arguments.
Source code (C#)
// the callback function
private static void render_begin_callback()
{
	/* .. */
}

public override bool Init()
{
	// set the callback
	IntPtr id = LoadingScreen.AddRenderBeginCallback(render_begin_callback);
	
	return 1;
}

Arguments

  • RenderBeginDelegate func - Callback function with no arguments.

Return value

ID of the last added callback of the specified type, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool RemoveRenderBeginCallback ( IntPtr id ) #

Removes the specified callback from the list of render begin callbacks.

Arguments

  • IntPtr id - Callback ID obtained when adding it.

Return value

True if the callback with the given ID was removed successfully; otherwise false.

void ClearRenderBeginCallbacks ( ) #

Clears all added render begin callbacks.

IntPtr AddRenderEndCallback ( RenderEndDelegate func ) #

Adds a callback function that will be executed when a text is output to the console. The function is useful when you implement a custom loading screen rendering function, for example. The callback function must not take arguments.
Source code (C#)
// the callback function
private static void render_end_callback()
{
	/* .. */
}

public override bool Init()
{
	// set the callback
	IntPtr id = LoadingScreen.AddRenderEndCallback(render_end_callback);
	
	return 1;
}

Arguments

  • RenderEndDelegate func - Callback function with no arguments.

Return value

ID of the last added callback of the specified type, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool RemoveRenderEndCallback ( IntPtr id ) #

Removes the specified callback from the list of render end callbacks.

Arguments

  • IntPtr id - Callback ID obtained when adding it.

Return value

True if the callback with the given ID was removed successfully; otherwise false.

void ClearRenderEndCallbacks ( ) #

Clears all added render end callbacks.
Last update: 2021-02-17
Build: ()