Libraries

s&box libraries list

k.Ui

kfe.kui

manage your UI (open, close from code easily)

About

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.

More by k0fe

02
k.Cameras thumbnail
k.Cameras kfe.kcameras

simple camera library

+0 24h
1favorites
0upvotes
--Terry score
03
k.Constraints thumbnail
k.Constraints kfe.kconstraints

copy position and/or rotation from one gameobject to another

+0 24h
1favorites
0upvotes
--Terry score
04
k.Clothing thumbnail
k.Clothing kfe.kclothing

test available clothes

+0 24h
0favorites
0upvotes
--Terry score
06
k.Extensions thumbnail
k.Extensions kfe.kextensions

i will keep my code dry i will keep my code dry i will keep my code dry i will keep my code dry i will keep my code dry i will~

+0 24h
0favorites
0upvotes
--Terry score