73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
![]() |
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using BITKit;
|
||
|
using BITKit.Entities;
|
||
|
using BITKit.Mod;
|
||
|
using BITKit.UX;
|
||
|
using Cysharp.Threading.Tasks;
|
||
|
using Net.Project.B.Inventory;
|
||
|
using Project.B.Entities;
|
||
|
using Project.B.UX;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UIElements;
|
||
|
|
||
|
namespace Net.Project.B.UX
|
||
|
{
|
||
|
|
||
|
public class UXInventoryPrompt<TPanel> :UIToolkitSubPanel<TPanel>,IDisposable, IUXInventoryPrompt where TPanel : IUXPanel
|
||
|
{
|
||
|
private readonly IPlayerFactory _playerFactory;
|
||
|
|
||
|
[Inject] private IPlayerInventory _playerInventory;
|
||
|
|
||
|
[UXBindPath("inventory-prompts")]
|
||
|
private VisualElement _inventoryPrompts;
|
||
|
|
||
|
private VisualTreeAsset _template;
|
||
|
|
||
|
private bool _isDisposed;
|
||
|
|
||
|
public UXInventoryPrompt(IServiceProvider serviceProvider, IPlayerFactory playerFactory) : base(serviceProvider)
|
||
|
{
|
||
|
_playerFactory = playerFactory;
|
||
|
|
||
|
_playerFactory.OnEntityCreated += OnEntityCreated;
|
||
|
}
|
||
|
|
||
|
protected override async UniTask OnInitiatedAsync()
|
||
|
{
|
||
|
await base.OnInitiatedAsync();
|
||
|
_template =await ModService.LoadAsset<VisualTreeAsset>("ui_inventory_prompts-template");
|
||
|
|
||
|
_inventoryPrompts.Clear();
|
||
|
}
|
||
|
|
||
|
private UniTask OnEntityCreated(string arg1, IEntity arg2)
|
||
|
{
|
||
|
arg2.Inject(this);
|
||
|
|
||
|
_playerInventory.Container.OnAdd += OnAdd;
|
||
|
|
||
|
return UniTask.CompletedTask;
|
||
|
}
|
||
|
|
||
|
private async void OnAdd(IRuntimeItem obj)
|
||
|
{
|
||
|
var container = _inventoryPrompts.Create(_template);
|
||
|
|
||
|
UXInventoryUtils.Setup(container, obj).Forget();
|
||
|
|
||
|
await UniTask.Delay(3000);
|
||
|
if(_isDisposed)return;
|
||
|
|
||
|
container.RemoveFromHierarchy();
|
||
|
}
|
||
|
|
||
|
public void Dispose()
|
||
|
{
|
||
|
_isDisposed = true;
|
||
|
_playerFactory.OnEntityCreated -= OnEntityCreated;
|
||
|
}
|
||
|
}
|
||
|
}
|