k.Ui
k0fe k0fe Library update 1y ago

k.Ui

manage your UI (open, close from code easily)

hard_drive 0 MB folder 40 files build Engine v17 history Last update 460d ago
open_in_new View on sbox.game

About This Package

Manage your screens a bit easier. 


Start
  1. Create UI config | Asset Browser | Right click -> k.UI -> UiConfig
  2. Create prefab for each view, add Screen Panel, Razor component and class that inherits from ViewBase
  3. Register your prefabs in the config
  4. Add UiInitializer on your initialization scene and pick your UiConfig

Make a View
  1. Create script derived from ViewBase
public class ExampleView : ViewBase
{
}
  1. Attach script to your UI window prefab
  2. Reference prefab in UiConfig
Open a View
Ui.Open<ExampleView>();


Close a View
Ui.Close<ExampleView>();

How to pass a custom data model
  1. Create a model
public class PlayerViewModel : ViewModelBase
{
    public string Name { get; set; }
    public int Health { get; set; }
    
    // we will add constructor for ease of use
    public PlayerViewModel( string name, int health )
    {
       Name = name;
       Health = health;
    }
}


  1. Override OnViewModelUpdate method in your target ViewBase class
  2. Cast (!) your data model and process your data

public class PlayerInfoView : ViewBase
{
    [Property] public PlayerHUD PlayerHUD { get; set; }
    public override void OnViewModelUpdate( ViewModelBase model )
    {
       base.OnViewModelUpdate( model );
       if ( model is PlayerViewModel playerViewModel )
       {
          PlayerHUD.SetPlayerViewModel( playerViewModel );
       }
    }
}

  1. Now you can open your UI with a data model 
Ui.Open<PlayerInfoView>( new PlayerViewModel( "k0fe", 100 ) );

Be aware, that OnViewModelUpdate is better to be avoid when we want to update UI often. Instead we should use BuildHash in Blazor or anything else. OnViewModelUpdate is better used when we want to inject specific classes in our ViewBase classes.

Media

No usage statistics available
This package may be new or not widely used yet. Usage data becomes available as more users install and play with the package.
Package ID: kfe.kui
Created: 2025-04-01 08:05 UTC
Updated: 2025-04-06 01:29 UTC
Type: library
Public: Yes
Version: 95226
files: 40
Size: 0.0 MB
Engine Version: 17
Asset Version ID: 95226
Version Created: 2025-04-06 01:29 UTC
Hash: -7486759074735172923
Manifest: Open manifest
Resources:
Code Package References:
new_releases Latest Update Apr 6, 2025
Changes on 2025-04-06
tag v95226 folder 40 files hard_drive 0.0 MB build Engine v17
95226 Apr 6, 2025
Changes on 2025-04-06
folder 40 files hard_drive 17.68 KB build Engine v17
94473 Apr 1, 2025
Changes on 2025-04-01
folder 41 files hard_drive 18.06 KB build Engine v17