44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.IO;
|
|
using UnityEngine;
|
|
using YooAsset;
|
|
|
|
namespace BITFALL.Entities.Equipment
|
|
{
|
|
public sealed class EntityEquipmentLoader : EntityBehavior
|
|
{
|
|
[SerializeField] private Transform root;
|
|
[SerializeReference, SubclassSelector] private IReference[] tags;
|
|
|
|
[Inject]
|
|
private IEntityEquipment _equipment;
|
|
public override void OnStart()
|
|
{
|
|
base.OnStart();
|
|
foreach (var packageName in YooAssetUtils.RegisteredPackages)
|
|
{
|
|
var package = YooAssets.GetPackage(packageName);
|
|
foreach (var assetInfo in package.GetAssetInfos(tags.Cast()))
|
|
{
|
|
var task = package.LoadAssetAsync<GameObject>(assetInfo.AssetPath);
|
|
task.WaitForAsyncComplete();
|
|
var newObject = task.AssetObject.As<GameObject>();
|
|
var newInstance = Instantiate(newObject, root).GetComponent<IEquipBase>();
|
|
var newTransform = newInstance.As<MonoBehaviour>().transform;
|
|
|
|
newTransform.localPosition = default;
|
|
newTransform.localRotation = default;
|
|
|
|
_equipment.Register(newInstance);
|
|
|
|
BIT4Log.Log<EntityEquipmentLoader>($"已注册:{newInstance.AddressablePath}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|