52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using Cysharp.Threading.Tasks;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using Net.Project.B.Interaction;
|
|
using Project.B.Item;
|
|
using UnityEngine;
|
|
|
|
namespace Net.Project.B.Item
|
|
{
|
|
[RequireComponent(typeof(UnityEntity))]
|
|
public class WorldItemContainerCreator : MonoBehaviour
|
|
{
|
|
|
|
[SerializeField] private bool allowAdd;
|
|
[SerializeField] private bool allowRemove;
|
|
|
|
[SerializeField] private ScriptableItem[] initialItems;
|
|
|
|
private void Start()
|
|
{
|
|
var itemService = BITApp.ServiceProvider.GetRequiredService<IManagedItemService>();
|
|
|
|
var entity = GetComponent<IEntity>();
|
|
|
|
var itemContainer = new RuntimeItemContainer
|
|
{
|
|
Id = entity.Id,
|
|
AllowAdd = allowAdd,
|
|
AllowRemove = allowRemove
|
|
};
|
|
entity.ServiceCollection.AddSingleton<IWorldInteractable,WorldInteractable>();
|
|
entity.ServiceCollection.AddSingleton<IRuntimeItemContainer>(itemContainer);
|
|
|
|
foreach (var scriptableItem in initialItems)
|
|
{
|
|
var runtimeItem = scriptableItem.CreateRuntimeItem();
|
|
|
|
itemContainer.Add(runtimeItem);
|
|
|
|
itemService.AddOrUpdateItem(runtimeItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|