Skip to content
Feynmen edited this page Jun 18, 2018 · 2 revisions

ViewBase Description

In your scene, you can create View to help work with components. For example, you have the main menu with 2 pages (Menu and Setting Menu). You can create Controller and 2 Views (MenuView and SettingView). MenuView will be added to Parent Game Object of Menu Panel and SettingView to Setting Panel. Views will contain UI items from panels and implement initialization and access to UI items. You must invoke Init function of View manually, in Controller's Init function

ViewBase Features

For cleaning data, you can override function Release, which will be invoked when a component Destroying

public override void Release() 
{ 
    //Remove some data
}

ViewBase Example

View

public class ButtonView : ViewBase
{
    [SerializeField] private Button _button;
	
    public override void Init() { }

    public void AddButtonOnClickListener(UnityAction action)
    {
        _button.onClick.AddListener(action);
    }
}

Controller

public class TestController : ControllerBase
{
    [SerializeField] private ButtonView _buttonView;
		
    protected override void Init()
    {
        _buttonView.Init();
        _buttonView.AddButtonOnClickListener(() =>
	{
	    Disable();
	    SceneController.Enable<AnotherTestController>();
	});
    }
}

Clone this wiki locally