Haikara Manager
Haikara Manager
は、UI Document
の初期化などに使われるMonoBehaviourの基底クラスです。
アタッチするGameObjectにはUI Document
が必須です。Awake()
内でGetComponent<UIDocument>()
を実行します。
PreprocessInitialize
Awake()
内でInitialze()
よりも前に呼ばれます。Initialize()
で呼び出す処理が依存する内容などをここに記述することができます。
(例: ViewInstaller.Install
や、Viewクラスのインスタンス化よりも前に呼び出したい処理)
Initialize
Awake()
の最後に呼ばれます。ViewInstaller.Install()
の実行や、 CustomのUILoader
の登録などをこの中で行うことを想定しています。
Sample Code
csharp
public class AddressableCounterSampleHaikaraManager : HaikaraManager
{
protected override void PreprocessInitialize(HaikaraUIContext uiContext)
{
HaikaraDialogProvider.Instance.Initialize(uiContext,
AddressableDialogRoot.UxmlGuid,
HaikaraBackdrop.UxmlGuid
);
}
protected override async void Initialize(HaikaraUIContext uiContext)
{
AddressableSampleViewInstaller.Install();
CommonViewInstaller.Install();
Haikara.Runtime.UI.ViewInstaller.Install();
// Both the VisualTreeAsset and the StyleSheet must be registered with the CustomUILoader.
RuntimeUICatalog.Instance.UxmlUICollection.RegisterCustomUILoader(
new AddressablesUILoader<VisualTreeAsset>()
);
RuntimeUICatalog.Instance.UssUICollection.RegisterCustomUILoader(
new AddressablesUILoader<StyleSheet>()
);
var counter = new AddressableCounter();
await counter.LoadAndAddToAsync(uiDocument.rootVisualElement);
counter.SetDataSource(new AddressableCounterViewModel(new AssetBundleCountModel()));
}
}