Skip to content
Alex Silaev edited this page Nov 30, 2025 · 17 revisions

API

Note

You don't need to use Image/RawImage/Text/TMP* references to control their state. In UIWS there are ready components containers for each of them as a replacement.

WindowSystem API

// show MyScreen in asynchronous mode
WindowHandler<MyScreen> screenHandle = WindowSystem.Show<MyScreen>();

// show MyScreen immediately and return it's instance
MyScreen screenInstance = WindowSystem.ShowSync<MyScreen>();

// show MyScreen in asynchronous mode and pass some parameters to the OnParametersPass method
WindowHandler<MyScreen> screenHandle = WindowSystem.Closure(someData).Show<MyScreen>(static (w, data) => w.OnParametersPass(data)); 

Default components API

Important

Do not use gameObject.SetActive API with a UIWS components

// Show component (like a gameObject.SetActive(true), but with animations and right FSM state)
component.Show();
// Hide component (like a gameObject.SetActive(false), but with animations and right FSM state)
component.Hide();
// Show or hide component depends on boolean state
component.ShowHide(bool);

There are a lot of default components implemented, here are some common cases which may be useful:

TextComponent API

// set text
textComponent.SetText("some text");

// set unity localization
textComponent.SetText(unityLocalizationKey);

// set unity localization with parameters
textComponent.SetText(unityLocalizationKey, param1, param2, ...);

// set double value
textComponent.SetValue(123);

// set text with some int values (there are various overloads for these format)
textComponent.SetText(10, "/", 100);
Method Description
SetValue(double) Set value as text
SetValue(double, SourceValue) Set value as text and format it with SourceValue
SetValue(double, SourceValue.Seconds, [normal] TimeResult, [short] TimeResult) Set value as a time between short and normal variants (depends on value)
SetColor Set color to the UGUI Text or TMP Text color field
SourceValue Description
SourceValue.Digits Default value formatted with InvariantCulture
SourceValue.Seconds Format with default time format in seconds
SourceValue.Milliseconds Format with default time format in milliseconds
SourceValue.Percent Add percent char at the end of the value (ex: 15%) with InvariantCulture

ButtonComponent API

// replace button callback with new SomeMethod call
// you don't need to unregister this callback because it will be managed automatically
buttonComponent.SetCallback(SomeMethod);
// or you can use closure-free method to avoid unnecessary allocations
buttonComponent.SetCallback(closureState, static (data) => ...);

// ButtonComponent has an inheritance from GenericComponent, 
// so you can use GenericComponent's Get<>() method to get children components
buttonComponent.Get<TextComponent>().SetText(...)

// rarely you need to use these methods if you really need to control multiple callbacks
buttonComponent.AddCallback(...)
buttonComponent.RemoveCallback(...)

ImageComponent API

// set sprite
imageComponent.SetImage(sprite);

// set texture
imageComponent.SetImage(texture2d);

// set Resource (or Resource<>) which will be loaded by built-in UIWS Resources system
// it is the better type of SetImage call because it will handles Load/Unload AssetBundles/Addressables automatically
imageComponent.SetImage(resource);
Method Description
SetMaterial Set material instance to the UGUI Image/RawImage
SetFillAmount Set fill amount to the UGUI Image fillAmount field
SetColor Set color to the UGUI Image/RawImage color field

ListComponent API

// default usage
var arr = new SomeData[...];
listComponent.SetItems(arr.Length, (item, parameters) => {
   // item is a view instance
   item.SetInfo(arr[parameters.index]);
});

// set without allocations
var arr = new SomeData[...];
listComponent.Closure((arr, someData: 123)).SetItems(arr.Length, static (item, parameters) => {
   // item is a view instance
   item.SetInfo(parameters.data.arr[parameters.index], parameters.data.someData);
});

// list fill is async, so we may have to use complete callback
var arr = new SomeData[...];
listComponent.SetItems(arr.Length, (item, parameters) => {
   ...
}, (parameters, result) => {
   // result is TRUE if list is complete and FALSE if it's not ready yet
   // for example, if we call SetItems in Update method - we will get result as FALSE for a few frames and then TRUE when the job is done
});

Components Modules

You can add custom modules for components where you can handle or change default behavior.

Screens Modules

You can add custom modules for screens to add some common layout things like a player resource panel, or add some common behavior like a back button or close background behavior.

Screen code sample

    public class MyScreen : LayoutWindowType {

        private TextComponent text1Component;
        private TextComponent text2Component;
        private ButtonComponent someButton;
        private System.Action onButtonClick;

        public void OnParametersPass(System.Action onButtonClick) {
            this.onButtonClick = onButtonClick;
        }

        // fires on first instance only (if there is no instance in the pool)
        public override void OnInit() {
            
            base.OnInit();

            this.GetLayoutComponent(out this.text1Component); // get first text component assigned on the screen instance 
            this.GetLayoutComponent(out this.text2Component); // get next text component (this behavior by default)
            this.GetLayoutComponent(out this.someButton); // get first button component
            
        }

        // fires on each instance before animations has been started
        public override void OnShowBegin() {
            
            base.OnShowBegin();

            this.SetInfo();

        }

        // set some info
        public void SetInfo() {
            this.text1Component.SetText("Sample text1");
            this.text2Component.SetText("Sample text2");
            // here we use closure to set up callback without allocations
            this.someButton.SetCallback(this.onButtonClick, static (cbk) => cbk.Invoke());
            // here is text set sample to the button instance
            // be sure that you have components array fill in the inspector
            this.someButton.Get<TextComponent>().SetText("Button text");
        }

    }

Clone this wiki locally