库

s&box 库列表

k.Ui

kfe.kui

manage your UI (open, close from code easily)

关于

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.

更多作品,作者: k0fe

查看创作团队分析 →
02
k.Cameras 缩略图
k.Cameraskfe.kcameras

simple camera library

+024小时
1收藏
0好评
--Terry 评分
03
k.Constraints 缩略图
k.Constraintskfe.kconstraints

copy position and/or rotation from one gameobject to another

+024小时
1收藏
0好评
--Terry 评分
04
k.Clothing 缩略图
k.Clothingkfe.kclothing

test available clothes

+024小时
0收藏
0好评
--Terry 评分
06
k.Extensions 缩略图
k.Extensionskfe.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~

+024小时
0收藏
0好评
--Terry 评分